question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Complete Support for Font relative length units: rem, em, ex, ch, cap, ic + more

See original GitHub issue

With 0.2.0 alpha of the polyfill now supporting the poster childs rem and em for responsive designs, it would be nice to have complete support for font size relative length units to complete the picture.

With the ability to use the element related em unit for container widths, adding other font size relative units should be just a matter of “while-listing” and performing the same logic as for rem (root element font-size) or em (selected element font-size) respectively.

These are also long supported by browsers. For the selected element (like em):

  • ex: Equal to the used x-height
  • ch: Equal to the used advance measure of the “0” (ZERO, U+0030) glyph (Latin fonts), see ic below
  • cap: Equal to the used cap-height (capital Latin letter)

Browser support for additional font size relative sizes of CSS Values 4 is unknown / unavailable on caniuse or MDN, but could be added preemptively to be available when support is eventually implemented. Rules are virtually the same.

Selected element font:

  • ic: Equal to the used advance measure of the CJK water ideograph (CJK fonts), see ch above

Root element font:

  • rex
  • rch
  • rcap
  • ric

https://drafts.csswg.org/css-values-4/#font-relative-lengths https://drafts.csswg.org/css-values/#relative-lengths https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Values_and_Units#dimensions https://developer.mozilla.org/en-US/docs/Web/CSS/length

Thank you!


Some may argue that Point pt and Pica pc are also “font related”. While certainly standard in print and PostScript, both are actually absolute units based on the inch. Given their straight forward computation into pixels, both could be easy to implement, despite being highly inaccurate for modern screen resolutions. However, designers coming from print might find them useful.

  • pt: 1/72nd of 1in.
  • pc: 1/6th of 1in == 12pt.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
argyleinkcommented, Sep 6, 2022

From what I’ve learned while waiting for the lh unit and other font relative features, is that the font information isn’t always even available for the browser engine, let alone JS. Fonts themselves can have bad information in them that’s been accounted for by a browser, like impossible stuff for a polyfill author to know about font measurements. I agree attempts would work in many cases but not all (hence the brittle comment) because all JS can do is synthetically attempt a recreation of the environment needed to make a measurement, and while it’ll be fine for many fonts, it wont be perfect for all of them.

But, to devils advocate my own comment, that’s all a polyfill can do, is synthetically attempt as best it can, so maybe that’s not a good enough reason to reject the feature. Definitely up to the authors of the plugin here, to let them assess their own amount of fidelity and complexity they want to balance and manage over time with this polyfill.

So I see both sides here! Sorry if that’s not helpful lol. But it’s a fair request to want to use relative fonts in a container query, the spec allows it and the final implementations will too, but it’s also on a fine line cusp for maintenance and management from a maintainer POV, and few folks may actually leverage this feature. ⚖️

hope this was helpful 🙂

1reaction
WebMechaniccommented, Aug 31, 2022

I believe @argyleink may have valuable insight working on VisBug and he knows a thing or two about CSS

Read more comments on GitHub >

github_iconTop Results From Across the Web

15 CSS Relative units, how many do you know? em, rem, ex ...
I found out there are 14 relative units in CSS and compiled a list of ... Unlike em and rem which are dependent...
Read more >
<length> - CSS: Cascading Style Sheets - MDN Web Docs
Relative length units based on font ; ch. Represents the width or more precisely the advance measure of the glyph 0 (zero, the...
Read more >
CSS Values and Units Module Level 4 - W3C
This CSS module describes the common values and units that CSS properties accept and the syntax used for describing them in CSS property ......
Read more >
15 CSS Relative units, how many do you know? em ... - Medium
This article digs in 15 different relative units used in CSS. From regular rem & em to ex, cap, ch, ic and some...
Read more >
CSS Unit Guide: CSS em, rem, vh, vw, and more, Explained
Many CSS properties like width, margin, padding, and font-size take a length, and CSS has many different ways to express length. In CSS ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found