The adjustability ladder
Each step is more powerful, and more work to maintain, than the one before it. Take the first one that solves your problem.
1. Props
Section titled “1. Props”<sl:button variant="outline" size="sm">Cancel</sl:button>The declared props of each component are listed on its page. This covers most needs, with no CSS at all.
2. Pass-through attributes and classes
Section titled “2. Pass-through attributes and classes”Every attribute that is not a prop lands on the rendered element: hx-post, x-on:click, aria-*, data-*.
class is appended to the component’s own class.
<sl:button class="toolbar-action" hx-post="/orders/42/archive">Archive</sl:button>The classes are your application’s own. If you compile Tailwind, class="w-full mt-4" works; if you don’t, use a class
from your own stylesheet. The library’s bundles define no utility classes.
3. Token overrides
Section titled “3. Token overrides”The components are drawn with CSS variables. Redefine them in your stylesheet, loaded after the library’s, to rebrand every component at once:
:root { --primary: oklch(0.55 0.15 150); --primary-foreground: oklch(0.98 0 0); --radius: 0.25rem;}.dark { --primary: oklch(0.7 0.14 150);}The library’s tokens sit in a cascade layer, so your values win whether or not you put them in a layer yourself.
That has one consequence for dark mode. A rule outside a layer beats every rule inside one, whatever their
specificity, so your :root values also beat the library’s .dark values: a token you set on :root and not in a
.dark block of your own keeps its light value in dark mode. Give every token you change a dark value too, in a
.dark block after the :root one. The two selectors have the same specificity, so the later one wins while the
dark class is on <html>.
The variables have shadcn/ui’s names, so a theme from a shadcn theme builder, such as
tweakcn or shadcn’s own, can be pasted in unchanged.
The colours, --radius and the fonts (--font-sans, --font-mono) apply. The shadows do not: each skin has its own,
so a builder’s --shadow-* variables change nothing. Leave them out, or write your own rules
for the shadows you want.
Shadleaf adds a few of its own, which such a theme leaves at their defaults:
| Token | What it colours |
|---|---|
--success, --info, --warning |
Status colours, next to shadcn’s --destructive. Every part below mixes from them. |
--success-icon, --info-icon, --warning-icon, --error-icon |
A toast’s icon. |
--{success,info,warning,error}-{bg,border,text,description,close} |
A toast’s other parts, with the toaster’s rich-colors. |
4. Skin
Section titled “4. Skin”shadleaf.skin=lyraA skin changes geometry, spacing, type size and shadow: the same markup and the same tokens, a different look. There are nine:
| Skin | Look |
|---|---|
vega |
The default: the classic look, clean and neutral. |
lyra |
Boxy and sharp: square corners, small type and a thin focus ring. |
nova |
Reduced padding and margins: vega one size smaller, with a muted footer. |
maia |
Rounded, with generous spacing: pill-shaped buttons and fields. |
mira |
Made for compact interfaces: small type and 28px controls. |
luma |
Fluid, luminous and soft: maia’s shapes, borderless fields, soft shadows. |
rhea |
Like luma, but compact: smaller controls, tighter menus and tables. |
sera |
Editorial and typographic: square, uppercase labels, underlined fields. |
The ninth, sketch, makes the components look hand-drawn, as a wireframe in Balsamiq does, for mockups and
prototypes that should not pass for the finished application. Pencil lines with uneven corners, wavy underlines, hatched
skeletons and a handwritten font, Balsamiq Sans, which ships with the skin (SIL Open Font License). It sets that font on
the page’s body, so your headings and text are handwritten too; a font of your own on the body wins. The colours still
come from the tokens: a theme applies, and the pencil is --foreground.
Token overrides keep working under every skin. Use the skin switch on any preview in these docs to compare.
5. Your own CSS rules
Section titled “5. Your own CSS rules”When tokens and a skin are not enough (a gradient, a border on every button, a hard shadow), write CSS against the
components’ styling hooks: the class named after each component and its parts, and the data-* and aria-*
attributes the library styles them by.
.button[data-variant='outline'] { border-width: 2px; box-shadow: 2px 2px 0 var(--foreground);}
.sidebar-menu-button[aria-current='page'] { font-weight: 700;}Every component’s page lists its hooks in a Styling hooks section, after its attributes, in three groups:
- Parts: the class of the component’s own element and of each element inside it, such as
.buttonand.button-spinner. - Props: the attributes that reflect a prop, such as
data-variantforvariant. Such an attribute is absent while the prop has its default value, so select the default with:not([data-variant]). - States: the attributes the component, or its script, sets for a state, such as
aria-current="page"on the link of the current page oraria-expanded="true"on a trigger whose menu is open.
Point at a group to copy it as an empty stylesheet, one rule per selector, to fill in.
The hooks are an API, as the props are: a minor version does not rename or remove one.
As with tokens, the library’s rules sit in a cascade layer (components), so a rule of yours outside a layer wins over
the skin’s whatever its specificity. A rule inside a layer of your own only wins if that layer comes later in the
layer order than components.
6. Own the template
Section titled “6. Own the template”Copy a component’s template from the jar, for example templates/sl/components/button.html, into your application’s
src/main/resources/templates/sl/components/. Your copy wins, props included, with no configuration.
Your copy no longer receives the library’s fixes, so compare it with the new version when you upgrade. A test that renders a page using the component keeps it honest.
You can add components of your own the same way: a template at templates/sl/components/badge.html is <sl:badge>.