Base elements
elements man style/baseThe base stylesheet styles bare HTML elements. Write semantic markup (<h1>,
<p>, <a>, <ul>, <table>, <code>) and it is styled with no classes. This is
base.css in @layer base.
Base rules are in the base cascade layer, which is declared before
components and utilities. A rule in a later layer applies over a rule in
an earlier layer regardless of selector specificity, so a component or utility
class you add to an element overrides its base style. A rule of your own
written outside any layer overrides it too. You never need !important to
override a base style.
Spacing
Base rules space flow content. Headings, paragraphs, lists, quotes, tables, figures, forms and rules carry vertical margins, so an ordinary page reads as a document without a single class.
Margins collapse between siblings, so a heading's bottom margin and the
following paragraph's top margin resolve to the larger of the two rather than
adding up. First and last children reset their outer margin, so a padded
container (a .card, a .callout) never has extra space between its padding
and its first or last child.
The layout classes .stack, .cluster and .row space their children with
gap instead, so they set the flow margins of their direct children to zero.
The space between two children is the gap alone, never the gap plus a margin.
Base rules set no width
base.css styles elements. It sets no width, no centering and no page padding
on any element, so width, centering and page padding come only from the
classes you add.
Width comes from layout (opens in a new tab), where it is named and visible in the markup:
Page shell<main class="page-shell"> <h1>A page</h1> <p>Measured, centred, with a gutter.</p> </main>
.page-shell is 72rem. .is-prose narrows it to 65ch for an article,
.is-narrow, .is-marketing and .is-wide set other widths, and
.is-full removes the maximum width. elements create page writes
.page-shell into the new page, so a generated page already has a width.
A <main> with no class gets no width, by design: a class adds styling, and
no class is ever needed to remove a default.
A page is a template named <html>, so <html class="page-chat"> puts
page-chat on the <html> element, not on the body:
Page template<html class="page-chat"> <main> <h1>A page</h1> </main> </html>
elements create page chat writes the page- prefix. A bare .chat there
would share a namespace with every component class in the app, and a .chat
rule written for a widget would match <html> and restyle the whole document.
Use the page class to scope custom properties and theming, not to set
layout. Layout written against it applies to <html>, which makes <body> a
child box of whatever you declared: give <html> a grid and a height and the
body becomes a shrink-to-fit grid item. Put layout on an element inside the
page instead, and use .app in layout (opens in a new tab) when you want a
full-height application shell.
No base rule limits the line length of running text. Line length is set by
the width of the container: .page-shell.is-prose is 65ch wide, so the text
inside it wraps at 65ch.
Because the width is set on the container and not on the text, text inside a
component lines up
with the component: a paragraph in a text-align: center hero centres under
the heading above it.
Colored containers
Put anything in a container that sets a color and the text inside inherits
it, headings and paragraphs included:
Colored container<div style="background: #0b1f30; color: white"> <h2>Readable</h2> <p>So is this.</p> </div>
This works because base rules set color on almost nothing. html and body
supply --ink for the document, and everything below them inherits. Only
elements that carry their own background set a color of their own (code,
pre, kbd, mark, ::selection). Those elements set both their
background and their text color, so their text stays legible whatever color
the container sets.
Elements that are meant to read softer than body text (dd, blockquote,
th, figcaption) use --ink-soft-flow, which is derived from
currentColor. They stay soft on a normal page and still follow the container
on a colored one.
Links adapt too, taking their lightness from the text around them. See links below.
Document
html and body set the sans font, base font size, body line height, --ink
text, and --bg background. In dark mode the theme gives --ink and --bg their dark values, so both
change.
Headings
h1–h6 form a modern scale, with semibold, tight leading, tightened
tracking on the larger sizes:
| Element | Size |
|---|---|
h1 |
--text-4xl (48px) |
h2 |
--text-3xl (36px) |
h3 |
--text-2xl (30px) |
h4 |
--text-xl (24px) |
h5 |
--text-lg (20px) |
h6 |
--text-base (16px) |
Links
Bare <a> renders as an underlined link with a soft underline that solidifies
on hover and a focus ring on :focus-visible. The rule's selector is wrapped
in :where(), which gives it zero specificity, so link component classes
(.button, .link-action, and the like) override it even within the same
layer.
The theme sets the color. A bare <a> takes --link. A branded theme
sets it from the accent, so links follow your brand, and the default theme sets
it to the ink, so links render as the surrounding text plus the underline. To
brand links under the default theme, set --link:
Link color:root { --link: var(--accent); }
Without --link, as with the base stylesheet on its own, a link takes its
lightness from the text around it, nudged a fifth further from mid-grey, and
its hue and chroma from --link-c and --link-h, or from that text when they
are unset. The chroma is capped to what sRGB can show at that lightness, so
the link stays in gamut. See branding (opens in a new tab).
Focus
Anything focusable shows a ring. Links, buttons, inputs, summary and the
interactive components each draw their own; every other focusable element,
including one you make focusable with tabindex, gets a 2px --focus outline
from a rule in the base layer. A focusable control you have not styled still
shows a focus state.
Forms
A bare form is a stack of labels and controls with no wrapper, so base makes
the form itself a one-column grid and spaces it with a gap: fields are
separated, and a label sits tight against the control it names.
The spacing is a gap on the form and not a margin on its children, so it
follows whatever layout you give the form. Give a form display: flex to put
an input beside its button and the gap becomes the space between the two, with
no margin left under the button and no class to add. form.is-grid lays
fields out in two columns, also spaced with a gap.
Form<form> <label for="email">Email</label> <input id="email" type="email"> <button type="submit">Sign up</button> </form>
For validation states, hints, inline errors and grouped controls, use the form components in form (opens in a new tab).
Lists
A bare ul gets discs, a bare ol gets decimals, both indented, with nested
lists stepping through circle and square. The reset strips markers first so a
nav or a menu built from <ul> starts clean, and the layout primitives strip
them again for exactly that case: <ul class="cluster"> is a row of links, not
a bulleted list.
Definition lists render dt semibold and dd in --ink-soft-flow.
Items get no space between them and dd gets no indent, so a list you lay out
as a row or a grid (breadcrumbs, a card grid, a stat row) lines up without
undoing anything. Long-form text in .prose gets both: a little space between
list items and an indented dd.
Quotes and rules
blockquote gets a left rule and italic --ink-soft-flow text. hr is a single
--rule top border.
Code, pre, kbd
code: monospace, on a--bg-mutedfill with small padding and--radius-xs.pre: monospace block on--bg-inversewith--ink-inversetext,--radius-surface, and horizontal scroll.pre coderesets its own fill so nested code doesn't double up.kbd: a small keycap: monospace, muted fill, a--ruleborder and a subtle bottom shadow.
<pre> uses --bg-inverse, so it flips with the theme (dark block in light
mode, light block in dark mode). The terminal component is different: it stays
dark in both modes. See terminal (opens in a new tab).
Icons
Size every svg on the tag, with width and height. An svg carrying only
a viewBox fills whatever contains it, so an icon paints full-page for as long
as it takes its CSS to arrive. The width and height attributes
are in the HTML, so they apply before any stylesheet loads.
Icon size<svg width="24" height="24" viewBox="0 0 24 24" aria-hidden="true">
Mark a decorative icon aria-hidden="true". An icon that conveys meaning with
no text beside it needs a label instead.
Mark
mark is a highlight using the warning tint (--warning-soft on
--warning-ink).
Tables
table is full-width with small text and collapsed borders. thead gets a
bottom rule, body rows get soft top rules between them, th is left-aligned
semibold --ink-soft-flow, and td is top-aligned with comfortable padding.
figcaption renders as small --ink-soft-flow caption text.
For a more editorial table or long-form content, wrap it in .prose (see
typography (opens in a new tab)).
Selection
::selection tints the highlight with the accent color, so selected text is
highlighted in your brand color once you set --accent.