Composition
The component pages show each piece on its own. This page is about how they fit together: which piece owns colour, which owns spacing, which owns text, and where the seams between them are. Each component page ends with a Composition section showing that component in common combinations.
Examples on this page and in each component's Composition section use the class build. Layout that the framework leaves to you, such as a grid, is written inline so you can see it.
Who owns what
Every piece of markup plays one of five roles. Most mistakes come from asking
one piece to do another's job, such as giving a grid wrapper
.prose, or a card a margin.
| Role | Pieces | Owns |
|---|---|---|
| Layout | .container, .flex, .navbar, CSS grid |
Width, columns, and the gap between siblings. No colour, no text spacing. |
| Surface | .card, .card-border, .dialog-box, .dropdown-content |
A background, a border or shadow, and inner padding. Nothing outside its edge. |
| Text | .prose, .text-secondary, .link, .badge |
Vertical rhythm between headings, paragraphs and lists, and the colour of words. |
| Control | .label, .input, .btn, .fieldset |
Its own box, its own bottom margin, and its states. |
| Boundary | .retheme, data-color-scheme, .disabled, .error |
The colour of everything inside it. Draws nothing itself. |
A section of a page is usually one of each, nested in that order: a layout places surfaces, a surface holds text and controls, and a boundary can wrap any of them.
Surfaces
There are three colours to stand on. --surface is the page.
.card raises a block onto --fill with a shadow.
.card-border stays on --surface and draws a
--line border instead.
Surfaces are solid colours, mixed into the page rather than laid over it, so a
card inside a card is the same colour as its parent and does not darken. To
separate something inside a card, put it on a .card-border, which
drops back to the page colour, or split the card with a
.divider or .card-actions.
Below: text on the page, a service on a .card, and a download on
a .card-border.
<div class="prose">
<p>Text on the page sits on <code>--surface</code>.</p>
</div>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: var(--padding)">
<article class="card prose">
<h3>A service</h3>
<p>What it is, in a line.</p>
</article>
<article class="card-border prose">
<h3>A download</h3>
<p class="flex"><a href="#" class="link">PNG</a> <a href="#" class="link">SVG</a></p>
</article>
</div>
- Use
.cardfor the thing you want looked at: a service you sell, a call to action. - Use
.card-borderfor many items of equal weight, such as a grid of downloads, where a shadow on each would be noise. - A surface sets padding and nothing else outside itself. Space between surfaces comes from the layout around them.
Spacing
Spacing comes from two places, and they do not overlap.
-
Between siblings in a layout: the gap.
.flexhas a1remgap; a grid should usegap: var(--padding). -
Down a column of content: bottom margins. Form controls,
labels, alerts and every block inside
.prosecarry a1rembottom margin, so a stack of them spaces itself with no wrapper.
Nothing carries a top margin, so the first child of any box sits flush with
its padding. The last child keeps its bottom margin, which is why
.card-actions exists: a footer row gives the end of a card its
own rule and spacing.
The two meet in one place: a .flex .flip row of form fields. Side
by side, the gap separates them. Stacked on a phone, the gap lands on top of
each label's own bottom margin and doubles the space. Set
row-gap: 0 on such a row and let the margins do the stacking.
--padding sizes the inside of many components: badges,
alerts, menus, the navbar, segmented controls and .card-border.
Set it on a section to tighten or loosen those insides together. The
1rem margins between blocks stay as they are.
<div class="flex flip">
<div class="card-border" style="flex: 1">
<span class="badge">default</span>
<p class="text-secondary" style="margin-top: 0.5rem">--padding: 1rem</p>
</div>
<div class="card-border" style="flex: 1; --padding: 0.5rem">
<span class="badge">tight</span>
<p class="text-secondary" style="margin-top: 0.5rem">--padding: 0.5rem on the card</p>
</div>
</div>
Text
The reset removes every margin, and the class build does not style bare
elements. Headings, paragraphs and lists stack with no space between them
until something inside .prose spaces them.
Put .prose on the box that holds the words: a card, a section's
text column, an article body. Do not put it on a layout wrapper.
.prose also spaces section, ul and
pre, so on a grid it would add margins between your columns.
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: var(--padding)">
<div class="card-border">
<h3>No prose</h3>
<p>Heading and paragraph touch.</p>
<p>So do paragraphs.</p>
</div>
<div class="card-border prose">
<h3>With prose</h3>
<p>The card spaces its own text.</p>
<p>The grid around it is untouched.</p>
</div>
</div>
Three classes colour words without spacing them. .text-secondary
is for supporting text: a lede, a date, a caption. .link is for
words that navigate. .badge is for a short label attached to
something else, such as a tag or a count.
Actions
Buttons come in three weights, and a region should have one filled button.
.btn is the primary action, .btn-secondary the
alternative, .btn-ghost anything that should recede, such as a
menu toggle in a header. Links navigate; buttons do things.
When a whole card is the link, make the card the anchor:
<a class="semantic card">. .semantic strips the
link styling and .card comes later in the cascade, so the surface
wins. Then mark the words that read as the link, here the title, with
.link so the card still looks clickable. Inside a grid or flex
row the anchor is laid out as a block, so it needs nothing else.
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: var(--padding)">
<a href="#" class="semantic card prose">
<h3 class="link">Project one</h3>
<p>What it was and how it turned out, in a sentence or two.</p>
</a>
<a href="#" class="semantic card prose">
<h3 class="link">Project two</h3>
<p>What it was and how it turned out, in a sentence or two.</p>
</a>
</div>
Forms
A .label is the unit of a form. It wraps a <p>
for the label text, the control, and an optional <small>
for help or an error, and it spaces all three. Put a checkbox or toggle inside
a .label and it becomes a row instead. Group related labels in a
.fieldset with a .fieldset-legend.
The <small> is inline-block, so after a field
narrowed with max-width it sits beside the field instead of under
it. Give it display: block, as the newsletter form below does.
States are generic. aria-invalid="true" or .error on
a control turns it, and the label text above it, to the error colour.
Disabling a <fieldset> greys everything inside it, because a
disabled element is a boundary that sets --chroma: 0 for its
subtree.
Below: a sign-up form with a bad address entered, and a group of filters.
<form class="prose">
<h2>Newsletter</h2>
<p>A short note when there is something new.</p>
<label class="label">
<p>Email</p>
<input class="input" type="email" value="name@" aria-invalid="true" style="max-width: 30rem" />
<small style="display: block">Enter a full email address.</small>
</label>
<button class="btn btn-secondary">Subscribe</button>
</form>
<form style="margin-top: var(--padding)">
<fieldset class="fieldset">
<legend class="fieldset-legend">Filter</legend>
<div class="flex" style="flex-wrap: wrap">
<label class="label"><input type="checkbox" class="checkbox" checked /> In stock</label>
<label class="label"><input type="checkbox" class="checkbox" /> Free</label>
<label class="label"><input type="checkbox" class="checkbox" /> On sale</label>
</div>
</fieldset>
</form>
Colour boundaries
Colour is never set on a component. It is set on a region, and everything in the region derives from it. Two attributes draw those regions.
-
.rethemewith an input such as--primaryre-themes a subtree: a partner's block in their colours, or an error region. -
data-color-scheme="dark"or"light"flips a subtree's scheme and paints its background, so a band can sit dark on a light page with no extra classes.
A boundary draws nothing on its own, so put it on the element that already exists for layout, such as the section or the card, rather than adding a wrapper.
Below: a section in one brand colour, with a credit block inside it in another. Boundaries nest, and each one reaches only its own subtree.
<section class="retheme" style="--primary: #a33b2b; display: grid; gap: var(--padding)">
<div class="prose">
<h3>The site's own section</h3>
<p>Everything here takes the section's colour.</p>
<a href="#" role="button" class="btn">Browse the catalog</a>
</div>
<aside class="card-border retheme prose" style="--primary: rebeccapurple">
<h3>Built by a partner</h3>
<p>This block takes the partner's colour instead.</p>
<a href="#" role="button" class="btn">Visit the partner</a>
</aside>
</section>
Layout
The framework gives you a page width, a row, and a bar. Everything else is
CSS grid with var(--padding) as the gap.
| Need | Use |
|---|---|
| A page column | .container, once per page, around the main content |
| A full-width band with padded content | .container-fluid |
| A row that stacks on phones | .flex .flip; add .reverse to put the second item first |
| A header | .navbar with .navbar-start and .navbar-end |
| A grid of cards | grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)) |
See Layout for the breakpoints, and the Composition section at the end of each component page for these rules at work.