Post

🎉 New Blogpost 🎉 Building Typographic Scales in CSS with :heading(), sibling-index(), and pow() www.alwaystwisted.com/articles/bui... What if we could create a typographic scale for headings with one line of CSS? One rule to scale them all. #CSS #FrontEnd #WebDev

alwaystwisted.comTypographic Scales in CSS with :heading(), sibling-index(), and pow()Learn how to build flexible, mathematical typographic scales using :heading(), sibling-index(), and pow() for cleaner CSS design systems.

15 reposts49 likes

just noticed a bit of a (big) issue with this - sibling-index() only works if there's H1 - H6 If there's h1,h2, two h3s, the second h3 would be styled like h4 dagnabbit :(

Still an interesting exploration! If you're iterating… why not use clamp() for fluid sizing? Also I'm curious: do you really get away with h-element selectors in the systems you've worked on? Or is this just for simple WYSIWYG pages? H-level and visual style seldom match in my components/systems.

regarding systems. I have had to style one heading to look like another before yes (if I read your second part correctly). This can also pair with headingOffset - which will be Fridays article.

sadly it seems I jumped to quickly and misunderstood sibling-index quite a bit. If the HTML is: h1, h2, two h3s, the second h3 would be styled like h4 poop :(

Ah boo. But you’re still bringing awareness to a whole bunch of cool CSS that can still be used in a similar way, just maybe not as concisely.

A quick fix I've just added to the article is to be explicit in the :heading(Nn) { }. So rather than using sibling-index() we could guarantee that the heading levels will be adhered to.