TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Responsive type scales with composable CSS utilities

50 pointsby danielskoglyover 1 year ago

4 comments

rustypotatoover 1 year ago
It&#x27;s probably easier to express this sort of scale as a linear function y = mx + b, where y is the font size and x is the screen size. If you have:<p><pre><code> minFont = 12 maxFont = 18 minScreen = 320 maxScreen = 2400 </code></pre> Then you calculate the slope (m) using the ol&#x27; (y - y) &#x2F; (x - x):<p><pre><code> m = (maxFont - minFont) &#x2F; (maxScreen - minScreen) </code></pre> Then plug one of the (font, screen) pairs into the equation and solve for b. Use that as --linear-font-size.<p>Once you have the linear equation for your font size, you use clamp() to bound the screen size between the min and max that you set before.<p><pre><code> font-size: clamp(var(--minScreen), var(--linear-font-size), var(--maxScreen)) </code></pre> I think this basically has the same effect as the blog post produces, but it fits in my head better when the dynamic part is expressed as the equation for a line.
thundermuffinover 1 year ago
I appreciate how the author has laid out how the calculation works and the pitfalls of CSS calc. It makes it very approachable for folks.<p>Has anyone seen a responsive type solution like this that doesn&#x27;t break the &quot;resize text&quot; accessibility section of WCAG? [0] I would love to be able to use this style of responsiveness, but every time I&#x27;ve ever seen it there&#x27;s always accessibility concerns or a piece of a blog post dedicated to how you&#x27;ll still need to tweak and fine tune to meet the needs of less sighted users so it isn&#x27;t the silver bullet it seems.<p>For instance on this blog post when zooming in on the example section, my naked eye feels like I never see it actually grow to 200% bigger. I&#x27;m on my gaming PC which isn&#x27;t set up well for much code inspection, but it feels like it&#x27;s either not growing at all or clamped at a certain size based on the zoom&#x27;s width. Looking at dev tools, it shows it going from 28px to 18px, so it technically is getting a little smaller, whereas if you have 2rem you see the text grow as you zoom in.<p>I also could be completely misinterpreting this WCAG section or maybe misunderstanding the font size calculation. It is college football Saturday here in the US, so my brain may not be firing on all cylinders!<p>[0] <a href="https:&#x2F;&#x2F;wcag.com&#x2F;designers&#x2F;1-4-4-resize-text" rel="nofollow noreferrer">https:&#x2F;&#x2F;wcag.com&#x2F;designers&#x2F;1-4-4-resize-text</a>
mediumsmartover 1 year ago
I have been using this approach and happy with it. It’s similar I think? I just don’t need tailwind for the puny websites I cobble together.<p><i>Andy Bell – Be the browser’s mentor, not its micromanager</i><p><a href="https:&#x2F;&#x2F;m.youtube.com&#x2F;watch?v=5uhIiI9Ld5M">https:&#x2F;&#x2F;m.youtube.com&#x2F;watch?v=5uhIiI9Ld5M</a><p>Btw. Great website and articles. Thank you for posting.
esafakover 1 year ago
It would be nice to have this as a tailwind class.