My CSS Reset
This is my CSS reset which features basic styles which take care of various CSS annoyances. I’ve stolen various rules from people who are much better at CSS than I am, such as:
- Josh Comeau
- Jen Simmon’s CSS Remedy
- Andy Bell’s More Modern Reset
- Mayunk’s CSS Reset
- Elly Joel’s Modern CSS reset
Source Code
/*
My CSS Reset, heavily ripped off from people better at CSS than I am, like:
* CSS Remedy by Jen Simmons https://github.com/jensimmons/cssremedy
* Andy Bell https://piccalil.li/blog/a-more-modern-css-reset/
* Josh W Comeau https://www.joshwcomeau.com/css/custom-css-reset/
* Mayank https://github.com/mayank99/reset.css
* Elly Joel https://www.ellyloel.com/projects/modern-css-reset/
LICENSE: Public Domain
*/
* {
box-sizing: border-box;
}
*:before,
*:after {
box-sizing: inherit;
}
html {
line-height: 1.5;
line-sizing: normal;
/*
Fixes safari's text-sizing issue https://www.farai.xyz/codelab/blog/strange-safari-codeblocks/
*/
text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
-moz-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}
/*
Add smooth scrolling unless a user wants reduced motion
*/
@media (prefers-reduced-motion: no-preference) {
html:focus-within {
scroll-behavior: smooth;
}
}
/*
Adds some margin when yous scroll to an element
*/
:target {
scroll-margin-block: 5ex;
}
body {
margin: 0 auto;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeSpeed;
}
/*
Typography helpers
*/
h1,
h2,
h3,
h4,
h5,
h6 {
line-height: 1.25;
}
/*
Prevent overflowing text
*/
p,
h1,
h2,
h3,
h4,
h5,
h6 {
overflow-wrap: break-word;
}
caption,
figcaption,
label,
legend {
line-height: 1.375;
}
/*
Following two rules are to help with images
*/
img,
svg,
video,
canvas,
audio,
iframe,
embed,
object {
display: block;
vertical-align: middle;
max-width: 100%;
}
img,
svg,
video,
canvas {
height: auto;
}
/*
Prevents weird behavior with font elements: https://iam.farai.xyz/codelab/16px-inputs/
*/
input,
button,
textarea,
select {
font: inherit;
}
/*
Things to do with audio elements
*/
audio {
width: 100%;
}
audio:not([controls]) {
display: none;
}
/*
Learnt this the hard way: https://meowni.ca/hidden.is.a.lie.html
*/
[hidden] {
display: none !important;
}
/*
To visually hide an element: https://www.a11y-collective.com/blog/visually-hidden/
*/
.visually-hidden {
border: 0;
clip-path: inset(50%);
height: 1px;
margin: 0;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}TODO
- Add a whole bunch of other CSS reset rules that are worth having.
- Move this into a git repo.