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.
npm install cobalto tailwindcss @tailwindcss/vite
Import Cobalto right after Tailwind:
@import "tailwindcss";
@import "cobalto/tailwind";
And the JavaScript, if you use interactive components:
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:
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.
<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.
npm install cobalto
Add Cobalto right after Tailwind, in the CSS that comes with the project:
@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';
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:
<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 forlivewire:navigatedand reinitializes after everywire:navigate(Livewire 3 and 4).- A
MutationObserverinitializes the components that Livewire or Alpine add to the DOM. Anything already initialized is not duplicated. - Cobalto only uses
data-cb-*attributes andcb-*classes, so it doesn't clash withx-*orwire:*. - If Livewire re-renders an open component (modal, dropdown), wrap it in
wire:ignore.selfto keep its state.
To fire a toast or open a modal from PHP, dispatch an event from the component:
$this->dispatch('toast', title: 'Guardado', variant: 'success');
And listen for it in your JavaScript with Livewire.on() inside livewire:init:
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:
<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:
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:
<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:
| Key | Attribute | Default value |
|---|---|---|
commandEmpty | data-cb-command-empty | No results for |
toastRegion | — | Notifications |
toastClose | closeLabel (toast option) | Close notification |
tableEmpty | data-cb-table-empty | No results |
tableStatus | data-cb-table-status-text | Showing {start}–{end} of {total} |
tableSelected | data-cb-table-selected-text | {count} selected |
paginationPrev | data-cb-pagination-prev | Previous page |
paginationNext | data-cb-pagination-next | Next page |
paginationPage | data-cb-pagination-page | Page {page} |
copyDone | data-cb-copy-done | Copied |
copyError | data-cb-copy-error | Copy 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:
<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:
@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
| Import | File | Use |
|---|---|---|
cobalto | dist/cobalto.js | Full JS (ESM). |
cobalto/tailwind | src/cobalto.css | CSS source to import after Tailwind. |
cobalto/tokens.css | src/tokens.css | Only tokens, themes and the dark:/light: variants. |
cobalto/css | dist/cobalto.css | Precompiled CSS (also dist/cobalto.min.css). |
cobalto/components/* | src/js/components/*.js | JS for a single component. |
| CDN | dist/cobalto.umd.min.js | Script for <script> that exposes window.cobalto. |