7 ms·
CSS: Unavoidable Bad Parts
- al2o3cr 5mo agoLOL @ "I've never written production CSS" followed shortly by "don't use CSS selectors"
- marcomezzavilla 5mo agoBad: responsive design Uhmmm, ok
- chrismorgan 5mo agoPoor choice of words there; it would have been better as “Bad: responsive breakpoints”.
- HelloNurse 5mo agoMy experience with responsive breakpoints is that they require compromises and therefore it's hard to make a manager commit to them: everything must look perfect, and identical, on every different device that exists, and if it doesn't it's the designer's fault.
- camillomiller 5mo agoYeah, infuriating that this shit gets so upvoted here
- alwillis 5mo agoIn 2026, you can avoid the bad parts. > Let's start with the basics: if you write`font-size: 16px`then `16px` is the size of what? Sadly, the answer is "nothing in particular" -- this is a size of a virtual box around the glyph, but the box isn't tight, and the size of the glyph varies, depending on the font. Luckily, `font-size-adjust` property can fix it, and make `font-size` consistent across fonts. All modern browsers default to 16px, but for accessibility and sanity reasons, we shouldn't use pixels. By default, 16px = 1rem. You don't need to declare it; it just is. Also by default, 16px = 100% if using percentage for font-size. See "The Ultimate Ideal Bestest Base Font Size That Everyone Is Keeping a Secret, Especially Chet" - https://adrianroselli.com/2024/03/the-ultimate-ideal-bestest-base-font-size-that-everyone-is-keeping-a-secret-especially-chet.html https://adrianroselli.com/2024/03/the-ultimate-ideal-bestest... > Can you just set `font-size: 18px`or whatever works best for your chosen font? I think the answer is yes, but there are some caveats to keep in mind. If you want to manually increase the base size, using relative units is the answer: `html { font-size: 1.125rem }`. Since by default, 1rem = 16px, 1.125rem is 18px. > Setting `font-size` in your CSS disables that second approach. Setting `font-size` in pixels disables changing the browser's default size; works fine with relative sizes. If the goal is not having to learn the intricacies of CSS, just use the built-in type scale: | CSS absolute-size values | xx-small | x-small | small | medium | large | x-large | xx-large | xxx-large | | ------------------------ | -------- | ------- | ----- | ------ | ----- | ------- | -------- | --------- | | scaling factor | 3/5 | 3/4 | 8/9 | 1 | 6/5 | 3/2 | 2/1 | 3/1 | | HTML headings | h6 | | h5 | h4 | h3 | h2 | h1 | | By default, medium is 16px which is 1rem. You can write `p { font-size: medium }`. BTW, the main use case of `font-size-adjust` is for changing the font size of your fallback font incase your primary web font doesn't load or if it takes too long depending on what `font-display` is set to. You want the metrics of the fallback font to match the primary font so the text doesn't shift [1]. [1]: https://www.w3.org/TR/css-fonts-4/#font-size-adjust-prop https://www.w3.org/TR/css-fonts-4/#font-size-adjust-prop
- LoganDark 5mo ago> > Let's start with the basics: if you write`font-size: 16px`then `16px` is the size of what? Sadly, the answer is "nothing in particular" -- this is a size of a virtual box around the glyph, but the box isn't tight, and the size of the glyph varies, depending on the font. Luckily, `font-size-adjust` property can fix it, and make `font-size` consistent across fonts. > All modern browsers default to 16px, but for accessibility and sanity reasons, we shouldn't use pixels. That's not what that means. font-size specifies the size of the font's em box, but the correlation between the em box and the visual size of the font is not consistent across fonts. font-size-adjust can adjust how a font-face responds to the font-size so that the sizing is consistent with other fonts of that size. For example, capsize is easier to implement that way. https://seek-oss.github.io/capsize/ https://seek-oss.github.io/capsize/ (I agree that specifying font size in pixels rather than rem is bad practice.)
- elxr 5mo agoYup, using rem for as many things as possible has always been good to me.
- sheept 5mo agoThis is bad advice. You should only use rem for text, e.g. font sizes and paragraph margins. If the user is on a phone and has a larger default font size due to vision difficulties, making padding scale with the font size takes screen real estate away from the larger text the user needs.
- TonyStr 5mo agoThis is true. I use increased font size on my phone, and so many websites are borderline unusable because of massive unnecessary padding. But I am also a culprit of using rem for everything. What is the alternative? Pixels?
- elxr 5mo agoThanks for helping me realize my accidental anti-pattern. Can you link some of the sites that do that the worst. I want to use those as references to fix my UI (on increased font-sizes on small screens) before releasing an app I've spent 4+ months on.
- deleted 5mo ago[deleted]
- bryanrasmussen 5mo agoNote: The following of course varies from site to site based on how design focused the site needs to be. I had thought about writing some things about this, but I will put a quick observation here >restrict yourself to using only markup-meaningful semantic tags, and then figure out CSS which works with the markup you have. this used to be the best practice advice about 20 years ago. If you've been around long enough in programming, especially in web development, you will see cycles of best practice advice where the thing you were told as the best practice at one time becomes the worst practice later. For example at one time it was considered "best practice" to put script tags at the head of the document. Anyway this guy really isn't the person to give you best practice advice, as he notes. The semantic tags advice is dear to my heart and I wish it were so, but it is wrong, unless the site you are working on is the online representation of a textbook or something highly structured like that, in which case it is spot on. The reason why it is wrong is that most of the web is a design focused medium, as opposed to a meaning focused medium. In a meaning focused medium the semantics are the most important thing, because semantics are how we convey meaning. That's pretty much tautological there. In a design focused medium obviously semantics of things are important, but so is arbitrariness. To see that arbitrariness is important, pick up any highly visual magazine that has been applauded for its design aesthetic. Obviously no magazine is completely arbitrary but even more structured ones like The New Yorker need to do somewhat arbitrary things with the layout and design to enforce the rules of taste which guide it. It is not impossible for a design focused publication that in moving between articles that the look of headlines change (although always recognizably headlines), the necessity of splitting things up with visually arresting details that delight the reader is common place, typography and images are there to delight the visual sense, not to clarify a point being made in the article, as a common rule. If you were to try to semantically describe all these effects and things with meaningful class names you would end with lots of drivel, essentially, or things that mixed presentation description with semantics like ".ArtDecoHeading" perhaps, and that is because the difference in presentation of many of these things communicate absolutely not semantic value but only that it looks cool or nice or whatever way you want to describe the effect of design on the target of the design. This relates to lots of CSS frameworks where the names of classes describe not what the element is or means, but rather what the class does, because when design affects are placed in a somewhat semi-arbitrarily manner this is really the most sensible way to describe a lot of classes. Again, as nothing is completely arbitrary you will find things that are a mix of semantic classes like ".productTitle" Semantics and Presentation mixed ".bigHeader" and pure presentation that is trying its best to seem semantic somehow ".sideBoxSlideIn .upDownJumper" I mean definitely you have to identify what parts of your application have semantic meaning, where the design will not arbitrarily affect them, such as .productTitle, but I believe in most modern web development much of what you will be doing is not semantic styling, but design styling. And when you are doing design styling you might find you're creating layers and layers of wrapper elements, because making wrappers is often one of the easier ways to solve arbitrary layout problems. On edit: this was partially prompted by the guy claiming never to have written production CSS and saying he is not really the person to be giving advice here, and I agree because he does not understand the actual needs of web development as a design based medium. Which is why he suggests such previous best practices as don't use classes and stuff like that which just doesn't work because to be able to do arbitrary layout without classes we would need to have millions of element types to play around with and then you have just recreated the problems with classes, only worse. on edit2: added note at beginning.
- bryanrasmussen 5mo agoI mean, this has a lot of out of date information which I guess is not surprising for someone who says I'm not an expert and don't do production CSS, but it is weird to get the suggestions that are pretty reasonable for 5+ years ago.
- Joker_vD 5mo agoYou know, this speaks volumes. Layout is a complicated business, sure, but CSS just keeps having monumental shifts in how you're supposed to approach it year after year; it's as if it's done without any overarching theory/vision but merely groping in the dark, trying things and fixes, and seeing what sticks and doesn't suck too horribly (this latter part is optional; remember Yandex's BEM?)
- Jaxan 5mo agoYou really don’t have to change your css. My personal website has been using roughly the same css for a decade. Why not? Sure if you are a designer and want to follow trends, you’ll have to keep your css skills up to date. But for most websites, you can use css from a decade ago.
- TonyStr 5mo agoWould you prefer that CSS never evolve, and our frustrations remain the same? Writing CSS today has gotten significantly easier with flexbox, variables and now nesting. BEM is not part of the CSS spec, that's just a design methodology.
- Joker_vD 5mo agoI would prefer it to finally figure things out properly, and then just stop changing, yes. > Writing CSS today has gotten significantly easier with flexbox, variables and now nesting. Which, you know, are not some technically complicated ideas that simply could not have been done thirty years ago. Heck, <table> existed, and so did the algorithm that laid it out, from the outset yet getting flexbox to replicate that functionality took literal decades. And nesting is in no way more complicated to implement than cascading. > BEM is not part of the CSS spec, that's just a design methodology. Yes, and it existed for a reason, to paper over the deficiencies of the built-in functionality.
- hexasquid 5mo agoSo many complaints about web technology, where is the replacement? I'd be interested to know if there was the one true layout system that everyone agrees on
- gucci-on-fleek 5mo agoTeX [0] is in some sense "the one true layout system", but it's designed for printed documents, so it doesn't work on the web [1]. And in some ways, it's much simpler than CSS (you can build nearly everything from only a dozen typesetting primitives or so), but in other ways it's much more complex (since TeX is itself a fairly complex programming language). It's typesetting quality is still unbeaten by any of its competitors though, even 50 years after its first release. [0]: https://en.wikipedia.org/wiki/TeX https://en.wikipedia.org/wiki/TeX [1]: But it does work on WEB :) [2] [2]: https://en.wikipedia.org/wiki/Web_(programming_system) https://en.wikipedia.org/wiki/Web_(programming_system)
- deleted 5mo ago[deleted]
- srdjanr 5mo agoMy understanding is that it's designed for fixed-size documents? There's a big difference between a layout system for that, and one where size of a document can vary wildly, up to completely opposite aspect ratios
- gucci-on-fleek 5mo agoI guess I'd call it mostly fixed: most TeX engines only produce a single page size at a time, but you generally only need to modify a single variable to change the page size and, after recompiling the document should be perfectly reflowed into the new page size. This is not helpful at all for someone who wants to be able to freely rotate their phone, but it's still better than InDesign or Word where changing the page size will probably break the layout. There is actually a TeX extension that supports viewers arbitrarily changing the page size of documents [0], but it's fairly new, and as far as I'm aware it has essentially zero adoption. [0]: https://ctan.org/pkg/hitex https://ctan.org/pkg/hitex
- pathartl 5mo agoTo call a CSS pixel not an actual pixel but a measurement of an angle at a reading distance is... technically correct... but isn't really representative of how it's actually rendered. On a non Hi-DPI display at 100% scaling in the browser and OS, a px is a device pixel. An css inch is considered 96px, with the assumption that a CSS inch is an imperial inch on a 96 DPI display. Yes, it's a bit fuzzy now with modern displays (especially when display scaling is not at a whole number haha) but it just kinda feels like searching for something to complain about. If your browser and OS doesn't get in the way you can get exact measurement. This also applies to almost any UI framework that has some integration with the OS.
- vladde 5mo agoregarding `* { box-sizing: border-box; }`, i usually follow the "Probably Slightly Better Best-Practice" https://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/ https://css-tricks.com/inheriting-box-sizing-probably-slight...
- themafia 5mo ago> There isn’t a fully general solution to positioning and sizing GUI boxes. flexbox. You can literally recreate any fully responsive desktop style GUI with it. You just need to layout your elements the same way you would in a GUI designer like QtCreator or Glade. Which means thinking in terms of divs with flex-grow set on them to get the automatic container expansion you get with "vertical boxes" or "horizontal boxes". These divs will sometimes be empty if you want a simple "expander" box. Once you have it down you can look at any desktop GUI and just inherently understand how it maps into this flexbox model.
- edoceo 5mo agoYea, back in the day there was this h-box and v-box containers for the Widgets. I still think of my HTML that way, and div-soup to make them (is it soup tho?). Used to be TD soup.
- interstice 5mo ago>> So, don’t think “how can I do my layout in a given system”, think instead “what possible layouts are allowed by the system” Spoken like someone that hasn't been handed designs and expected to 'just figure it out' for a living.
- camillomiller 5mo agoPerson who hasn’t spent enough time understanding web design feels entitled to make a CSS mark sheet. Most of the “bad” is really “I haven’t worked with this enough and I will judge it from my limited point of view”. What a waste of time
- lwilld 5mo ago> An ersatz CSS tutorial for people who need to style a web page, but aren’t web developers. I am a wrong person to write this kind of thing, as I have neither the time, nor experience. I'd say this disclaimer at the top speaks for itself!
- deleted 5mo ago[deleted]
- seanwilson 5mo ago> If you “View Source” on any “real” website, you’ll notice that everything has layers and layers of wrapper elements, so you might be tricked into thinking that wrappers are how you solve layout problems. I can’t really agree or disagree here, as I never wrote “production” CSS, but, in my experience, it’s much easier to understand if you do the opposite — restrict yourself to using only markup-meaningful semantic tags, and then figure out CSS which works with the markup you have. CSS isn't powerful enough by itself to create any layout you want without modifying the HTML. You almost always need wrapper elements to group elements you want to align together for presentation purposes only (e.g. "a vertically centered row containing one paragraph next to two vertically stacked images"), so there often aren't semantic HTML tags that would make sense. It's similar to how you use numerous groups/frames in design apps like Inkscape and Figma to help align elements, where nobody would suggest you were a bad designer for using groups that don't have semantic meaning. You can only really avoid wrapper elements for simple Markdown style pages with simple designs, where the CSS for that is straightforward. I think in these discussions, it needs to be clearer how complex the page designs being discussed are. The CSS advice that makes sense for simple Markdown style pages is very different to what makes sense for a complex web app UI or a highly designed marketing page.
- grebc 5mo agoI think this is a pretty pragmatic take, and I do something similar with all the web apps I’ve created since I started self employment close to 15 years ago. As you mentioned sometimes there are unavoidable things you need to do in markup to make it work visually. Although lately grid & flex solve 95% of the problems that crop up for me fortunately.
- siddboots 5mo ago20 years ago everyone was sold css entirely on the premise that, once the standards were adopted by all of the browsers, we would all be writing purely semantic html with completely orthogonal and swappable css. And today literally no one designs web sites that way - html today is mostly specific to presentation. It feels like pretty dramatic technological failure to me.
- cbold 5mo agoCSS, the only way to win is not to play
- lelandfe 5mo ago> Use CSS nesting to avoid writing “far reaching” selectors and style component-per-component I view nesting as a footgun. I recommend trying to restrain all CSS to one selector, and to instead view additional qualifiers as an escape hatch where needed. Death to specificity.
- pramodbiligiri 5mo agoGoogle released "Modern Web Guidance" a few weeks back that includes a set of agentic skills: https://github.com/GoogleChrome/modern-web-guidance-src https://github.com/GoogleChrome/modern-web-guidance-src. I wonder if that includes some of the suggestions in this article.
- reverseblade2 5mo agoI call my self experienced and informed about bleeding edge css. And I disagree every single item including font sizes and border box
- RandyRanderson 4mo agoRandy's Axiom 173: VERY widely used techs are some of the worst, ill-conceived techs ever. However, no one will admit this because: . many people don't know them (the techs) well enough because they're so abstruse. Some people would argue this a necessary feature. . many people only know them and so can't compare them to something else . people that do understand them typically have financial or ego reasons to look the other way . people that do understand them AND are rich and happy are afraid of all the other ppl in this list. Generalization: any widely use tech must be extremely complex or extremely simple (eg TCP).