layout-text
Typographic content container with vertical rhythm. Provides intelligent spacing between paragraphs, headings, lists, and other block elements.
Attributes
| Attribute | Values | Default | Description |
|---|---|---|---|
| layout-text has no configurable attributes. It applies consistent typographic spacing automatically. | |||
How It Works
The layout-text element creates a container optimized for long-form reading content. It:
- Sets a maximum line width of 65ch (characters) for optimal readability
- 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 and code blocks
Live Example
The Art of Typography
Good typography makes content easier to read and understand. The layout-text element handles the complexity of vertical rhythm so you can focus on writing great content.
Research shows that optimal line length for reading is between 45-75 characters. The layout-text container sets a max-width of 65ch to hit this sweet spot.
Vertical Rhythm
Vertical rhythm refers to the consistent spacing between elements on a page. Notice how the space before this paragraph is smaller than the space before the heading above it.
This creates a visual hierarchy that helps readers scan and understand the structure of your content.
The Proximity Principle
Elements that are related should be closer together. Headings have less space below them than above, associating them with the content they introduce.
- First list item
- Second list item
- Third list item
Lists are also spaced appropriately within the prose container.
"Typography is the craft of endowing human language with a durable visual form."
Robert Bringhurst
Blockquotes receive special treatment to stand out from body text.
Code
Spacing Rules
The prose element applies different spacing based on element types:
| 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 figures and pre | var(--size-l) |
Extra breathing room for media |
Usage Examples
Blog Post
Getting Started with Web Components
Learn how to build reusable, encapsulated HTML elements using the Web Components standards.
Web Components are a set of web platform APIs that allow you to create custom, reusable HTML tags. They work across all modern browsers and can be used with any JavaScript library or framework.
Why Web Components?
Unlike framework-specific components, Web Components are built on web standards. This means they:
- Work everywhere HTML works
- Don't require a build step
- Can be shared across projects
- Encapsulate styles and behavior
Documentation Page
Installation
Install the package using npm:
npm install vanilla-breeze
Or include via CDN:
<link rel="stylesheet" href="https://cdn.example.com/vanilla-breeze.css">
Usage
Import the styles in your CSS:
@import 'vanilla-breeze';
Then use the custom elements in your HTML.
With layout-center for Page Layout
Centered Article
Combining layout-text with layout-center creates an optimal reading experience. The prose handles vertical rhythm while the center constrains the horizontal width.
This pattern is common for blog posts, documentation, and any long-form content.
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.
- Combine with layout-center - For page layouts, wrap layout-text in a layout-center to constrain width.
- 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.
CSS Implementation
Related Elements
- layout-center - Horizontally centered container
- layout-stack - Vertical stacking layout
- layout-card - Card container