723 points · by thunderbong · 4y ago · 242 comments
A snippet that could work better in my opinion is the following:
html {
max-width: 70ch;
/* larger spacing on larger screens, very small spacing on tiny screens */
padding: calc(1vmin + .5rem);
/* shorthand for margin-left/margin-right */
margin-inline: auto;
/* fluid sizing: https://frontaid.io/blog/fluid-typography-2d-css-locks-clamp/ */
font-size: clamp(1em, 0.909em + 0.45vmin, 1.25em);
/* use system font stack: https://developer.mozilla.org/en-US/docs/Web/CSS/font-family */
font-family: system-ui
}
/* increase line-height for everything except headings */
body :not(:is(h1,h2,h3,h4,h5,h6)) {
line-height: 1.75;
}With this one I tend to agree, I can't see enough text at once and the margins seem a bit wide.
I think much more reasonable is the assumption that many designers have Macs with good monitors and there you can still read it well.
Whereas most people have old or poorly color calibrated monitors where you only get a grey goo.
I would think so. And because of that, accessibility is an essential topic. Luckily, this snippet will automatically follow your zoom level and/or font size settings.
Seeing how slick and smooth and beautiful and handy it is on Opera, puts any ridiculous dev team rejections to waste.
Text reflow missing from Chrome -- valid proof end user convenience is not a primary concern.
I bet text reflow moves ads into the wrong position, thus the decade long block.
Unfortunately that appears to be the case for a great many sites when viewed on a mobile device.
My current pet hate is British Airways, https://www.britishairways.com/travel/home/public/en_gb/ has so much wasted space that on my Pixel I have to scroll to reach the buttons "Manage My Booking" and "Check In". Further down the page the "Your account" and "Sign up" bits are so large and generously padded that they fill my mobile device's screen all by themselves.
Is this by design? Maybe in some warped design brief "scrolling" = "[potential] customer interaction" = a KPI gets fulfilled?
(I wonder if it is a "posh / classy" style or what not?)
then you can let the user (agent) set the default font size on root/html.
So? Most people over a particular age cannot focus close-up anyway, so the phone is at arms length or close to it, which requires a larger font size.
OK. This will probably be in the range 640–780px where it caps out (taking the font-size scaling for that width into account), but it depends on the font (and the viewport aspect ratio because of the font-size vmin component). Acceptable.
> padding: calc(1vmin + .5rem);
Assume the browser em is 16px (almost always true) and the above values for 70ch, and you end up with this reaching almost 15px at 700px, down to 11px on a 300px viewport (which is about the narrowest realistic viewport). I reckon a bit more is warranted at both ends, and tying it to viewport width only rather than vmin. I’d prefer just `padding: 1rem` (16px everywhere) or `padding: 4vw` (12px at 300px, 28px at 700px). Maybe a mixture like `padding: calc(3vw + .2rem)` if you really want to get fancy (12.2px at 300px, 24.2px at 700px).
Actually, a correction (though I’ll leave that paragraph alone): you haven’t touched the body margin in this stylesheet, so you’ll get an extra 8px on every side, so I’d either adjust that or reduce this padding by approximately 8px in each case. In light of the extra 8px, calc(1vmin + .5rem) is actually a bit much on tiny viewports, rather than too little.
> margin-inline: auto
But be aware this is new, March 2019 in Firefox up to April 2021 in Safari: https://caniuse.com/mdn-css_properties_margin-inline. Where unsupported, you’ll lose the centring of the document column.
Also this won’t do what you want in a vertical writing mode language. :-)
> font-size: clamp(1em, 0.909em + 0.45vmin, 1.25em);
This is typically 16px until 323.5̅px, 18px at 768px, 20px from 1212.4̅px. I would generally prefer to cap at 18px, but this scaling is acceptable. Actually, since it’s using vmin rather than vw, it’s seldom going to reach even 19px because almost no one has viewports that are both even 1000px wide and tall.
Again this is new, mostly early 2020: https://caniuse.com/css-math-functions. Where unsupported, it’ll stay at the typically-16px value.
> font-family: system-ui
I object to this. system-ui is problematic because there’s no guarantee that the font it resolves to is suitable for your content language. In Chinese Windows setups, this is likely to get you a font that renders English fullwidth, basically equivalent to massive letter-spacing. Use `font-family: sans-serif` instead. At present it will commonly resolve to a font that is subjectively not so “pretty”, but it will always provide a reasonable font, and it’ll be even better for users that have chosen their own default fonts.
system-ui has often been being used as a proxy for nicer-looking default fonts, but it has semantics attached to it, and those semantics actually make it an unreliable choice.
Also again comparatively new in the scheme of things, with Firefox the latecomer having only had it for twelve months: https://caniuse.com/font-family-system-ui. Where unsupported, you’ll get the default font, which is likely to be serif. Even if keeping system-ui, I would recommend adding a fallback, e.g. `font-family: system-ui, sans-serif`. (Incidentally also, remember the semantics of system-ui and that it might not be a sans-serif. It could be a serif, or even something more exotic. It could be Comic Sans. Do you really want your website shown in Comic Sans? Wonder if that’s the angle to take in dissuading people from system-ui! :P)
> line-height: 1.75;
Too much. Much too much. I’d suggest something in the range 1.2–1.5.
:is() is also new, last couple of years, https://caniuse.com/css-matches-pseudo. So this excessive line-height is comparatively unreliable. A more compatible spelling of the selector would be `body :not(h1):not(h2):not(h3):not(h4):not(h5):not(h6)`.
html{ margin:0 auto; max-width:80ch; padding:0.6em; font-family:serif; line-height:1.6; background:#FFF; color:#222 } h1,h2,h3{color:#444} img{width:100%}
> font-family: system-ui
Why render texts with the font that the reader has selected for a different function, ignoring the one that she has selected for texts?
> Glyphs are taken from the default user interface font on a given platform. Because typographic traditions vary widely across the world, this generic is provided for typefaces that don't map cleanly into the other generics.
So it might have been used to make the snippet "truly" universal for the developer using it. That said, I believe it would be better to choose the font family based on the content.
Even if a viewer is from a place where Serif/San-Serif/etc. doesn't make sense, they are still viewing the same content as anyone else.
[0]: https://developer.mozilla.org/en-US/docs/Web/CSS/font-family
So stick with something like serif or sans-serif.
That seems both clever and hard to maintain over the long run.
But using the ":not(:set())" operator, you're making your code implicit. Because you're telling your code what NOT to do (and instead rely on defaults or other side effects to define what will happen to your headings line-height).
Default: https://postimg.cc/k2Zwffms
With the 100 bytes version: https://postimg.cc/645d9vKT
Really the only reason to use a line spacing of 2 is if you are printing it and then editing the text with a pen. So... maybe in a print stylesheet in a very specific situation? But never on the web, IMHO.
It often can look better to have more whitespace, but it lowers information density. It depends on the situation.
People complain a lot about "wasted screen estate" but the first version that "doesn't waste blank space" is completely unreadable to me on desktop, I want to stop reading after the first line.
Having dead space on the side is kind of a different problem, more on the lines of the appropriate default settings of the application (or system)
Personally, I think websites should fill up the available space, increasing font size if it makes sense, perhaps using resizing images. So, no - text should not be constrained to a maximum width. If width were a problem, billboards wouldn’t be a thing.
Billboards are meant to be read from far away. So even though the physical width is large, we perceive it to be much smaller. Maybe similar to a big banner on a Desktop monitor.
Imagine reading the billboard at a much closer distance, say 2 meter. You'll have to move your neck from left to right. It doesn't matter how big or small the font size is.
As a subjective test, I lowered the font size of a random article to see if I would have trouble reading it. Other than having to focus more to make out the text, I don't have problems reading the entire paragraph. On the other hand, removing the max width made it more uncomfortable to read.
So the distance from where the text will be viewed from is an important factor to take into account. Phones, Desktops & Banners all are viewed from different distances.
I guess not.
> there’s a difference between number of characters and width
Billboards use large letters to fill the space, but normally they would be readable on a business card.
https://en.wikipedia.org/wiki/Dead_Sea_Scrolls#/media/File:G...
I've experimented with this style on Wikipedia, with separate columns under each headline. It usually works well.
Newspapers don't have scrollbars. So they use columns.
This may be why phone-apps are so popular, their content is designed to be viewed only through the app.
CSS columns is cool, I didn't know about it. But not sure where I would use it either.
I really love multi-column, and appreciate horizontal scrolling. I've got an ultrawide screen, and I love that my site is one of the very few that makes an interesting use of a screen that wide. (There are articles on my blog you can easily read with no scrolling at all.)
I've gotten so many complaints over the years about my use of multi-column, including here on HN. It seems a very polarizing thing, even as I wish it were more common. The one time one of my posts trended it got a lot of hate about my blog CSS. That was a revision ago, though. I've made a bunch of adjustments to it since then, because I did read all of them, and tried to find some tweaks (including a few bits of JS) to smooth the experience a bit.
(Some group or groups at Microsoft during Windows 8 development must have passionately loved multi-column text and proper "newspaper inspired" typography and wanted to see it succeed, and they did not seem to survive the backlash against Windows 8, sadly.)
As one example, the "Golf with your Friends" subreddit always throws me for a loop due to its use of columns. I have no idea how to read it!
https://old.reddit.com/r/GWYF/
Note this example will only work on a widescreen desktop browser.
Give me customization, not "alleged optimization" that turns out not to be so
Also, don't ask users to resize their browsers to accomodate for a site's poor UX. That's called "blaming the user."
9X% of web sites don’t do anything sophisticated, with columns or otherwise. They hard limit the content width regardless of the user’s window size, resulting in a tiny sliver of text.
I deliberately bought a giant high resolution monitor that I want to fully use. If I stretch my browser window full screen, I expect your web site’s content to expand to fit. I don’t care what some researcher thinks is “readable”.
I wish web developers would stop second guessing the user.
Do you have trouble reading HN in a maximized browser window on a wide screen monitor? I don't.
HN comments happen to be capped at 1215px (which I find too long on big comments), and comments usually have line breaks in between that make them not reach the max width.
> Text in books tends to take the full width of the page
Yes. Not the full width of both pages at the same time. Pages on a book have a vertical format, not horizontal. I guess columns would be somewhat ok on the web, but it's not really comfortable either... as we can scroll.
Coverage of the screen with text is the wrong metric regarding legibility.
If the text is too small I can hit Cmd - Plus but with those i have no recourse.
I have monitors either side of my primary in portrait mode specifically for looking at a bunch of code/text and it still wastes at least half of the useful display area.
https://i.imgur.com/Qk7fM35.png
If I wanted this, I'd press the reader button in Firefox or squish my browser window. Why? Shakes fist at sky
If that text was full width along your screen you'd be wasting vertical screen space instead. Will you ask them to write more to fill your screen up?
What would be nice is a special element <viewport sizeable style=“width:n”> so a user could either enjoy a default width or drag one side of it to resize its margin at both sides, without resizing a window. Or, instead of an element it could be purely a browser viewport-resize feature, like they do for textareas.
Meta: it’s really frustrating that every time an argument about web ui starts, nobody thinks of how to actually make it better and just holds on some particular use case or preference.
Sure there is: Tiling window managers. Available for every desktop OS in some form or another. I assume people who are power users enough to have large, multiple monitors can help themselves.
In my image you can see that either portrait or landscape orientation, there is considerable 'dead' area (edit: either side), by default, even if the text was many paragraphs long.
The usual solution is to smash "ctrl numpad +" four times til things fit perfectly at (usually) 150%. It's actually uncanny how I'll do this without even thinking while browsing.
Of course, this looks like wasted space when you have a landscape-oriented monitor... I personally very rarely maximize my browser so that I read in more of a portrait-style mode, regardless of the orientation of my display.
What's your solution? The only other option I can think of is multi-column newspaper style, but that's pretty fundamentally incompatible with the scrolling model of the web.
That's probably why you only see multi-column formats in page-based media like physical newspapers and PDF papers.
It isn’t though. If browsers supported overflowing text into a “next” container (defined via hierarchy, selectors, whatever), designers could just design repeating pages of layouts like they usually do with full-height marketing stripes.
Something like this: https://jsfiddle.net/n87hkdf4/
I think anything else would require tedious scrolling up and down all the time or worse - horizontal scrolling!
I don't need solutions to problems I don't have.
If people find it hard to read long lines on my website they can make their browser window thinner. I don't feel compelled to impose my reading abilities (or lack thereof) on them.
So because long lines are hard to read, line length is clamped to at least provide a decent experience to all those users.
@-moz-document url-prefix("about:reader") {
.container{
max-width:100% !important;
}
.toolbar-container{
display:none !important;
}
}
Make sure to set your preferred size/color first.Besides, the other half of my monitor is usually taken up by another window or two.
There are many citations that lead to other studies on the same topic.
Why are people so afraid of black text on white background?! In the end, after all the colors and custom fonts the website has gray text with poor readability which instantly fails WCAG AAA. Had he kept #555 (which is still not ideal), the author would have had a WCAG AAA-compliant design with minimal effort.
But I still prefer how the page looked initially, without all the styles.
Of course, if you change the default CSS now that 30 years of HTML have been written to rely on these defaults, almost every website will break.
I personally just don't see the point. There are a lot of bare bone frameworks around and if you're doing a static website (which would likely be the only type to benefit from that)... The <10 kilobytes gzipped css won't matter for the most part.
IMHO it's a fairly big miss that default styling is bad, we're missing basic controls like drag & drop, and there's no native layouts like heros or hamburger menus and so on. A lot of cumulative effort has gone into reimplementing these things thousands of times.
> 30 years of HTML
holy fucking shit
Anyway, the browsers still can update the CSS and add a "reverse read mode" button that changes it back.
Browsers still ship the bad defaults because changing defaults would break existing websites.
> Text also gets easier to read when more spaced out; the default line height makes the text too close together.
The opposite is easily true in my experience. Making text large, using ample line height, and even greater spacing between paragraphs, makes for text that is more readable but makes the experience of reading much worse. This is of course entirely subjective unless someone comes up with measurable evidence, like a study on the sentiment of users.
Something tells me that designers have been taking principles that are appropriate to hero page sections, advertisements, magazine covers and such, and applying them inappropriately to bodies of prose. Larger text with spacing and huge margins (or smaller max width) helps the reading impaired, but I don't really buy that people actually prefer it.
It's very well possible that it's all different for different people, but I much prefer having a larger piece of text in view; smaller font, smaller margins and smaller line height all help with that. Longer lines of text too. All within reason, of course.
You know how books for children have ridiculously large fonts and spacing, in stark contrast with (most) books for grown ups? It seems there is a trend now to make websites look like the books I had when I was just a little kid. I don't like it.
What makes you say that? Anecdotally, I prefer using the full width of my screen.
> Research has led to recommendations that line length should not exceed about 70 characters per line. The reason behind this finding is that both very short and very long lines slow down reading by interrupting the normal pattern of eye movements and movements throughout the text.
And a document on the topic from the US government: https://www.usability.gov/get-involved/blog/2006/08/line-len...
> The best available research suggests that users will read fastest if the line lengths are longer (up to 10 inches). If the line lengths are too short (e.g., two and a half inch columns), the line length probably will impede rapid reading. Users tend to prefer lines that are relatively short (about four inches).
Wikipedia cites a whole bunch of studies on the topic (https://en.wikipedia.org/wiki/Line_length):
> Legibility research specific to digital text has shown that, like with printed text, line length can affect reading speed. If lines are too long it is difficult for the reader to quickly return to the start of the next line (saccade), whereas if lines are too short more scrolling or paging will be required. [...] One proposal advanced that, in order for on-screen text to have the best compromise between reading speed and comprehension, about 55 cpl should be used.[11] On the other hand, there have been studies indicating that digital text at 100 cpl can be read faster than text with lines of 25 characters, while retaining the same level of comprehension.
There's a decent amount of variance, but common across all research in this area is that many hundreds of characters per line is never found to be the optimal length of a text column.
There exist decades of empirical research on this topic.
It's hard to find to the next line, if they are too long.
There has been over a century of research into this. It's why newspapers print their stories in columns, instead of across the entire page, which would be easier.
Depends. The reason why it may seem better to have narrow column is so you can skip ahead more easily and thus read faster (reason why newspaper divide an article into columns). Otherwise it doesn't make difference.
To me it's absurd that this day the trend is to have wide screen displays (16:9 but nowadays even 21:9 is common) and then all the text is vertical in a column that makes it impossible to read.
I prefer to give the use a choice: after all if the user prefers narrow text all he has to do is to take the mouse and resize the browser window at the width that he likes! But doing the opposite is not possible (at least without an extension that modifies CSS), and thus you have to keep scrolling something that otherwise would have fitted in a single screen.
I keep my browser window maximised (usually on a secondary screen). I like that all web pages are more or less readable in that configuration.
Do you have some evidence backing this up? Thanks.
https://www.fonts.com/content/learning/fontology/level-2/tex...
https://pimpmytype.com/line-length-line-height/
https://material.io/design/typography/understanding-typograp... (see under Line Length)
I don't have any studies at hand, but I think it's been pretty well established.
80 is somewhat arbitrary, I could've said 50 or 70 or even 100, but it's in the ballpark of what studies find. Studies never find 400 characters per line to be optimal.
Are they, or is this a legacy of 80x25 text mode terminals?
(Also, couldn't you have read the answers to one of the many other comments which ask the exact same thing?)
It's not "wrong" it's legacy.
The problem with browser default styling is that there should be another level: user default styling. I.e., the styling as chosen by the user.
Why does every website have to reinvent the wheel?
Those changes pretty much cover all this does, and it doesn't do a great job IMO. I'd let them get away with "look slightly better than defaults nearly everywhere"
On mobile, so many times it ends up creating a bad UX, but I will say that it does make more sense there where you can't change your browser width.
The NASM website is an example of this. Personally, I don't like it and would prefer a single column.
Proper column layout involves limiting columns to screen height, probably by paginating. Then the reader can perceive the text as a tree of Page > Column > Paragraph > Row. Tangentially, I think there are studies positing that this, helped by the notion of physical pages in space, is what's behind the readability advantage of books.
Alternative to pagination is scroll-direction: horizontal. Now the experience is even closer to reading a book. And to Windows 8! IMO there's a shortage of novelty sites with true (non-slideshow or carousel) horizontal scrolling.
[0]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Columns...
Not really "everywhere".
I’m not an expert in CSS, but I don’t think this makes sense. Why base the width on the default font size when you know you’re aiming for 600px? Just write 600px. Also that’s a max width, so what makes this support 600px screens at a minimum?
I dont get the logic here. If the goal is 600px, why are we using rem?
Why are we even setting a font-size on root of we want to base the width on the "default?"
Why are we even setting a max-width? Just split text into columns to maintain a legible line length.
:root {
color-scheme: light dark;
}
This makes the browser choose dark colors for those that prefer them, including form widgets etc...it's a handrolled theme, with a lot of inspo from @leerob of vercel. i keep a clonable version here https://github.com/sw-yx/swyxkit/
Here's an archive:
https://web.archive.org/web/20220915195112/https://bettermot...
I made up a attribute feature="usercss" which is supposed to mean to use the user-specified CSS (or suitable defaults for semantic HTML) instead of this one, if the client supports that feature; it can also use the user-specified CSS (or suitable defaults) if the web page does not specify any CSS at all. As far as I know no browsers implement this, but some of the people making up some newer browsers (the less common ones) might consider to add such a feature when user-specified CSS is implemented.
CSS is fun.
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Mod...
html {
max-width: 70ch;
padding: 3em 1em;
margin: auto;
line-height: 1.75;
font-size: 1.25em;
}
if you have 100 more to spare: h1,h2,h3,h4,h5,h6 {
margin: 3em 0 1em;
}
p,ul,ol {
margin-bottom: 2em;
color: #1d1d1d;
font-family: sans-serif;
}
explanation in the blogpostbody{font-family:sans-serif;font-size:1.1em;max-width:600px;margin:0 auto;padding:0 8px}a{color:#06c}
Thanks for the inspiration, I threw together my own spin on it.
You probably don't want to apply it to a whole document because then you need to scroll back to the top to read the second half. But it can be effective to columnize text sections between headings.
That oddity aside, seems the explanation didn't start 101 enough for me - I've not come across `main` before! Though it's not at all new: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ma...
I disagree about the font-size. I say go very small (pack more info on a screen). Very easy for people to make it bigger. People have known this for hundreds of years (old newspapers pack in the text, older readers can wear spectacles or use magnifying glass).
Why, is it a contest who can cram the more? People can always scroll, and they know how to do that better than they know how to increase the text (not to mention most read on mobile phones, were even fewer know how to change the text size)
>old newspapers pack in the text, older readers can wear spectacles or use magnifying glass
Seems like the worst argument one could chose in favor of this idea...
I wonder if that's true for the average (non-nerd) user on a smartphone though. They can likely pinch-and-zoom, but that's a terribly way of reading text since you constantly have to pan back and forth. Have they definitely found the text size adjustment buttons?
Default browser styles are perfectly alright.
When they aren't, this is mainly a self-inflicted problem by your browser (that can set whatever default it wants), and by yourself (who can easily override the default browser style with either a personal css file or just by CTRL+scrolling to change your text size). Text size, window width, margins, should never be a responsibility of the website.
Well, almost. The only problem (as far as I can think of right now) is that pictures which are included in a document are not limited to the width of the viewing area, by default.
> When they aren't, this is mainly a self-inflicted problem by your browser (that can set whatever default it wants), and by yourself (who can easily override the default browser style with either a personal css file or just by CTRL+scrolling to change your text size). Text size, window width, margins, should never be a responsibility of the website.
I fully agree.