Skip to content
npm ↗ GitHub ↗

Documentation

03/Get started

Customization

All colors go through CSS variables. Change one and the whole library is recolored, without touching the components.

Live customizer

Pick a color and watch this page change. The CSS below is ready to paste into your project. Colors adjust themselves to keep AA contrast in both modes.

Accepts any hexadecimal color.

Mode
Active Pro

Preview

The components across the page use the new color. A link

Contrast (min. 4.5)DarkLight
Text on background
Muted text
Accent on background
Primary button
tu-tema.css

Three levels

1. One variable. Change --cb-accent and the 50–950 scale, the button fill, the soft backgrounds and the focus ring are recalculated.

CSS
:root {
  --cb-accent: #e11d48;
}

2. A preset theme. Six themes, each with its light and dark version.

HTML
<html data-cb-accent="esmeralda">

3. Your own theme. Define the values for each mode with the --cb-dark-* and --cb-light-* prefixes. See the full example in Create your own theme.

Where this CSS goes

It's plain CSS, so it works the same in Laravel, Vite, TypeScript or an HTML file with no build. Paste it in your own stylesheet, after importing Cobalto. In Laravel that's resources/css/app.css:

resources/css/app.css
@import 'tailwindcss';
@import 'cobalto/tailwind';

:root {
  --cb-dark-accent: #808080;
  --cb-light-accent: #000000;
}

With no build, put it in a file or in a <style> that loads after Cobalto's CSS:

HTML
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cobalto@0.1.2/dist/cobalto.min.css">
<link rel="stylesheet" href="/css/mi-tema.css">

A :root block always wins, even over data-cb-accent: while it's there, the preset themes won't change the color. If you want your theme and also the ability to switch between themes, give it a name:

resources/css/app.css
[data-cb-accent="marca"] {
  --cb-dark-accent: #808080;
  --cb-light-accent: #000000;
}

And activate it in the HTML, or from JS when the user picks it. It is saved the same way as the preset themes:

HTML
<html data-cb-accent="marca">
JS
cobalto.theme.setAccent('marca');

Preset themes

Click to apply it to this page. Your choice is saved in localStorage. The color dots use nested data-cb-accent: a theme can also be applied to just one part of the page.

HTML
<html data-cb-accent="violeta">

<section data-cb-accent="ambar">...</section>
Emerald

Section with data-cb-accent="esmeralda".

Amber

Section with data-cb-accent="ambar".

Ruby

Section with data-cb-accent="rubi".

Violet

Section with data-cb-accent="violeta".

Light and dark

Without an attribute, Cobalto follows prefers-color-scheme (dark if the system doesn't specify). data-cb-theme fixes it, on html or on any section.

HTML
<html data-cb-theme="light">

<section data-cb-theme="dark">...</section>

Tailwind's dark: and light: variants follow the same rules:

HTML
<div class="bg-cb-bg-2 dark:bg-cb-bg-3 light:shadow-cb-sm">...</div>

From JS:

JS
cobalto.theme.set('light'); // 'dark', 'light', 'system'
cobalto.theme.toggle();
cobalto.theme.setAccent('rubi');

document.addEventListener('cb:theme', (event) => console.log(event.detail.resolved));

Accent scale

Generated with color-mix(in oklab) from --cb-accent. Available as variables (--cb-accent-500) and utilities (bg-cb-accent-200).

50
100
200
300
400
500
600
700
800
900
950

Color tokens

Each token exists as a --cb-* variable and as a Tailwind utility: bg-cb-bg-2, text-cb-muted, border-cb-line, bg-cb-accent/20...

--cb-bg
Page background
--cb-bg-2
Raised surface (cards on hover, panels)
--cb-bg-3
Higher raised surface (menu hover, kbd)
--cb-line
Borders and dividers
--cb-line-2
Control borders
--cb-text
Main text
--cb-muted
Secondary text
--cb-dim
Dimmed text (metadata)
--cb-accent
Brand color
--cb-accent-ink
Text on accent fill
--cb-accent-bg
Accent fill (primary button)
--cb-accent-soft
Soft accent background
--cb-success
Success
--cb-warning
Warning
--cb-danger
Error
--cb-info
Information

Create your own theme

Copy this block, change the values and activate it with data-cb-accent="marca". If you omit a token, Cobalto's is used. Make sure the text has at least 4.5:1 contrast against the background.

tema-marca.css
[data-cb-accent="marca"] {
  --cb-dark-bg: #0c0a09;
  --cb-dark-bg-2: #141210;
  --cb-dark-bg-3: #1c1917;
  --cb-dark-line: #292524;
  --cb-dark-line-2: #3a3431;
  --cb-dark-text: #f5f5f4;
  --cb-dark-muted: #a8a29e;
  --cb-dark-dim: #8a837e;
  --cb-dark-accent: #fb923c;
  --cb-dark-accent-ink: #0c0a09;

  --cb-light-bg: #fafaf9;
  --cb-light-bg-2: #f5f5f4;
  --cb-light-bg-3: #e7e5e4;
  --cb-light-line: #d6d3d1;
  --cb-light-line-2: #c4bfbb;
  --cb-light-text: #1c1917;
  --cb-light-muted: #57534e;
  --cb-light-dim: #6b645f;
  --cb-light-accent: #c2410c;
  --cb-light-accent-ink: #ffffff;
}

Status colors can also be changed per mode: --cb-dark-success, --cb-light-danger, etc.

Other tokens

Defined in @theme, so they also generate utilities (font-cb-mono, rounded-cb-lg, py-cb-section, text-cb-4xl...).

GroupTokens
Fonts--font-cb-mono, --font-cb-sans
Typography--text-cb-xs (11px) … --text-cb-6xl (clamp(64px, 17vw, 230px)), --text-cb-lead
Tracking--tracking-cb-tight|tighter|display|huge|wide|wider
Radii--radius-cb-sm (5px), --radius-cb (8px), --radius-cb-lg (10px), --radius-cb-full
Spacing--spacing-cb-section (110px), --spacing-cb-block (56px), --spacing-cb-gutter (24px), --spacing-cb-nav (64px)
Container--cb-max (1180px) → max-w-cb
Breakpoints--breakpoint-cb-sm (600px), --breakpoint-cb-md (960px) → cb-sm:, max-cb-md:
Shadows--shadow-cb-sm|md|lg (--cb-scrim)
Motion--cb-duration-fast|pop|duration|slow|reveal, --ease-cb, --ease-cb-out
Layers--cb-z-dropdown|mobile|sticky|drawer|overlay|toast|tooltip