18 ms·
58 bytes of CSS to look great nearly everywhere
- bawolff 4y ago> it appears that the default font size for most browsers is 16px, so 38rem is 608px. supporting 600px displays at a minimum seems reasonable. I dont get the logic here. If the goal is 600px, why are we using rem?
- cantSpellSober 4y agoIf the units don't match, changing the user's base font size will only affect one of them. Part of why we stopped 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.
- metayrnc 4y agoWould have been nice to have some examples showing it in action.
- noizz 4y agoQuick example of how it looks: https://jsfiddle.net/n8Lqypb7/ https://jsfiddle.net/n8Lqypb7/
- schemescape 4y agoIs there some way to view the result full screen, namely for viewing on mobile?
- new_user_final 4y agoresult: https://jsfiddle.net/n8Lqypb7/show https://jsfiddle.net/n8Lqypb7/show Original page: http://web.archive.org/web/20210318102514/https://jrl.ninja/etc/1/ http://web.archive.org/web/20210318102514/https://jrl.ninja/...
- mort96 4y agoThe original page seems to be gone from the web, but here's an archive of it: http://web.archive.org/web/20210318102514/https://jrl.ninja/etc/1/ http://web.archive.org/web/20210318102514/https://jrl.ninja/.... That shows the described CSS in practice.
- sva_ 4y agoIt also references this previous discussion: https://news.ycombinator.com/item?id=19607169 https://news.ycombinator.com/item?id=19607169
- cerved 4y agothere's a lot of studies about optimal typography for readability in terms of fonts and characters per line etc. 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)
- freediver 4y agoWhat is wrong with browser default styling, and why do browsers ship with something that is wrong?
- djbusby 4y agoBrowsers ship with defaults that are now 20 years old - there was a cool post here about 8px body padding a while ago. It's not "wrong" it's legacy.
- postalrat 4y agoWhy is it legacy though? Shouldn't browsers be free to change it?
- soulofmischief 4y agoWeb browsers have a hard constraint of backwards compatibility. Eventually we could see some CSS directive which enables "modern" default styling, both for mobile and desktop, but it would be opt-in so that existing sites which rely on defaults do not break.
- postalrat 4y agoI bet if they did an experiment where they changed the default styles a bit very very few would complain. Most people visiting tiktok or whatever wouldn't even notice.
- soulofmischief 4y agoThink for a moment. This has nothing to do with tiktok. This has to do with your favorite personal website which hasn't been updated since 2001. And any change in default styling would be immediately noticed. Pages suddenly centered, or half the width? Increased padding? And "most people wouldn't notice" is a harmful mentality in web design which allows minorities to suffer. Most people aren't blind, either. Should we not worry about them when designing websites?
- mikewarot 4y agoI've got a screen that is much wider than it is tall, this throws away so much of it. It's as bad as Facebook, where the stuff you want to see is a band about 1/4 the area of the screen.
- ricardobeat 4y agoIn theory sites could optimize for wide screens by adding columns, but 1) its a very small audience 2) most content is not suitable for that (how would you scroll a feed that spans 3 columns?)
- shadowofneptune 4y agohttps://www.nasm.us/xdoc/2.15.05/html/nasmdoc2.html https://www.nasm.us/xdoc/2.15.05/html/nasmdoc2.html The NASM website is an example of this. Personally, I don't like it and would prefer a single column.
- sen_armstrong 4y agoThat has a small number of long columns down the entire page, which doesn't give any of the benefits of having columns. Actually, it's only worse in terms of readability, as a big factor is how well your brain can spatialize the location of what you're reading for backwards jumps or subconscious memory palace stuff. Here that's complicated by the mental overhead of "I'm halfway down the page, but the page is really twice as long as it is, so that's actually 1/4 of the way through." 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.
- hoherd 4y agoThis whole design pattern of wasting screen real estate in desktop browsers drives me crazy. If I want narrow text I'll make my browser window narrow. 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.
- mwcampbell 4y agoDo you still have to explicitly add CSS to do something appropriate for the user's dark mode setting? I'd rather not specify any colors at all and just let the browser use system defaults, but last time I checked, that used black-on-white even in dark mode.
- wildrhythms 4y agoThat would introduce yet another set of defaults that developers would then need to inevitably override.
- mwcampbell 4y agoI'd accept that. The user-agent knows better than I do what the user needs. Especially if the user is low-vision, color-sensitive, or whatever.
- graftak 4y agoIt would break legacy websites that never considered dark mode.
- schemescape 4y agoYes. Sadly, iOS Safari defaults to dark blue links on a dark background for dark mode.
- curlftpfs 4y agoYou do, via `color-scheme` or media query
- jraines 4y agoShot in the semi-dark: there was a blog post posted here —- I haven’t been able to find it with HN search —- some years ago that started from scartch/browser-defaults and proceeded in like 5 steps to some nice minimal defaults. Not exactly a plain reset; there were some opinionated choices. Step one was something like the parent article. Anyone have an idea what this was, or have some similar recommendations?
- Herodotus38 4y agoI had to through my saved favorites, but I knew what you were talking about. From 5(!) years ago: https://jgthms.com/web-design-in-4-minutes/ https://jgthms.com/web-design-in-4-minutes/
- jraines 4y agoAmazing! Thanks :)
- Herodotus38 4y agoGlad to help
- deleted 4y ago[deleted]
- sdoering 4y agoInstantly thought of the same ressource. Still something I recommend regularly to people.
- dmitriid 4y agoGreat, with one nitpick: "Black text on a white background can be harsh on the eyes. Opting for a softer shade of black for body text" 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.
- FrontAid 4y agoI think this does not work well for mobile devices. Spacing and the font size is too large. Hence, a lot of screen space is wasted and the user has to scroll more. Larger font sizes on mobile are usually not a good idea as the device tends to be closer to your eyes anyway. 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; }
- dwringer 4y agoI wonder if everyone has a different optimum here based on different eyesight, screen size, and usage patterns. I always have a slightly different zoom on every website I visit. With this one I tend to agree, I can't see enough text at once and the margins seem a bit wide.
- FrontAid 4y ago> I wonder if everyone has a different optimum here based on different eyesight, screen size, and usage patterns. I always have a slightly different zoom on every website I visit. 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.
- mwcampbell 4y agoBut it would be better still if browsers offered an opt-in modern default style, to relieve us developers of having to make assumptions about the user's visual needs, which should be the domain of the user agent.
- marcosdumay 4y agoAnd it sets a text color, but no background color, ensuring it will fail on most non-standard color schemes. Not really "everywhere".
- makeworld 4y agoAlso restated here: https://www.swyx.io/css-100-bytes https://www.swyx.io/css-100-bytes
- worldmerge 4y agoDoes anyone know what theme that blog is using? It looks really nice.
- swyx 4y agouh wow, this is the first time anyone's complimented anything I designed lol! 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/ https://github.com/sw-yx/swyxkit/
- intelVISA 4y agoI doubt it :), swyxkit is one of the best designed blog templates I've seen.. even if the default color scheme is a bit ..tropical.
- magnio 4y agoA comparison using danluu's website: Default: https://postimg.cc/k2Zwffms https://postimg.cc/k2Zwffms With the 100 bytes version: https://postimg.cc/645d9vKT https://postimg.cc/645d9vKT
- mod 4y agoThanks for taking a minute to do this, it gives a nice side-by-side for a real-world example. What a great improvement.
- c0mptonFP 4y agoLine spacing is atrocious
- xani_ 4y agoThat line spacing is obnoxiously big tho
- skyfaller 4y agoYeah, I agree the line spacing is far too much. Butterick's Practical Typography recommends 1.2 to 1.45: https://practicaltypography.com/line-spacing.html https://practicaltypography.com/line-spacing.html 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.
- rossjudson 4y agoI think the line spacing is "comfy". Approved. For me.
- collinmanderson 4y agoYeah when I saw 2em padding and 1.75 line height in the css I thought "too big". I think 1em padding and 1.5 line-height are a bit better for general defaults. It often can look better to have more whitespace, but it lowers information density. It depends on the situation.
- baud147258 4y ago
- deleted 4y ago[deleted]
- civilized 4y agoSo long as we're talking about making websites legible, why is it that so many websites these days have content that's too wide for a mobile screen and there's no horizontal scroll, so the content simply can't be seen?
- wirrbel 4y agoI will never understand inflated line height. It doesn’t make Text more legible.
- zora_goron 4y agoA little more heavy and less generalizable than this, but I’ve used this Drop-in Minimal CSS bookmarklet [0] several times to quickly try out drop-in CSS frameworks on my projects! [0] https://dohliam.github.io/dropin-minimal-css/ https://dohliam.github.io/dropin-minimal-css/
- pronlover723 4y agoI'd add :root { color-scheme: light dark; } This makes the browser choose dark colors for those that prefer them, including form widgets etc...
- stevebmark 4y agoNot explicitly mentioned here, but worth bringing up: Text width should always be constrained to a maximum width to optimize for human reading. Every book ever printed has text with set within the same range for a reason. Full width text guarantees most users will have a poor reading experience.
- swid 4y agoI almost agree, but there’s a difference between number of characters and width, and also graphics and tables are a different beast. 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.
- xcambar 4y agoHave you ever seen a long text on a billboard? I guess not.
- swid 4y agoI'm pretty sure you misunderstood what I wrote. > 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.
- xcambar 4y agoFair enough. But your point requires discussing nonetheless. You seem to suggest that fontsize should adapt to width to fill the space (seemingly to a billboard, as per your example). If the billboard technique was used on the web, I guess we might not have more than a handful of lines on screen (on a 16:10 or so). That would disable skimming on long texts and even more, barely display a single paragraph (that's a gut guessing). Plus, and more importantly, the distance to the screen is such that a font too big is not more readable. There's a tradeoff to he found for the fontsize that not only has to take into account the size of the screen but also the distance of the reader from the medium. Or so I assume.
- growt 4y ago“max-width: 38rem it appears that the default font size for most browsers is 16px, so 38rem is 608px. supporting 600px displays at a minimum seems reasonable.” 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?
- breck 4y agoLove things like this. This is why I can't stop reading HN. 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).
- coldtea 4y ago>I disagree about the font-size. I say go very small (pack more info on a screen) 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...
- simonw 4y ago"Very easy for people to make it bigger" 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?
- shadowofneptune 4y agoI've moved towards a larger size with the knowledge that I'll have trouble reading small text in 20 years. With the state of modern medicine, most people reading this will be old for a long time.
- pGuitar 4y agoI tend to agree but modern designers are doing the opposite and post the least amount of content in a specified amount of space. I bet that they will come to their senses eventually.
- r3trohack3r 4y agoI really like the minimal CSS on Nat’s website, I frequently reference it when styling my own content: https://nat.org https://nat.org
- evandale 4y agoDoes this actually look great to people? I can't stand forced line lengths and these ones feel way too short for the text size. This seems that it looks great for mobile, not desktops.
- TheWoodsy 4y agoIt seems like I'm permanently in some sort of dystopian nightmare 'unpopular opinion' group where wasting two thirds of my monitors useful space is the right way about doing things. 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 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
- zahllos 4y agoI think this is due to the desire to fall in the approx 40-75 characters per line that are considered ideal (numbers vary depending on the source of the study but broadly fit this definition) for users to read. It is also why some prefer double-columns in academic papers, because each 'column' has closer to ideal lines, rather than have wide margins on the page. 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.
- Accacin 4y agoBut, you're the one wasting it, right? You have a huge monitor with one window open. I use a WM and very rarely have one window on a whole screen, because that would be a waste of screen. 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?
- TheWoodsy 4y agoWell, OK sure. I'm not the most effective communicator but in the end I'm still genuinely 'not getting it' though. 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.
- 4y ago
- enriquto 4y agoThis is useless bloat. 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.
- zzo38computer 4y ago> Default browser styles are perfectly alright. 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.
- achn 4y agoIs there a html/css only way to automatically “columnize” text into multiple columns of reasonable width?
- iza 4y agoThere is the columns CSS property: https://developer.mozilla.org/docs/Web/CSS/columns https://developer.mozilla.org/docs/Web/CSS/columns 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.
- achn 4y agoThanks. I’d love to see automatic pagination as well so it builds full window columnized “pages”.
- swyx 4y agoI wrote my version here last year: https://www.swyx.io/css-100-bytes https://www.swyx.io/css-100-bytes 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 blogpost
- curlftpfs 4y agoElement-based selectors, setting the root font-size, mixed units, text color with no background color...I guess the assumption is that you won't add ANY other styling? Big headaches down the road if you do.
- swyx 4y agowell yeah thats the gimmick with these things, ultra minimalist drop in css. its not like its hard to modify later on
- uhtred 4y agoWe bloat websites with ridiculously huge js frameworks but sure, let's focus on a few bytes of css
- divbzero 4y agoCould the default style in browsers be adjusted so nearly any webpage can look great with plain HTML?
- zzo38computer 4y agoIn my opinion, it does already, without needing much CSS except to limit pictures to the width of the viewable area (you can click on them and select "view picture" to zoom them, if desired). I rarely need to add my own CSS code to web pages that do not already have CSS; it is those that do, that I need to fix. 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.
- scorpios77 4y ago
- Blackthorn 4y agoPeople who use that accursed max-width style are the bane of my existence. Let it fill the entire browser! I have no idea how this became a trend.
- RobbieGM 4y agoIsn't it more readable not to have really long lines?
- curlftpfs 4y agoWe can have both! Wide containers with narrow line lengths. We call them "columns" and they're part of CSS now.
- thunky 4y agoPeople are using 48+ inch OLED tvs for monitors now. Someone reading full width text will look like they're watching a tennis match.
- Blackthorn 4y agoPeople can set the exact width they're comfortable with by making the browser window the size they want. But the moment that max-width is added, the choice is removed.
- ranger_danger 4y agono example screenshot or demo page? really?
- javchz 4y agoI just love this. I still don't get it how in this year, something like wikipedia, and newspapers in a 4k/1440p monitor are a pain to read. I get it, mobile first it's a thing, but with something as simple as this your readers will have a great time.
- imran0 4y agohttps://en.m.wikipedia.org/wiki/Cinnamon_clownfish https://en.m.wikipedia.org/wiki/Cinnamon_clownfish is what you are looking for.
- pgt 4y agofont-family: Georgia;
- OJFord 4y agoShould you take this sort of advice from someone using block quotes for explanatory sections? 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/main https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ma...
- hit8run 4y agoLine height 1.75 lol no thanks.
- gardenhedge 4y agothis is too narrow for my liking
- deleted 4y ago[deleted]
- quickthrower2 4y agoSee also: https://motherfuckingwebsite.com https://motherfuckingwebsite.com https://bettermotherfuckingwebsite.com https://bettermotherfuckingwebsite.com https://perfectmotherfuckingwebsite.com https://perfectmotherfuckingwebsite.com
- busymom0 4y agoThe second link seems to be down (taking forever to load). Here's an archive: https://web.archive.org/web/20220915195112/https://bettermotherfuckingwebsite.com/ https://web.archive.org/web/20220915195112/https://bettermot...
- quickthrower2 4y agoMaybe it got hugged by HN traffic? Was working fine earlier, but now also hangs for me.
- russellbeattie 4y agoFYI: It took me an embarrassingly long time to realize that vertical margins overlap to the largest value. So doing p { padding: 1rem 0; } will only separate paragraphs by 1rem, not 2rem as you might think if you add both top and bottom margins. However, there are rules, so throw them into a display: flex and suddenly all your paragraphs have 2rem in between. CSS is fun. https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Mod...
- snickerbockers 4y agois there an example of this? really annoying that he posts a github md instead of a page rendered with the actual css
- 24amxn24 4y ago
- plug_world 4y agoJust applied some of these changes to my own site. https://plug-world.com/posts/css-template/ https://plug-world.com/posts/css-template/ body{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.
- issung 4y agoHad a very tiny error page I was making this morning with absolutely no CSS and remembered this from 2 days ago, dropped it in and it looks great! I just added font-family Trebuchet MS :)