Deft
Ask AI

Search

Search skills, authors and topics

jakubkrehel / skills

better-typography

Web typography from choosing fonts to spacing, wrapping and accessibility. Use when picking or pairing typefaces, configuring variable fonts or OpenType features, setting up a type scale, styling text in components, truncating text, styling underlines, selection, placeholders or carets, or reviewing frontend code for typography. Triggers on typography, fonts, font formats, woff2, variable fonts, font-weight, opentype, font-feature-settings, letter-spacing, line-height, type scale, tabular numbers, text-wrap, truncation, line clamp, underlines, text-decoration, text selection, iOS input zoom, font smoothing, text contrast, measure, line length, text-box, smart punctuation, drop cap.

Install

npx skills add https://github.com/jakubkrehel/skills --skill better-typography

Spacing and sizing

Units, a starting type scale, the heading mapping, line-height for wrapping text and text trimming.

Units

UnitBehavior
pxFixed
emScales with the current font size
remScales with the root font size
% on font-sizeRelative to the parent's font size, behaves like em

Type scale

Pick an existing scale or define one. Tailwind's text-xs through text-9xl, each pairing a size with a line height, is a solid ready-made choice.

A starting point for a product interface, named by role:

css
:root {  --text-caption: 0.8125rem;  --text-body: 1rem;  --text-heading: 1.125rem;  --text-title: 1.5rem;  --text-display: 2.25rem;}
RoleSizeLine-heightWeight
Display2.25rem (36px)1.1600
Title1.5rem (24px)1.2600
Heading1.125rem (18px)1.3600
Body1rem (16px)1.5400
Caption0.8125rem (13px)1.4400

Emphasis within a role is one weight step up (400 → 500), not a size change.

Heading hierarchy

css
h1 { font-size: var(--text-display); }h2 { font-size: var(--text-title); }h3 { font-size: var(--text-heading); }

In Tailwind, centralize the per-level classes in a component or @layer base rather than repeating them inline.

Line-height for wrapping text

css
/* Bad: card description at heading leading */.card-description { line-height: 1.1; }
/* Good: it wraps to 3 lines, so it reads as body text */.card-description { line-height: 1.4; }

Text trimming with text-box

text-box takes which edges to trim (trim-both, trim-start, trim-end) and where. Name both edges, start then end. cap, ex and alphabetic need a second edge value, so trim-start cap is dropped and trim-start cap text is not.

KeywordTrims at
capThe cap height (top)
alphabeticThe baseline (bottom)
textThe font's own text edge, keeping room for descenders
css
/* trim top and bottom */.badge {  text-box: trim-both cap alphabetic;}
/* trim only the top */.heading {  text-box: trim-start cap text;}
/* trim only the bottom */.label {  text-box: trim-end text alphabetic;}

Supported in Chromium 133+ and Safari 18.2+, not yet Firefox. Unsupported browsers keep the default leading.