147 points · by surprisetalk · 3y ago · 73 comments
Nothing against proven crafts when they serve well, yet all "typographic scales in CSS" I've seen so far always operated almost exclusively on font-size / line-height and seldom letter-spacing, almost never font-weight and never used other visual clues for expressing hierarchy and rhythm like decorative ornaments, different shades or even palette or some other creative tricks. Those are techniques that are sometimes used in the wild, built organically, but I have never seen them analysed in isolation, some colour theory telling that "you either bump-up font size by this factor or increase contrast between background and text to get such and such level of urgency".
What I find most strange is that, seemingly, everyone is fine with conveying the same information using two and more ways in parallel: size, visual contrast and disruptions in vertical rhythm. Making part of text bigger makes it stand out on it's own, since it disrupts vertical rhythm around it and also shines with thicker strokes. Side-effect of this is more visual contrast, something I'd call "pressure".
It is mostly the absence of content what constitutes the hierarchy -- the space around headings, indentation etc -- not the local "pressure" of the letters in headings. From my subjective perspective large contrasting text very often "screams" in my head.
Some time ago I've tried if would be possible to normalize that optical pressure across sizes (without changing weight); this was the result: https://codepen.io/myf/pen/oNLKzNY
In short, I think we should try to "tone down" blocks with large text when we have the opportunity, like:
(edit HN discards block element characters; think large square in "lighter" shade followed by two "heavier" lines of the same width below)
rather than keeping it same, like:
(think large square followed by two lines below, all of same shade, so the compact area of the square stands out even more.)
I find your example interesting, but I hate things overriding letter-spacing like that, because it generally looks bad, and definitely looks bad in my chosen fonts. Need to finish off my article railing against people changing letter-spacing on body text, which is ridiculously common and always a bad idea. Line-height you take a bit too far, but the general concept of “larger text means smaller line-height” is one I wish more people understood. I’ve become partial to `* { line-height: calc(1em + 0.5rem) }` in the last year, which I find to work quite nicely as a single definition. For colour, it’s an interesting thing to consider, but I think it’s mostly the wrong solution—optical size s the proper solution for most of it, and my experience is actually that larger text normally wants to have a stronger colour rather than a weaker, because it’s a heading. But the interactions between font sizes and contrast in various guises is absolutely relevant, and I’m glad that the successor to WCAG’s terrible colour contrast technique, APCA (Advanced Perceptual Contrast Algorithm), takes font size into account in considering what makes for acceptable contrast.
That’s why you might do things like this (which I provide as an example of something reasonable, not as the only way of doing things):
1. Page title: positively huge (e.g. 4rem/64px/48pt). Probably not bold (though I freely invite you to use inline styles inside the title, something nowhere near enough people do).
2. Heading: quite large, and with a large gap before it (e.g. 2.5rem/40px/30pt, plus margin-top of 1.5em/60px and margin-bottom of 1rem/16px). Maybe bold, maybe not.
3. Subheading: somewhere between heading and body text in size, and perhaps with a decent-sized gap before it when not preceeded by a heading (e.g. 1.5rem/24px/18pt, margin-top 1.33em/30px and margin-bottom of 1rem/16px). Probably bold.
4. Subsubheading (rare) and certain sorts of captions (e.g. on figures and asides): normal size and distinguished by style instead. (e.g. 1rem/16px/12pt, but bold, and perhaps with a larger gap above.)
One thing covered incidentally in this sample scheme is the use of asymmetric margins to visually separate sections. That’s normally a good idea, but for some reason people don’t often try to fit it into their neat mathematical constructions—though you will note this tool’s sample area using such asymmetry unremarked. Probably because their formulæ are arbitrary anyway.
Another thing to note is that for general typography you don’t need many levels. As far as major sizes and styles are concerned, I’m sceptical of any general-use model that goes beyond five (title, heading, subheading, caption, body text). As far as headings are concerned, if you’re using more than title + two more, you should probably reconsider your content structure.
Cast off the tyranny of typographical scales. They have the appearance of wisdom in promoting rigour, but they are of no value.
That’s the point of scales — to provide structure to any scale of values so there’s distinction without excessive variation.
The only reason their values might seem to make any sense is if you have this weird idea that you should support at least five or six levels of headings. You actively shouldn’t.
Take the scale of 1.250 (the default of this tool). −1 is riskily small for any purpose, and −2 should never be used. +1 isn’t big enough for any kind of heading. +2 to +4 are reasonable heading sizes, but aren’t different enough from each other. +5 might be OK as a title, but very often you’ll want to go bigger. Depending on content, it might do for a heading style too.
Another mildly popular value: φ, 1.618. −1 is already too small for any purpose. +1 is decent for a subheading level, and +2 for a heading, and +3 for a title. (+3 is normally too big for any sort of heading; +4 could also be reasonable for a title.) But at that point you have only about four usable values, and where was the virtue in using a scale for them? You could have chosen more suitable values manually.
The virtue was in drastically reducing the space of correct answers.
How long would it take the average developer to pick sizes out of an infinite number of sizes? And how long would it take them to pick sizes out of a small number of sizes?
I know I do not want to fiddle with an infinitely large problem space.
A fluid typographic scale and spacing. Eliminates the need for breakpoints for text. I’ve used it on a number of projects with great success and love its simplicity.
This approach allowed me to remove all font size-related breakpoints from all my projects while achieving better visual results. Very grateful to its creators.
I think this tool may be good for documents with careful typesetting and layout, but maybe not modern, interactive, responsive pages.
If that's not what you're saying, then you'll need to clarify.
I always consider: That 9px text might look readable on your 4K iMac, but how about your users on a budget Chromebook with a 720p display? And text rendering differences between browsers and operating systems is still something that severely affects how the text looks, especially at thin font weights that seemed to be all the rage a few years ago.
yeah, chrome and safari supported retina displays on day one, but at yet another huge consistency nuclear bomb that we now have to remember forever.
It mostly works, but gets weird when you have non-scaled content in the design.
I would imagine things would have progressed to have decent points or some other measurement based on screen actual size by now.
In reality, the browser will use a variable number of pixels (and even device subpixels) to actually render the font or div -- but if you use all "em" measurements, all those sizes will have the same relationship to each other on the final device.
The 16px in the demo comes from the default base font size in the browser, which has 1em = 16px.
so, yes, it is still all based on a "base pixel value, that is not really a pixel".
There are three families of distance units.
One is absolute length units <https://www.w3.org/TR/css-values-4/#absolute-lengths>. px is the canonical one of these, but it may be anchored to physical measurements (typical in print) or the reference pixel (which in practice is generally approximated by some number of device pixels multiplied by a scaling factor from the operating system).
Then you get viewport-percentage lengths <https://www.w3.org/TR/css-values-4/#viewport-relative-length...>, of which I will not speak, save to note that they’re broken by design so that they’re almost completely useless for layout purposes.
Then you get font-relative lengths <https://www.w3.org/TR/css-values-4/#font-relative-lengths>. The em dtagames speaks of is one of these. The root em, rem, is commonly used as a base, and is most commonly 16px, but it depends on a variety of factors like user preferences, the root font-size, the root font-family, and the root language. It’s very messy and even mildly context-dependent.
Most lengths should generally be font-relative for most perfect compatibility and user-preference-acceptance, but doing this perfectly is harder than it may sound.
The exact definition evades me since it's been a couple years I did any web development, but your px-based sizes won't look tiny on high-DPI screens.
This is great advice. This is exactly what i think so many web design failed to follow, e.g. bootstrap.
I just changed an H2 tag to an H3, and it looks like your H3 is way too small.
One thing I've seen for H3 and below is to use `font-style: italic` and font-weight 500 to distinguish it from the H2. I don't think that would work for your site though.
For your site, you could maybe throw a `color: #444` on H3 and below? You can also try `h1, h2 { margin-left: 1em }`.
I just get sad for the designers who have to battle this stuff every day. No programmer would take "input" on their code from a nurse (say), but designers face "input" on their decisions and their craft at every turn. I've yet to meet a designer who was longing for a web form to input a bunch of numbers to generate some type sizes.
But I could be wrong. It happens a lot.
(I’m genuinely curious what you think is wrong with CSS, and how it could be fixed. I’ve heard this kind of sentiment from time to time, and never had a reasonable answer. CSS certainly isn’t perfect, but it’s not at all bad, and most criticisms of it like the meme “CSS is awesome” box with overflow genuinely come from not understanding it and why any other approach would be worse.)
I don't think I need to have a solution prepared to define a problem?
> How will it avoid the problems you perceive with CSS while still being useful?
How did <insert any language> replace <insert any older language> while still being useful?
This is kind of what I mean when talking about CSS. For whatever reason, all of the innovation, invention, tinkering, progress that went into _every other aspect of software_ just gets forgotten about with regard to CSS? This idea that CSS is the perfect solution, or close enough that there's no reason to invent something radically different. We're on our 5000th Javascript build tool but we still just have terrible old CSS.
> and never had a reasonable answer.
Completely reasonable answer: I have no idea, it's not my responsibility to create a solution. CSS is enough of a problem that I just generally refuse to use it. I'm not alone in this.
(Honest question. I’ve toyed with it in minute detail a couple of times over the past decade, but for fun or as part of matching a lined-paper æsthetic. Not because I think there’s any inherent virtue in it, because I don’t. So I’m curious why you think CSS needs it badly.)
More calm More orderly Easier to read More professional
To the best of my knowledge, no one has treated “rhythm” in any way rigorously, and it’s mostly just a crock, something that sounds good on paper but is utterly without actual reason or value, rather like modular scales for typography.
I don’t respect that article. Its analogies are lousy, its examples of non-rhythm unnecessarily bad (straw-man arguments), its rhythm not great in any case (and lacking any attempt at anything like baseline alignment), and after the first instance it only really shows rhythm with an unrealistic superimposed grid which obviously makes rhythm look better than non-rhythm. I get the sense that the author has read a bit of various things, and then attempted to justify an opinion in any way they could, and ended up producing an incoherent and completely unsound argument.
There are certainly major places where consistent spacing and sizing is of value. But slavishly following it page-wide without something like a background pattern that you’re aiming to match (which is absolutely a legitimate use case, but is æsthetic rather than functional)… I’ve never come across any argument that seemed to hold any water, and I’d like to understand why a few people are so attached to the notion that it has inherent virtue.
P.S. CDNs can keep your site up at near zero cost.