Skip to content
Likable Aurora @likable-hair/svelte 5

CSS and Tailwind

The library keeps all its CSS in cascade layers: the app's own CSS always wins, Tailwind utilities work on components and resets do not break them. The tokens are also available as Tailwind classes.

Markdown for LLMs

Cascade layers

Every CSS file of the library declares this order of layers. The library lives in global: tokens and component defaults in global.base, themes in global.theme, component rules in global.components.

@layer reset, theme, base, global, components, utilities;

Put the same line at the top of the main CSS file of the app, so the order holds whichever file the browser loads first.

CSS outside layers always wins over the library, whatever its specificity: a class passed with class overrides the component. For colors, sizes and states prefer the CSS variables of each component (--button-background), which also cover hover, focus and disabled.

Resets go below the library, in @layer reset. An unlayered rule such as button { padding: 0 } or * { margin: 0 } would override the components.

src/app.css
@layer reset, theme, base, global, components, utilities;

@layer reset {
	*,
	*::before,
	*::after {
		box-sizing: border-box;
	}
}

Tailwind 4

Import the library theme after Tailwind. Tailwind puts its preflight in base and its utilities in utilities, so the order above places the library between them: utilities override components, the preflight does not.

src/app.css
@layer reset, theme, base, global, components, utilities;

@import 'tailwindcss';
@import '@likable-hair/svelte/tailwind.css';

The values come from tokens.css, which every component imports. If a page uses the classes before any component, import it once in the root layout: import '@likable-hair/svelte/tokens.css'.

Opacity modifiers work with the tokens: bg-primary/50.

Tailwind 3

Tailwind 3 does not use native cascade layers, so its preflight would override the components (button { background-color: transparent }, * { border-width: 0 }). Wrap @tailwind base in @layer reset: the preflight and the app's @layer base blocks end up there. Utilities stay outside layers and win over the library.

src/app.css
@layer reset, theme, base, global, components, utilities;

@layer reset {
	@tailwind base;
}
@tailwind components;
@tailwind utilities;

The classes come from a preset.

tailwind.config.js
import aurora from '@likable-hair/svelte/tailwind-preset';

/** @type {import('tailwindcss').Config} */
export default {
	presets: [aurora],
	content: ['./src/**/*.{html,js,svelte,ts}']
};

Opacity modifiers (bg-primary/50) do not work with the tokens in Tailwind 3: use the -soft colors (bg-primary-soft).

Classes

Every class reads a --global-* token at runtime, so it follows the theme and the light/dark mode. The name is the token without --global- (and without color- for colors). Colors work with every color utility (bg-, text-, border-, ring-, outline-, fill-, shadow-, ...). font-sans is --global-font-family: set the app font there, so components and utilities share it.

ClassToken
Colors
bg-bg--global-color-bg
bg-bg-2--global-color-bg-2
bg-surface--global-color-surface
bg-surface-2--global-color-surface-2
bg-surface-3--global-color-surface-3
bg-surface-solid--global-color-surface-solid
bg-surface-pop--global-color-surface-pop
bg-border--global-color-border
bg-border-strong--global-color-border-strong
bg-text--global-color-text
bg-text-2--global-color-text-2
bg-text-3--global-color-text-3
bg-primary--global-color-primary
bg-primary-strong--global-color-primary-strong
bg-primary-soft--global-color-primary-soft
bg-primary-glow--global-color-primary-glow
bg-on-primary--global-color-on-primary
bg-accent--global-color-accent
bg-accent-soft--global-color-accent-soft
bg-success--global-color-success
bg-success-soft--global-color-success-soft
bg-on-success--global-color-on-success
bg-warning--global-color-warning
bg-warning-soft--global-color-warning-soft
bg-on-warning--global-color-on-warning
bg-error--global-color-error
bg-error-soft--global-color-error-soft
bg-error-glow--global-color-error-glow
bg-on-error--global-color-on-error
bg-overlay--global-color-overlay
bg-data-1--global-color-data-1
bg-data-2--global-color-data-2
bg-data-3--global-color-data-3
bg-data-4--global-color-data-4
bg-data-5--global-color-data-5
bg-data-6--global-color-data-6
bg-focus-ring--global-focus-ring-color
Radius
rounded-xs--global-radius-xs
rounded-sm--global-radius-sm
rounded-md--global-radius-md
rounded-lg--global-radius-lg
rounded-xl--global-radius-xl
Shadows
shadow-sm--global-shadow-sm
shadow-md--global-shadow-md
shadow-lg--global-shadow-lg
shadow-fill--global-shadow-fill
Fonts
font-sans--global-font-family
font-display--global-font-family-display
font-mono--global-font-family-mono
Motion
ease-spring--global-ease-spring
Gradients
bg-fill-primary--global-fill-primary
bg-fill-error--global-fill-error
bg-fill-gradient--global-fill-gradient
bg-gradient--global-gradient
bg-gradient-soft--global-gradient-soft