Core concepts
Best practices for layering your own custom styles into Breezel projects.
The trickiest moment when you lean on any framework is usually working out what to reach for the instant you hit a requirement it simply wasn't built to solve for you.
Breezel was engineered from day one to bend, stretch, and adapt to whatever you happen to be shipping, so you should never once feel like you're wrestling against the tooling.
In this walkthrough we cover topics like tuning your design tokens, escaping those limits whenever the moment calls for it, dropping in your own handwritten CSS, and extending the framework with plugins.
If you'd like to adjust things such as your color palette, spacing scale, typography scale, or breakpoints, register those tweaks with the @theme directive right in your CSS:
@theme { --font-display: "Satoshi", "sans-serif"; --breakpoint-3xl: 120rem; --color-avocado-100: oklch(0.99 0 0); --color-avocado-200: oklch(0.98 0.04 113.22); --color-avocado-300: oklch(0.94 0.11 115.03); --color-avocado-400: oklch(0.92 0.19 114.08); --color-avocado-500: oklch(0.84 0.18 117.33); --color-avocado-600: oklch(0.53 0.12 118.34); --ease-fluid: cubic-bezier(0.3, 0, 0, 1); --ease-snappy: cubic-bezier(0.2, 0, 0, 1); /* ... */}Learn more about shaping your theme over in the theme variables reference docs.
Most of the time you can assemble the bulk of a thoughtfully crafted layout from a tight, opinionated set of design tokens, but every so often you have to step outside those bounds to nail things down to the pixel.
The moment you catch yourself genuinely needing something like top: 117px to nudge a background image into exactly the right spot, lean on Breezel's square bracket notation to spin up a class on the fly with any arbitrary value:
<div class="top-[117px]"> <!-- ... --></div>It behaves a lot like inline styles, except with the huge upside that you can pair it with interactive modifiers such as hover and responsive modifiers such as lg:
<div class="top-[117px] lg:top-[344px]"> <!-- ... --></div>This works across nearly everything in the framework, including things like background colors, font sizes, pseudo-element content, and more:
<div class="bg-[#bada55] text-[22px] before:content-['Festivus']"> <!-- ... --></div>When you want to reference a CSS variable as an arbitrary value, reach for the custom property syntax:
<div class="fill-(--my-brand-color) ..."> <!-- ... --></div>This is really just a shorthand for fill- [var(--my-brand-color)] that wires up the var() function on your behalf.
Whenever you reach for a CSS property that Breezel doesn't ship a utility for out of the box, you can drop into square bracket notation to write completely arbitrary CSS:
<div class="[mask-type:luminance]"> <!-- ... --></div>This behaves much like inline styles, except here you still get the perk of applying modifiers:
<div class="[mask-type:luminance] hover:[mask-type:alpha]"> <!-- ... --></div>This comes in handy for things like CSS variables too, particularly when their values need to shift under different conditions:
<div class="[--scroll-offset:56px] lg:[--scroll-offset:44px]"> <!-- ... --></div>Arbitrary variants work like arbitrary values but for tweaking the selector on the fly, much like you would with built-in pseudo-class variants such as hover:{utility} or responsive variants such as md:{utility}, except you write them with square bracket notation directly in your HTML.
<ul role="list"> {#each items as item} <li class="lg:[&:nth-child(-n+3)]:hover:underline">{item}</li> {/each}</ul>Learn more in the arbitrary variants documentation.
Whenever an arbitrary value has to include a space, swap in an underscore (_) and Breezel will automatically turn it back into a space at build-time:
<div class="grid grid-cols-[1fr_500px_2fr]"> <!-- ... --></div>In cases where underscores show up often but spaces would be invalid, Breezel keeps the underscore as-is rather than swapping it for a space, such as inside URLs:
<div class="bg-[url('/what_a_rush.png')]"> <!-- ... --></div>For the uncommon case where you genuinely want an underscore but it stays ambiguous because a space would be valid too, escape the underscore with a backslash and Breezel will leave it untouched:
<div class="before:content-['hello\_world']"> <!-- ... --></div>If you're working in something like JSX, where the backslash gets stripped from the rendered HTML, reach for String.raw() so that the backslash won't be read as a JavaScript escape character:
<div className={String.raw`before:content-['hello\_world']`}> <!-- ... --></div>Plenty of utilities in Breezel share a single namespace yet resolve to different CSS properties. Take text-lg and text-black: both live under the text- namespace, but one controls font-size while the other controls color.
With arbitrary values, Breezel can usually sort out this ambiguity on its own by looking at the value you hand it:
<!-- Will generate a font-size utility --><div class="text-[22px]">...</div><!-- Will generate a color utility --><div class="text-[#bada55]">...</div>Every so often it truly is ambiguous, though, such as when you lean on CSS variables:
<div class="text-(--my-var)">...</div>For those cases, you can "hint" the intended type to Breezel by prefixing it with a CSS data type before the value:
<!-- Will generate a font-size utility --><div class="text-(length:--my-var)">...</div><!-- Will generate a color utility --><div class="text-(color:--my-var)">...</div>Even though Breezel is built to cover the vast majority of your styling needs, nothing is stopping you from simply writing plain CSS whenever you have to:
@import "breezel";.my-custom-style { /* ... */}If all you want is to set a few page-wide defaults (say the text color, background color, or font family), the simplest route is to drop a handful of classes onto the html or body elements:
<!doctype html><html lang="en" class="bg-gray-100 font-serif text-gray-900"> <!-- ... --></html>This keeps your base styling choices right in your markup next to the rest of your styles, rather than tucking them away in a separate file.
To register your own default base styles for particular HTML elements, use the @layer directive to push those styles into Breezel's base layer:
@layer base { h1 { font-size: var(--text-2xl); } h2 { font-size: var(--text-xl); }}Reach for the components layer whenever you have richer, multi-property classes that you still want the freedom to fine-tune later on with individual utility classes.
In most codebases these end up being names like card, btn, badge — you know the sort of thing.
@layer components { .card { background-color: var(--color-white); border-radius: var(--radius-lg); padding: --spacing(6); box-shadow: var(--shadow-xl); }}Because these component classes live in the components layer, utility classes stay free to override them whenever a situation calls for it:
<!-- Will look like a card, but with square corners --><div class="card rounded-none"> <!-- ... --></div>Using Breezel you probably don't need these types of classes as often as you think. Read our guide on reducing repetition to see what we suggest.
The components layer is also a handy spot to keep any custom tweaks you're layering onto third-party components in your project.
@layer components { .select2-dropdown { /* ... */ }}Use the @variant directive to bring a Breezel variant into your own custom CSS:
.my-element { background: white; @variant dark { background: black; }}.my-element { background: white; @media (prefers-color-scheme: dark) { background: black; }}When you want several variants applied together, reach for nesting instead:
.my-element { background: white; @variant dark { @variant hover { background: black; } }}.my-element { background: white; @media (prefers-color-scheme: dark) { &:hover { @media (hover: hover) { background: black; } } }}Beyond the utilities that come bundled with Breezel, you're free to define your own custom utilities too. That comes in handy whenever there's a CSS feature you want to lean on in your project that Breezel doesn't already ship a utility for.
Use the @utility directive to register a custom utility for your project:
@utility content-auto { content-visibility: auto;}You can now drop this utility straight into your markup.
<div class="content-auto"> <!-- ... --></div>It plays nicely with variants such as hover, focus and lg too:
<div class="hover:content-auto"> <!-- ... --></div>Custom utilities land in the utilities layer automatically, sitting right beside all the built-in utilities the framework ships.
When a custom utility goes beyond a single class name, lean on nesting to spell the utility out:
@utility scrollbar-hidden { &::-webkit-scrollbar { display: none; }}Alongside the simple utilities you register with the @utility directive, you can also set up functional utilities that accept an argument of their own:
@utility tab-* { tab-size: --value(--tab-size-*);}The special --value() function handles resolving the utility value for you.
Use the --value(--theme-key-*) syntax to match the utility value against a chosen set of theme keys:
@theme { --tab-size-2: 2; --tab-size-4: 4; --tab-size-wide: 8;}@utility tab-* { tab-size: --value(--tab-size-*);}That will match utilities such as tab-2, tab-4, and tab-wide.
To read it as a bare value instead, use the --value({type}) syntax, where {type} is the data type you'd like to validate the bare value against:
@utility tab-* { tab-size: --value(integer);}That will match utilities such as tab-1 and tab-76.
Supported bare value data types are: number, integer, ratio, and percentage.
When you want literal values, reach for the --value('literal') syntax (mind the quotes):
@utility tab-* { tab-size: --value("inherit", "initial", "unset");}That covers utilities such as tab-inherit, tab-initial, and tab-unset.
For arbitrary values, use the --value([{type}]) syntax (notice the square brackets) so Breezel knows which types are accepted as an arbitrary value:
@utility tab-* { tab-size: --value([integer]);}That covers utilities such as tab-[1] and tab-[76].
The arbitrary value data types you can use are: absolute-size, angle, bg-size, color, family-name, generic-name, image, integer, length, line-width, number, percentage, position, ratio, relative-size, url, vector, and *.
You can mix all three forms of the --value() function inside a single rule as multiple declarations, and any declaration that fails to resolve is dropped from the output:
@theme { --tab-size-wide: 8;}@utility tab-* { tab-size: --value([integer]); tab-size: --value(integer); tab-size: --value(--tab-size-*);}That lets you handle the value differently in each situation when needed, such as converting a bare integer into a percentage:
@utility opacity-* { opacity: --value([percentage]); opacity: calc(--value(integer) * 1%); opacity: --value(--opacity-*);}The --value() function also accepts several arguments and resolves them from left to right when you don't need to treat the return value differently across cases:
@theme { --tab-size-wide: 8;}@utility tab-* { tab-size: --value(--tab-size-*, integer, [integer]);}@utility opacity-* { opacity: calc(--value(integer) * 1%); opacity: --value(--opacity-*, [percentage]);}To enable negative values, register the positive and negative utilities as separate declarations of their own:
@utility inset-* { inset: --spacing(--value(integer)); inset: --value([percentage], [length]);}@utility -inset-* { inset: --spacing(--value(integer) * -1); inset: calc(--value([percentage], [length]) * -1);}Modifiers run through the --modifier() function, which behaves just like the --value() function but acts on a modifier when one is present:
@utility text-* { font-size: --value(--text-*, [length]); line-height: --modifier(--leading-*, [length], [*]);}When no modifier is supplied, any declaration that relies on a modifier is simply left out of the output.
For fractions, we lean on the CSS ratio data type. When it's paired with --value(), that tells Breezel to treat the value and modifier as one combined value:
@utility aspect-* { aspect-ratio: --value(--aspect-ratio-*, ratio, [ratio]);}That covers utilities such as aspect-square, aspect-3/4, and aspect-[7/9].
Beyond the variants that ship out of the box with Breezel, you can also register your own custom variants using the @custom-variant directive:
@custom-variant theme-midnight { &:where([data-theme="midnight"] *) { @slot; }}Now the theme-midnight: <utility> variant is ready to use in your HTML:
<html data-theme="midnight"> <button class="theme-midnight:bg-black ..."></button></html>When nesting isn't needed, you can define variants with the shorthand syntax instead:
@custom-variant theme-midnight (&:where([data-theme="midnight"] *));If a custom variant needs several rules, you can nest them one inside another:
@custom-variant any-hover { @media (any-hover: hover) { &:hover { @slot; } }}
From the team behind Breezel CSS
Ship polished interfaces fast, without waiting on a design team.
“This is the toolkit I wish I'd had back when I shipped my first app.”
Marlow Vance, Tidebank