Disclaimer

This blog is kind of my own personal work Notebook, and the processes below are only guaranteed to work for my specific configurations. So, use this info at your own risk, and please understand I won't be able to provide any help if you break something

Saturday, November 27, 2021

Josh W Comeau's Custom CSS Reset

A pedantic note (from the Author):

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.


/*

  1. Use a more-intuitive box-sizing model.

*/

*, *::before, *::after {

  box-sizing: border-box;

}

/*

  2. Remove default margin

*/

* {

  margin: 0;

}

/*

  3. Allow percentage-based heights in the application

*/

html, body {

  height: 100%;

}

/*

  Typographic tweaks!

  4. Add accessible line-height

  5. Improve text rendering

*/

body {

  line-height: 1.5;

  -webkit-font-smoothing: antialiased;

}

/*

  6. Improve media defaults

*/

img, picture, video, canvas, svg {

  display: block;

  max-width: 100%;

}

/*

  7. Remove built-in form typography styles

*/

input, button, textarea, select {

  font: inherit;

}

/*

  8. Avoid text overflows

*/

p, h1, h2, h3, h4, h5, h6 {

  overflow-wrap: break-word;

}

/*

  9. Create a root stacking context

*/

#root, #__next {

  isolation: isolate;

}

Source: 

https://www.joshwcomeau.com/css/custom-css-reset/

No comments:

Post a Comment