Skip to content
npm ↗ GitHub ↗

Documentation

02/Get started

Installation

Two ways to use it: as a source for your Tailwind CSS v4 build, or precompiled from a CDN. The package is published on npm.

With Tailwind (recommended)

This way you can use the bg-cb-bg, text-cb-muted or dark: utilities in your own HTML and only the CSS you use is generated.

Terminal
npm install cobalto tailwindcss @tailwindcss/vite

Import Cobalto right after Tailwind:

app.css
@import "tailwindcss";
@import "cobalto/tailwind";

And the JavaScript, if you use interactive components:

app.js
import cobalto from 'cobalto';

cobalto.autoInit();

autoInit() restores the saved theme, initializes the page and watches the DOM to initialize anything added later. If you prefer manual control, call cobalto.init(element). You can also import individual components:

JS
import { init as initTabs } from 'cobalto/components/tabs';

initTabs(document);

No build, from a CDN

The precompiled CSS includes the Tailwind reset, the tokens and all the components. The UMD script initializes itself; add data-cb-manual to prevent that.

HTML
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cobalto@0.1.2/dist/cobalto.min.css">
<script src="https://cdn.jsdelivr.net/npm/cobalto@0.1.2/dist/cobalto.umd.min.js" defer></script>

With a CDN you don't get arbitrary Tailwind utilities, only the cb-* classes, cb-wrap and the utilities the components themselves use.

Laravel + Vite

Laravel 12 and 13 already ship with Tailwind v4 and Vite. Nothing else needs to be configured.

Terminal
npm install cobalto

Add Cobalto right after Tailwind, in the CSS that comes with the project:

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

@source '../../vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php';
@source '../../storage/framework/views/*.php';
@source '../**/*.blade.php';
@source '../**/*.js';
resources/js/app.js
import cobalto from 'cobalto';

window.cobalto = cobalto;
cobalto.autoInit();

In the layout, add this script in the head to apply the saved theme before the first paint and avoid flicker. It is the same for any stack:

resources/views/layouts/app.blade.php
<script>
  try {
    var t = localStorage.getItem('cb-theme');
    var a = localStorage.getItem('cb-accent');
    if (t) document.documentElement.setAttribute('data-cb-theme', t);
    if (a) document.documentElement.setAttribute('data-cb-accent', a);
  } catch (e) {}
</script>
@vite(['resources/css/app.css', 'resources/js/app.js'])

Livewire and Alpine

  • autoInit() listens for livewire:navigated and reinitializes after every wire:navigate (Livewire 3 and 4).
  • A MutationObserver initializes the components that Livewire or Alpine add to the DOM. Anything already initialized is not duplicated.
  • Cobalto only uses data-cb-* attributes and cb-* classes, so it doesn't clash with x-* or wire:*.
  • If Livewire re-renders an open component (modal, dropdown), wrap it in wire:ignore.self to keep its state.

To fire a toast or open a modal from PHP, dispatch an event from the component:

app/Livewire/EditarCliente.php
$this->dispatch('toast', title: 'Guardado', variant: 'success');

And listen for it in your JavaScript with Livewire.on() inside livewire:init:

resources/js/app.js
document.addEventListener('livewire:init', () => {
  Livewire.on('toast', (event) => cobalto.toast(event));
  Livewire.on('abrir-modal', (event) => cobalto.modal.open(event.id));
});

Or with Alpine, without writing separate JS:

HTML
<div x-data x-on:toast.window="cobalto.toast($event.detail)"></div>

Texts and language

The texts your users see (search empty state, toast close button, table status and pagination, copy button) come in English. Change them site-wide with setMessages() or when initializing:

app.js
import cobalto from 'cobalto';

cobalto.autoInit({
  messages: {
    commandEmpty: 'Sin resultados para',
    tableStatus: 'Mostrando {start}–{end} de {total}',
    copyDone: 'Copiado',
  },
});

// o en cualquier momento
cobalto.setMessages({ toastClose: 'Cerrar notificación' });

Or for a single element, with attributes. The attribute wins over the global text:

HTML
<div class="cb-table-wrap" data-cb-table data-cb-table-empty="Sin resultados" data-cb-table-status-text="{start}–{end} de {total}">...</div>
<button class="cb-code__copy" data-cb-copy data-cb-copy-done="Copiado">...</button>

Available keys. The {name} placeholders are replaced by the corresponding value:

KeyAttributeDefault value
commandEmptydata-cb-command-emptyNo results for
toastRegion—Notifications
toastClosecloseLabel (toast option)Close notification
tableEmptydata-cb-table-emptyNo results
tableStatusdata-cb-table-status-textShowing {start}–{end} of {total}
tableSelecteddata-cb-table-selected-text{count} selected
paginationPrevdata-cb-pagination-prevPrevious page
paginationNextdata-cb-pagination-nextNext page
paginationPagedata-cb-pagination-pagePage {page}
copyDonedata-cb-copy-doneCopied
copyErrordata-cb-copy-errorCopy failed

With the CDN script, add data-cb-manual and call cobalto.setMessages() before cobalto.init().

Font

Cobalto doesn't load any font on its own. If you add nothing, it uses the system monospace font. For JetBrains Mono from Google Fonts:

HTML
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">

To self-host it (no requests to Google), install @fontsource-variable/jetbrains-mono or declare your own @font-face, and if you want another family change the token:

CSS
@import "@fontsource-variable/jetbrains-mono";

:root {
  --font-cb-mono: "JetBrains Mono Variable", ui-monospace, monospace;
  --font-cb-sans: "Inter", system-ui, sans-serif;
}

What the package includes

ImportFileUse
cobaltodist/cobalto.jsFull JS (ESM).
cobalto/tailwindsrc/cobalto.cssCSS source to import after Tailwind.
cobalto/tokens.csssrc/tokens.cssOnly tokens, themes and the dark:/light: variants.
cobalto/cssdist/cobalto.cssPrecompiled CSS (also dist/cobalto.min.css).
cobalto/components/*src/js/components/*.jsJS for a single component.
CDNdist/cobalto.umd.min.jsScript for <script> that exposes window.cobalto.