Typography
The semantic content engine.
Typography in Keystone is not merely aesthetic; it is strict architecture. The .ks-prose utility acts as a container for user-generated content (Markdown), enforcing Vertical Rhythm and WCAG 2.2 spacing rules automatically.
It isolates your blog posts and documentation from the rest of the layout, preventing CSS conflicts while ensuring optimal readability.
Typography defines the structural hierarchy of information. Keystone uses Contextual Spacing to manage flow.
Vertical Rhythm
Notice how the space after the paragraphs depends on the following element.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptate et accusamus nemo expedita voluptates a asperiores sunt?
Laudantium provident velit, dolorum iure maiores, esse ipsa harum sequi minima quisquam sed totam excepturi placeat sapiente enim labore officia ea! Culpa vitae quaerat molestiae numquam fuga aspernatur sunt architecto nostrum.
- Lists use specific indentation.
- Nested lists change markers automatically.
- Ordered nested
- Or unordered sub-nested list
- Ordered nested
We also handle inline code and blockcodes:
{{- /* I'am a comment */ -}}
{{- /*I' am a long comment that I will exceed the layout boundaried and overflow the container*/-}}
And of course tables
| Variable | Value |
|---|---|
| Spacing | 2.25em |
| Width | 80ch |
Reference
The system relies on three architectural pillars:
- Namespacing: All rules are scoped to
.ks-prose. It does not pollute global generic tags likeporh1. - Contextual Selectors: It uses
:has()to change margins dynamically. A paragraph followed by a Heading (h2) gets more breathing room than a paragraph followed by a List (ul). - Mathematical Harmony: Spacing follows the formula:
Line-Height (1.5) * WCAG Multiplier (1.5) = 2.25em.
Installation
The typography system is disabled by default to prevent override issues.
Uncomment the import in your main CSS file:
Define your rulesets in the assets/css/components/_typography.css.
Create the file:
Import it in your main Tailwind file:
Usage
Wrap the Markdown output variable in the .ks-prose class.
Accessibility
The system is engineered to meet WCAG 2.2 AA standards:
- Visual Presentation (SC 1.4.8): Paragraph spacing is strictly calculated to be 1.5 times the line spacing, aiding users with cognitive disabilities in tracking lines.
- Text Spacing (SC 1.4.12): Line height (
leading-normal) and paragraph spacing use relative units (em) to scale correctly if the user overrides the root font size. - Readability: The
max-w-[80ch]of the container restricts line length to the maximum recommended ~80 characters. Lines longer than this cause eye fatigue and tracking errors for users with reading difficulties. - Contrast: Use of themes variables to ensure WCAG 2.2 AAA contrast and better legibility out of the box.