w3c / w3c/csswg-drafts

[css-fonts] Proposal to expose font metrics

Open
#4,780 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

css-fonts-5
Dominant language
Bikeshed
Stars
4.9k
Forks
816
PR merge metrics
PR metrics pending

Description

Introduction

It would be useful to expose metrics from the font that is being used by the browser.

These values would be normalised across all fonts, and not defined as an additional metadata in font files. This would insure backward compatibility with all fonts.

Use cases

Syntax

I'd like to propose a syntax similar to custom properties or environment variables that would be familiar to most authors:

font(--x-height)
font(--ascender)
font(--descender)
font(--cap-height)
/* etc. */

The double hyphen syntax could be a quoted value instead, such as font("x-height"), but maybe that should be kept for custom ident in font files.

Questions

These metrics are available with tools like Font Inspector, but are they passed along to the browser when it loads in the font? If not, I realise this proposal would not be feasible.

Limitations

I can imagine that the rise of variable fonts also means a single font can have multiple x-heights based on the different parameters, and I am not sure if this should be handled by browsers or authors.

One argument for it to be handled by browsers is that authors cannot predict a font that failed to load (unless using something like Font Face Observer to apply styles conditionally…).

Thanks for your time reading this. Please let me know if this has already been discussed, or if there is any interest in this.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No implementation file or test is identified. Start by reviewing the proposed font() syntax, the listed use cases and limitations, and the linked leading-trim discussion; determine whether browser-exposed metrics are feasible, how variable fonts should be handled, and what syntax and behavior the CSS Fonts proposal should specify.

Written by the indexing model from the issue text.

Assessment

Tech stack
css
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.