Typographic content container with vertical rhythm. Provides intelligent spacing between paragraphs, headings, lists, and other block elements.
Overview
The layout-text element creates a container optimized for long-form reading content. It:
- Sets a maximum line width of
--measure-normal (65ch by default; data-fluid makes it fluid, and the dyslexia and large-text themes shorten it)
- Applies consistent vertical spacing between block elements
- Uses larger margins before major headings (proximity principle)
- Tightens spacing after headings so they associate with their content
- Provides extra breathing room around figures,
pre, code-block, tables, blockquotes, video and browser-window
The rhythm applies between direct children. Content wrapped in one extra element (a single <article> inside) only gets the browser's default spacing; put the content straight inside, or use the attribute form on the article itself.
Element and attribute forms
The same typographic core (measure, rhythm, centering, bleed) is available without a wrapper element. The attribute value is prose, not text: there is no data-layout="text".
data-layout="prose": identical to <layout-text>. Spell the measure data-layout-max or data-layout-measure; both work on both forms.
data-layout="columns": adds multi-column flow; see <layout-columns>.
article[data-measure]: the reading width only, always centered, with no rhythm. See Reading width only.
1234567891011121314
<layout-text data-layout-measure="narrow"> <h2>Reading Width</h2> <p>Measure and vertical rhythm on a wrapper element.</p></layout-text> <article data-layout="prose" data-layout-max="narrow"> <h2>Reading Width</h2> <p>The same measure and rhythm on the article itself.</p></article> <article data-measure="narrow"> <h2>Reading Width</h2> <p>Capped and centered, browser-default spacing.</p></article>
Which to choose: when the text already lives in an <article> or <section>, put data-layout="prose" on it: no wrapper, and its headings and paragraphs are direct children, so the rhythm reaches them. Use <layout-text> when there is no such element, for example inside a sidebar layout's content slot. In the attribute form, main, article, section and aside are also container-query containers, which the element is not (that matters for data-bleed). See data-layout for the full comparison.
Attributes
Every row applies to <layout-text> and [data-layout="prose"], and also to <layout-columns> and [data-layout="columns"], which share the typographic core.
| Attribute |
Values |
Default |
Applies to |
Description |
data-layout-measure |
narrow, normal, wide |
normal |
both |
Line measure: --measure-narrow / --measure-normal / --measure-wide (45 / 65 / 80ch by default). See Measure. |
data-layout-max |
narrow, normal, wide |
normal |
both |
Same as data-layout-measure. ch-based: narrow is 45ch here but 40rem on layout-center. |
data-layout-centered |
(boolean) |
— |
both |
Center the container (margin-inline: auto). Off by default: the text keeps its position. |
Child attributes
| Attribute | On | Description |
data-bleed |
a direct child |
Break out to the full width of the nearest query container. Also works on direct children of article[data-measure]. See Full-width breakout. |
Measure
The default line width is --measure-normal. data-layout-measure (or data-layout-max) picks narrow, normal or wide. The tokens are 45, 65 and 80ch by default. Under data-fluid they become clamps that grow with the viewport, and the accessibility themes adjust them (dyslexia 55ch, large text 60ch).
Narrow containers: in a query container narrower than 30rem (a sidebar, a card, a phone-width column), the measure is released to 100%, so the text fills the space rather than leaving a gap.
Reading width only: article[data-measure]
For an article that needs the reading width but not the rhythm, use data-measure on the <article>. It is always centered. Bare or normal uses --measure-normal; narrow and wide use the other two tokens. data-bleed works on its direct children too.
It is not a data-layout value and only works on <article>. Choose it when the content brings its own spacing (a CMS body with its own styles, a stack of components) and you only want the line length; choose data-layout="prose" when you also want the rhythm. Unlike the prose and columns forms, data-measure is not released to the full width in narrow containers.
123
<article data-measure="narrow"> <p>Constrained to --measure-narrow, centered, no rhythm rules.</p></article>
Spacing rules
layout-text spaces its direct children according to their element type:
| Context |
Spacing |
Rationale |
| Default (between elements) |
var(--size-m) |
Standard paragraph spacing |
| Before h2 |
var(--size-2xl) |
Major section break |
| Before h3 |
var(--size-xl) |
Subsection break |
| Before h4/h5/h6 |
var(--size-l) |
Minor section break |
| After any heading |
var(--size-s) |
Associates heading with content |
| Between consecutive lists |
var(--size-s) |
Groups related lists |
Before/after figure, pre, table, blockquote, video, code-block, browser-window |
var(--size-l) |
Extra breathing room for media |
Examples
Vertical rhythm
1234567891011121314151617
<layout-text> <h2>Article Title</h2> <p>First paragraph of content...</p> <p>Second paragraph continues...</p> <h3>Section Heading</h3> <p>Content for this section...</p> <ul> <li>List item</li> <li>Another item</li> </ul> <blockquote> <p>A notable quote...</p> </blockquote></layout-text>
Centering
layout-text keeps its position by default. Add data-layout-centered to center it in its container. Since it already limits its own width, it needs no layout-center wrapper.
1234
<layout-text data-layout-centered data-layout-measure="narrow"> <h2>Centered Article</h2> <p>layout-text limits its own line length; data-layout-centered centers it.</p></layout-text>
Full-width breakout
Add data-bleed to a direct child (a figure, a table, a code block) to break it out of the measure. The child spans the full width of the nearest query container: main, article, section and aside are query containers by default, as is any element with data-container. (Not to be confused with data-layout-bleed, which spans a direct child of a data-page-layout grid across every column.)
- It works centered or not. Uncentered text bleeds from its start edge across the container; centered text bleeds evenly on both sides.
- It measures the container, not the viewport, so it never adds a horizontal scrollbar.
- If the text host is itself a query container (
<article data-layout="prose">, article[data-measure]), it stops being one while it holds a bleed child, so the bleed reaches the next container out. Add data-container to the host to keep it as a container (the bleed then fills only the host).
- With no query container above it at all, the bleed falls back to the viewport width.
- In
layout-columns, a bleed child also spans every column.
123456789
<main> <layout-text data-layout-centered> <p>Text at the reading measure…</p> <figure data-bleed> <img src="wide.jpg" alt="…" /> </figure> <p>…and back to the measure.</p> </layout-text></main>
Blog post
The article is the reading container: data-layout="prose" with a narrow measure, centered. No wrapper elements.
12345678910
<article data-layout="prose" data-layout-max="narrow" data-layout-centered> <h1>Getting Started with Web Components</h1> <p class="lead">Learn how to build reusable HTML elements.</p> <p>Web Components are built on web standards...</p> <h2>Why Web Components?</h2> <ul> <li>Work everywhere HTML works</li> <li>Don't require a build step</li> </ul></article>
Documentation page
Inside a sidebar layout there is no article to carry the attribute, so the element form fits. The measure is released to the full width when the content column gets narrower than 30rem.
123456789101112131415161718
<layout-sidebar data-layout-gap="l"> <nav aria-labelledby="contents-heading"> <layout-stack data-layout-gap="s"> <h2 id="contents-heading">Contents</h2> <ul> <li><a href="#installation">Installation</a></li> <li><a href="#usage">Usage</a></li> </ul> </layout-stack> </nav> <layout-text> <h2 id="installation">Installation</h2> <p>Install the package using npm:</p> <pre><code>npm install vanilla-breeze</code></pre> <h2 id="usage">Usage</h2> <p>Then use the custom elements in your HTML.</p> </layout-text></layout-sidebar>
Best practices
- Use for long-form content only - layout-text is designed for articles, documentation, and similar content. Don't use it for UI layouts.
- Center with
data-layout-centered - layout-text already limits its own width, so it doesn't need a layout-center wrapper to constrain it. Use layout-center only when the page needs a wider frame around the text. Note that the two data-layout-max attributes use different scales: narrow is 40rem on layout-center and 45ch on layout-text.
- Semantic HTML - The spacing rules work best with proper semantic markup (h2 before h3, etc.).
- Avoid nesting layout elements - layout-stack, layout-grid, and similar elements inside prose may have unexpected spacing.
Accessibility
- Line length: the measure keeps lines between roughly 45 and 80 characters, the range that is easiest to track from one line to the next. WCAG 1.4.8 Visual Presentation (AAA) recommends no more than 80.
- Reader preferences: the dyslexia and large-text themes shorten the measure tokens (55ch and 60ch), and line height comes from
--prose-line-height (1.6 by default), which those themes and user settings can raise. Set spacing through these tokens rather than fixed values so the preferences reach your text.
- Zoom and reflow: the measure is in
ch, so it grows with the text size, and it is released to the full width in containers narrower than 30rem, so enlarged text reflows instead of overflowing (WCAG 1.4.10 Reflow).
- Structure: the rhythm follows the heading levels, so use them in order (h2 before h3) and the visual hierarchy matches what screen readers announce.