Typography

No utility classes for text: the heading scale lives in the elements themselves, and .heading-1…6 reuse it for anything else.

Description

h1–h6, p, li and hr are styled from a single $text-sizes map: size, line-height, letter-spacing, margin, font-family and font-weight per selector. Every value is exposed as a per-element custom property with the map value as fallback, so --forma-heading1-font-size, --forma-paragraph-line-height and friends can be tuned per element in a style attribute without extra CSS.

At build time, edit the $text-sizes map in _config.scss (or override it before the import).

The heading scale

All six levels come from the same $text-sizes map, so the scale stays consistent across the document. Sizes are in em: the universal .sm/.lg/.xl classes scale whole sections in cascade, and h1/h2 hyphenate automatically on small screens.

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

Paragraph text at 1em with 130% line height.

HTML
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
<p>Paragraph text at 1em with 130% line height.</p>

The .heading-* classes

The .heading-1…6 classes reuse the exact same visual scale for elements that are not headings, keeping the document outline honest: only real headings count for it.

A div that looks like an h2

A normal paragraph with a span that looks like an h6 inside. The document outline stays honest: only real headings count for it.

HTML
<div class="heading-2">A div that looks like an h2</div>
<p>A normal paragraph with <span class="heading-6">a span that looks like an h6</span> inside. The document outline stays honest: only real headings count for it.</p>

Per-element custom properties

The signature pattern: class names plus custom properties as an inline style. Each element accepts its own tokens at runtime: --forma-heading1…6-font-size, -line-height, -letter-spacing, -margin, -font-family and -font-weight, plus --forma-paragraph-* and --forma-hr-margin.

Default h3

Tuned h3

HTML
<h3>Default h3</h3>
<h3 style="--forma-heading3-font-size: 1.5em; --forma-heading3-letter-spacing: 0; --forma-heading3-margin: 0.25em 0">Tuned h3</h3>

Display headings, forma-style

Bootstrap ships six .display-* classes, one CSS rule each. forma does it with the universal size classes you already use everywhere: .sm, .lg or .xl directly on a heading multiplies its own size (each heading defines --forma-font-size-base on itself, so the scale factors apply to 5em, 4em, 3em…), and the same class on a container scales every heading, paragraph and icon inside it, in cascade. Zero CSS added to the framework for each new display size.

Display 1

Display 2

A compact h3

The same h3, scaled by the .xl container

Everything inside scales in cascade: headings, text and icons. One class, no new CSS.

HTML
<h1 class="xl">Display 1</h1>
<h2 class="lg">Display 2</h2>
<h3 class="sm">A compact h3</h3>

<div class="xl">
  <h3>The same h3, scaled by the .xl container</h3>
  <p>Everything inside scales in cascade: headings, text and icons. One class, no new CSS.</p>
</div>

Sizes and colors

No utility classes for text: the document outline stays honest, and .heading-1…6 reuse the exact same visual scale for elements that are not headings. Sizes are in em, so the universal .sm/.lg/.xl classes scale whole sections in cascade, and h1/h2 hyphenate automatically on small screens.

At build time, edit the $text-sizes map in _config.scss (or override it before the import). At runtime, each element accepts its own custom properties: --forma-heading1…6-font-size, -line-height, -letter-spacing, -margin, -font-family and -font-weight, plus --forma-paragraph-* and --forma-hr-margin.

The helpers module adds the universal size classes .xl, .lg/.lead and .sm/small, which multiply --forma-font-size-base by $scale-xl/$scale-lg/$scale-sm, and the .color-* utilities for tinting text per element: primary, secondary, the four state colors and contrast.

Extra large intro text

A lead paragraph at large size

Normal paragraph, with a smaller span and a small element.

Primary text

Secondary text

Success, danger, info and warning inline.

Contrast text against the background

HTML
<p class="xl">Extra large intro text</p>
<p class="lead">A lead paragraph at large size</p>
<p>Normal paragraph, with <span class="sm">a smaller span</span> and <small>a small element</small>.</p>
<p class="color-primary">Primary text</p>
<p class="color-secondary">Secondary text</p>
<p><span class="color-success">Success</span>, <span class="color-danger">danger</span>, <span class="color-info">info</span> and <span class="color-warning">warning</span> inline.</p>
<p class="color-contrast">Contrast text against the background</p>