--- author: [Teemu Lahjalahti](https://www.linkedin.com/in/teemulahjalahti/) index: https://salty-css.dev/llms.txt --- # Variants A variant is a named branch of a style, picked at the call site. `size="large"`, `tone="danger"`, a `loading` flag — one axis, a few values on it, every branch compiled to plain CSS before your app ever runs. This page exists because variants aren't really a feature of `styled`. They're a *shape* that turns up in three places — [`styled`](/astro/docs/basics/styled-components), [`className`](/astro/docs/basics/class-names), and [`defineTemplates`](/astro/docs/basics/templates) — with the same five keys and the same semantics each time. Only the way you switch one on changes. Learn the shape once and the third one is free. And to get the obvious out of the way: not *that* kind of variant — no sacred timeline, no TVA. Just a class name that's either on the element or isn't, and the only thing monitoring it is the cascade. ## Why a variant, and not something else Three things could all express "this button is large," and it's worth being precise about why this one wins. **Not a second component.** `Button`, `LargeButton`, `PrimaryButton`, `LargePrimaryButton` — two axes with three values each is nine components, and every one of them is a place for the padding to drift. Variants keep it as one component with two knobs. The [Styled API](/astro/docs/basics/styled-components) page calls this thinking in *axes* rather than in branches, and it's the whole reason the API is shaped this way: `base` is what's true no matter what, variants are the named dimensions stacked on top, and the states your component can be in are the combinations. **Not a style object computed at render.** You could branch in JavaScript and hand the result to a `style` prop. That works, and it moves styling into the render path — a new inline declaration per element, no cascade, no cache, nothing shared between instances. A variant is decided *before* your app runs. What ships is a stylesheet; the prop only chooses which class is on the element. **Not a loose class name.** A string has no contract. A variant name is a typed prop, so your editor lists the axes, autocompletes the values, and a typo is a compile error rather than a component that silently renders unstyled. The cost, plainly: the compiler can't know which props you'll pass, so **every value you declare is compiled into the stylesheet whether a call site ever uses it or not**. A ten-value axis you use two of is eight rules of dead weight in `saltygen/index.css`. In practice that's cheap — the CSS is static, hashed, deduplicated, and cached — but it's a real reason to keep axes small and deliberate rather than enumerating every value a designer might one day want. ## The shape, once Five keys, and they mean the same thing on all three APIs. | Key | What it does | | :-- | :-- | | `variants` | The axes. Each name is one dimension; each value under it is one branch. | | `defaultVariants` | Which branch applies when nobody picks. | | `compoundVariants` | Extra styles when **all** the listed values are active — AND. | | `anyOfVariants` | Extra styles when **any** of them is — OR. Zero specificity by design. | | A `true` / `false` value | The boolean form. Declare only the side you want to style. | What changes between the three is how a branch gets switched on: | API | You activate a variant by… | Defaults applied for you? | | :-- | :-- | :-- | | `styled` | passing a prop — ` ``` Two behaviours worth holding onto. Variant props are **consumed by Salty and don't reach the DOM** — the rendered `