Center
.center
.center — the column a page is read in, and the gutter beside it.
Examples
Milano Centrale
Departures and arrivals, straight from the operator's own board.
<main class="center center-prose stack">
<h1>Milano Centrale</h1>
<p>Departures and arrivals, straight from the operator's own board.</p>
</main>Two decisions in one class: how wide the column is, and how far the text stays from the edge of the screen.
Eight consumers of this library had written both by hand, every one of them as .wrap. It spaces nothing — that is stack, and the two compose.
A form is narrower than the page it sits on.
<section class="center" style="--center-max: 30rem">
<p>A form is narrower than the page it sits on.</p>
</section>--center-max on the element is the escape the variants do not have to anticipate, and --center-gutter: 0 is the other one — for a column that sits inside something already padded, like a dialog-body.
When is the next one
<section class="hero">
<div class="center">
<h1 class="hero-title">When is the next one</h1>
</div>
</section>A section with its own background runs the whole width and puts the column inside it, which is why hero ships no inner container.
Centring the band itself instead leaves the colour stopping short of the edge of the screen.
Tokens 2
Level 2, declared on .center itself. Set any of them on that selector to restyle this utility without touching the skin.
| Token | Default |
|---|---|
| --center-gutter | var(--space-4) |
| --center-max | var(--container) |
Variants and states
Variants
.center-full.center-narrow.center-prose.center-wide
State it reads
None.
Before you ship it
What you have to do 4 requirements
- Put it on a wrapper, not on the band. A section that paints a background and carries this class stops its own colour short of the edge of the screen — which reads as a rendering fault rather than as a column.
- Nest it once. A
centerinside acentertakes the gutter twice, so the inner column is 2rem narrower than it says it is. Where a region needs its own width, set--center-maxon it instead of wrapping it again. - Add
stackwhen the children need spacing. This class owns the column and the gutter and nothing else; a page that wants both writes both, which is the point of two primitives rather than one page layout. - Say the width in a token, not a number. If a column needs a size none of the four variants gives,
--center-maxtakes any length — but a literal copied into two stylesheets is how eight consumers ended up with the same unexplained 46rem.
src/css/utilities/center.css · npx mostlycss add center