7 ms·
My Custom CSS Reset
- slmjkdbtl 5y agoThis is a pretty clean reset, and the explanations are really nice and thorough! But the person coming out from the left edge of the page scared the crap out of me
- nikodunk 5y agoSame!!! Holy cow! It was pitch black in my room and it scared the living daylights outta me.
- john37386 5y agoYa me too. I wonder if someone could try to trick a 3d effect and that it feels like something alive is coming from the screen
- rpastuszak 5y agoHehe I kind of liked the creepy/cute factor. I create similar art outside of my day job so perhaps this is an acquired taste though
- rambambram 5y agoHaha, I actually liked it. And it was the first time since long that I clicked a popup (or should I say popright).
- samhw 5y agoYeah, I found it quite sweet. I usually hate Intercom-style 'conversational' popups, but props to the author - he's made it unique and endearing enough that I would definitely have signed up if I were a front-end dev.
- flanbiscuit 5y agoI'm on Firefox Android and didn't see that. Where do they pop out?
- john37386 5y agoscroll down and it should pop from the left at some point. Maybe try in private mode?
- sexy_seedbox 5y agoSeems to show on desktop only.
- pdenton 5y agoThis reset does too much IMHO, the rest of the CSS will become dependent on these styles. That said, I'm guilty of this myself. Here's mine: http://0x0.st/-7gE.css http://0x0.st/-7gE.css To me, having reset styles feels like using unwanted globals in a programming language. Styles on html and body are ok though, as there's only 1 of them on a page.
- entropie 5y agoThis site is so nice (+memorable) and also good content but why do you hack my scrolling?
- deleted 5y ago[deleted]
- chrismorgan 5y agoI never quite get the reasoning behind changing box-sizing. My gut feeling is that most places that benefit from switching it to border-box were doing the wrong thing anyway, and that content-box really is the way you should be thinking—design the layout in terms of the content where possible, rather than other parts of the layout. To use his own example: `width: 100%`, that specific value is completely superfluous, just remove the line; and if you were talking about stacking things side-by-side, where historically you would have done things like `width: 50%` or `width: 33.3%` and hope the pixels line up well enough and it doesn’t wrap, then you should use flexbox instead. Certainly there used to be a couple of major exceptions to my feeling that content-box is a better way of thinking, but this is the main one. Now I can only think of one significant exception: that `html, body { height: 100% }` needs border-box on body if you introduce padding or don’t zero margin, and that if you have an element inside the body that constrains the whole page’s width with max-width and also has margin or padding, same situation. —⁂— > The WCAG criteria states that line-height should be at least 1.5. This is being completely misread. The criterion says that no loss of content or functionality must occur if the user overrides line-height and sets it to at least 1.5. It doesn’t say you should be setting it to at least 1.5—or else it would also say you should be setting letter-spacing to at least 0.12em, which would be awful. —⁂— On `-webkit-font-smoothing: antialiased`: Neither screenshot exhibits subpixel antialiasing. I’m guessing (as a non-user of macOS) based on the appearance that `-webkit-font-smoothing: antialiased` might actually be disabling that thing that macOS misnames “font smoothing” which is actually glyph dilation (about which I have written here on HN before). If it’s doing that, then hey, that could actually be useful for adjusting font grades. > MacOS is the only operating system to use subpixel-antialiasing, and so this rule has no effect on Windows, Linux, or mobile devices. This is not true: on Windows, ClearType (enabled by default, I think? but certainly not always) does subpixel antialiasing, and you can definitely choose to go with subpixel antialiasing under Linux. It’s just that those platforms don’t provide a CSS knob to twiddle, perhaps because they saw how much it was abused on macOS. —⁂— p, h1, h2, h3, h4, h5, h6 { overflow-wrap: break-word; } Why apply it to paragraphs and headings alone? Would it not be better to just apply it to the root element? Let it cascade, it’s an inherited property. That way also you don’t get anomalous behaviour when you write lists without wrapping each item’s contents in <p>.
- 5y ago
- windows2020 5y agoA friend recently started practicing front-end development and showed me something they put together. Included was a 200+ line CSS 'reset' file. It made up most of their CSS but they weren't able to explain what the different parts of it did or why they were needed. In fact, most of it wasn't applicable (it styled elements that didn't exist) or needed (it defined styles that were always overridden later on). I suggested they remove the file piece by piece to gain a better understanding of CSS.
- rp1 5y agoI don’t think this is good advice. The point of a reset file is to reset everything. You don’t want to add an element later and have that element contain random default styles. Is understand how each line of a dependency works really important?
- eyelidlessness 5y agoCSS resets have been contentious as long as they’ve existed, but they’re especially contentious now because they’re mostly superfluous (see the article) and tend to override things in ways that harm usability and accessibility. If you’re using one now, yeah it’s probably a good idea to understand what it’s actually doing, rule by rule.
- codingdave 5y agoYes, understanding each line is critical. I run a CMS that houses millions legal documents for thousands of organizations. A prior dev put in a reset that took away padding from P tags, so we have all these documents that have been built of the years with no layout difference between a soft return and a hard return. Which means they all have extra P tags between each actual paragraph, and at this point we can't even change our CSS without instigating reformatting of millions of documents. And legal authors do not like that one bit. So it stays because our data is more important than our CSS. But it also annoys. I pointed this out to them all when I first joined, and they said, "But CSS resets are good ideas." So yes - please take the time to understand what your CSS does, especially when working with tags that format text, as it can have subtle (and not so subtle) impacts on data created in a UI with unwise CSS reset choices.
- djbusby 5y agoI'm getting some odd text overlay on the anti-aliasing toggle. Pixel4/Chrome
- makeworld 5y agoPretty sure the toggle is just images, screenshots from macOS.
- cunthorpe 5y agoThe reset is reasonable except the antialiasing line. Shame. It was discussed just a couple of days ago on HN.
- iaml 5y agoDo you mean this [0]? Because that post is from before apple's recent changes to font rendering in Mojave. [0] https://news.ycombinator.com/item?id=29328838 https://news.ycombinator.com/item?id=29328838
- phelm 5y agoNot read it? Shame. It addresses that very article
- cunthorpe 5y agoThings maybe be "addressed," but that doesn't make them right. > Apple disabled subpixel antialiasing across the operating system Right, so what is he disabling exactly? > Chrome and Safari still use subpixel antialiasing by default Wrong. They do not. Zoom in yourself. There are no colored pixels. That CSS line basically acts as a `font-weight: -=100` across the document. That's all it does, and that does not belong to a CSS reset. You might as well set the rest of the `font` properties and call it a regular stylesheet.
- cfstras 5y agoI cannot stress this enough: -webkit-font-smoothing: antialiased Looks _horrible_ on non-retina (read: most external) monitors with macOS. Browsers have sane defaults for every OS! Please retain them rather than making me install TamperMonkey just to read your blog.
- musicale 5y agoWhy isn't this a setting in the browser or the OS?
- deleted 5y ago[deleted]
- sandreas 5y agoHere are some more "normalizers": https://pilabor.com/blog/2021/03/html-and-css-tricks/#normalizecss https://pilabor.com/blog/2021/03/html-and-css-tricks/#normal... I prefer: https://necolas.github.io/normalize.css/ https://necolas.github.io/normalize.css/
- lewisl9029 5y agoMy new favorite reset is this one: https://elad2412.github.io/the-new-css-reset/ https://elad2412.github.io/the-new-css-reset/ Here's a great interview with the author on CSS Tricks that explains some of the design choices in depth (this is where I first came across it): https://css-tricks.com/an-interview-with-elad-shechter-on-the-new-css-reset/ https://css-tricks.com/an-interview-with-elad-shechter-on-th... TL;DR: This rule does most of the heavy lifting and is the most novel aspect of this approach: /\* Remove all the styles of the "User-Agent-Stylesheet", except for the 'display' property */ *:where(:not(iframe, canvas, img, svg, video):not(svg \*)) { all: unset; display: revert; } It practically wipes out all styling from user agents across the board, so you will never again need to exhaustively override every undesirable user agent style to get an element to look exactly the way you want. The styles you've placed on an element explicitly become (for the most part) the only things that will contribute to its appearance. I've been prototyping with it at https://app.reflame.dev/ https://app.reflame.dev/ and it honestly feels like a breath of fresh air in terms of productivity. One thing I've learned to watch out for when using it, is that it also happens to wipe out the default focus state styles of interactive elements like button, anchor, etc (the blue outline in Chrome). This is the reset working as intended, but it's also a show-stopping accessibility issue if not properly addressed in userland by adding some form of visual focus indicator back in. I have a feeling we might discover more gotcha's like this as time goes on, but so far this is the only one I've noticed, and as a result I've been very happy with the tradeoff.
- butz 5y agoall: unset; is my new goto when custom styling form controls.
- ponyous 5y agoGoogle used to penalise websites with * {} selector. Has this changed? Surely you don't want a rule that will degrade your seo in a reset.
- rpastuszak 5y agoI’d be surprised tbh add the performance issues around this selector were already negligible 5+ years ago. Also ‘* > selector’ used to be much slower
- quickthrower2 5y agoNice to know the history of css resets and that you don’t need them anymore for their original purpose but this is a nice short starting point. Not to blindly copy in but gives some options to consider.
- arendtio 5y agoFrom my perspective that is not so much a reset/normalize.css but more something like a base.css. A reset.css is supposed to create a common truth across different browsers. However, this doesn't concern so much with different browser default settings but more with developer preference for specific behaviors, like e.g. the boxing model (which is the often being done in a base.css/scss in addition to a reset.css). That is not bad, just the wrong term being used. That being said, I like those settings :-)
- notRobot 5y agoFrom the article: > A pedantic note > Historically, the main goal of a CSS reset has been to ensure consistency between browsers, and to undo all default styles, creating a blank slate. My CSS reset doesn't really do either of these things. > These days, browsers don't have massive discrepancies when it comes to layout or spacing. By and large, browsers implement the CSS specification faithfully, and things behave as you'd expect. So it isn't as necessary anymore. > I also don't believe it's necessary to strip away all of the browser defaults. I probably do want <em> tags to set font-style: italic, for example! I can always make different design decisions in the individual project styles, but I see no point in stripping away common-sense defaults. > My CSS reset may not fit the classical definition of a “CSS reset”, but I'm taking that creative liberty.
- Waterluvian 5y agoBut then why call it that?
- busymom0 5y agoLove the design of the site! Also the confetti on subscribing to the news letter was lovely.
- pmlnr 5y agoI was a bit surprised seeing a Clippy(ish) popup figure on this site. If you want to go retro, make it Bonzi Buddy.
- deleted 5y ago[deleted]
- john37386 5y agoThe little man that appeared on the side really scared me! I mean wow, but for a second I really thought something was coming out of the screen.
- lelandfe 5y ago> The main element has height: 100%, but the element doesn't grow at all! > This doesn't work because in Flow layout... the width of an element is calculated based on its parent, but the height of an element is calculated based on its children. Well, more specifically, `height: 100%` isn't expanding as it's already the maximum height of its parent, right? All he's done is increase the parent height.
- sdfjkl 5y agoYou can tell a technology is beyond saving when CSS reset.
- Flankk 5y agoIt's 2021, you don't need a CSS reset old man. You're not designing for Netscape Navigator, AOL Browser, and Internet Explorer. You're designing for Chrome. This is the definition of cargo cult programming.
- wnevets 5y agoisolation is new to me. Not having to worry about IE anymore really makes things so much easier.
- deleted 5y ago[deleted]