Skip to content

fix(css): parse the font shorthand - #406

Merged
tannevaled merged 2 commits into
mainfrom
fix/font-shorthand
Nov 8, 2026
Merged

tannevaled merged 2 commits into
mainfrom
fix/font-shorthand

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

What

The font shorthand had no handler, so font: 32px/40px V, serif was dropped whole (size, line height, weight, style and family, including an @font-face family).

Spec opened: CSS Fonts 4 section 2.7 (the font shorthand): grammar [ [ <font-style> || <font-variant-css2> || <font-weight> || <font-width-css3> ]? <font-size> [ / <line-height> ]? <font-family># ]; longhands are first reset to their initial values; font-size and family are required; system keywords only as the whole value.

ParseDeclarations expands it to the five longhands the engine models (style, weight and line-height reset to normal when omitted). Variant and width keywords are accepted and dropped (no model). Invalid values, system-font keywords, CSS-wide keywords and var() expand to nothing, as before. Expansion at parse time keeps the cascade passes (size first, then family/weight/style) untouched, and a later longhand still wins.

Evidence

  • Tests failing on main: css.TestFontShorthandExpansion, css.TestFontShorthandCascade, engine.TestVariableFontViaFontShorthand. The new file is 100 percent covered.
  • The variable-font page of fix(paint): draw a variable font at the CSS font-weight #405 written with font: 32px V, serif renders pixel-identical to the longhand version (0 differing pixels) and shows the same per-weight ink progression as Chrome.
  • Performance: only a declaration named font takes the new branch (one string compare per declaration otherwise). Timings are deferred: 1-minute load was 48.

Closes #404

Co-Authored-By: Claude Sonnet 5.5 noreply@anthropic.com

🤖 Generated with Claude Code

tannevaled and others added 2 commits November 8, 2026 15:45
CSS Fonts 4 section 2.7: [ style || variant || weight || width ]? size
[ / line-height ]? family#. The shorthand expands, at declaration parse time,
to font-style, font-weight, font-size, line-height and font-family, resetting
the first, second and fourth to normal when omitted. font-variant and
font-width are accepted and dropped. A value without size and family, a
system-font keyword, a CSS-wide keyword or var() expands to nothing, as
before.

Closes #404

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Refs #398

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit f1335b4 into main Nov 8, 2026
13 checks passed
@tannevaled
tannevaled deleted the fix/font-shorthand branch November 8, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

css: the font shorthand is not parsed

1 participant