Style
elements man styleThe Elements design system: the stylesheet in @elements/ui. A set of CSS files
that give an Elements app a complete look: semantic design tokens whose values
are steps of OKLCH color ramps, base rules that style bare HTML elements with
no classes, a small family of component classes, atomic utilities, dark mode,
and a monochrome default theme that takes your brand color when you set the
--accent token.
The stylesheet is CSS only: you import CSS and write HTML with classes.
To make a component interactive, such as a tab that switches panels or a menu
that opens, toggle its is- state classes from the event handlers and
directives in your Elements HTML template. The package contains no JavaScript,
so the code that changes a component's state is written in one place, the
template, next to the state it reads; there is nothing to import into a .ts
file, and the package has no runtime or build step of its own. Everything
documented here is styling applied by importing CSS and adding classes.
This page is the quick reference. Every section links to a chapter that covers it in full.
Getting Started
A scaffolded app already imports the package: app/shared/styles/page.css
imports the package and every page's style.css imports page.css. Those two
imports put the package's CSS in every page's bundle. A page's CSS is every stylesheet reachable
by import from its <html> template, the template's own imports then each
child template's imports, depth first. A rule written in another page's
style.css is not in that set, so markup copied from one page renders
unstyled on the next until you move the rule into a stylesheet both pages
import, such as app/shared/styles/page.css. See
html/templates.
The import is one line, and elements create has already written it:
app/shared/styles/page.css@import "@elements/ui";
That one import loads the tokens, the reset, base element styling, typography, and every component and utility. From there you write HTML:
Example<main class="page-shell"> <div class="stack is-lg"> <h1>Account</h1> <p class="lede">Manage your profile and billing.</p> <div class="card"> <div class="card-head"> <h2>Profile</h2> </div> <div class="card-body"> <form class="is-grid"> <div class="field"> <label>First name</label> <input> </div> <div class="field"> <label>Last name</label> <input> </div> <div class="field is-full"> <label>Email</label> <input type="email"> <p class="hint">We'll never share it.</p> </div> </form> </div> <div class="card-foot"> <button class="is-ghost">Cancel</button> <button class="is-primary">Save</button> </div> </div> </div> </main>
See install (opens in a new tab) for the subpath export map and the style files
elements create writes.
The Naming Rule
Every class name in the system follows one rule:
A bare noun names an element or component. An
is-adjective names how it renders.
-
Elements and components are bare nouns:
<button>,<input>,.card,.callout,.pill,.field,.tab,.terminal. -
Component parts carry the family prefix, a part named after its parent:
.card-head,.card-body,.callout-title,.pill-dot,.tab-list,.tab-panel. -
Modifiers and state use
is-, an adjective describing how the noun renders, meaning the same thing everywhere:is-primary,is-ghost,is-danger,is-sm,is-lg,is-block,is-active,is-error,is-ok,is-loading,is-disabled. -
Atomic utilities are named for the property or value they set and never take
is-:.text-sm,.bg-soft,.font-mono,.gap-4,.hidden.
Each is- modifier changes one aspect of the element (its intent, size,
width or state), so modifiers combine in any order:
Example<button class="is-primary is-lg is-block">Sign up</button> <input class="is-sm is-error"> <div class="callout is-warning">Heads up</div>