CSS resets and normalizing stylesheets are essential tools for web developers to create a consistent foundation for their projects. These techniques help eliminate browser inconsistencies and provide a clean slate for styling.
CSS resets are stylesheets that remove or reset default browser styles. They aim to create a consistent starting point across different browsers by stripping away most pre-defined styles.
CSS normalizing, on the other hand, aims to preserve useful default styles while correcting common browser inconsistencies. It provides a more subtle approach compared to aggressive resets.
A widely used CSS reset that aggressively strips away default styles:
/* Reset CSS */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
A modern, HTML5-ready alternative to CSS resets:
/* Normalize.css (excerpt) */
html {
line-height: 1.15;
-webkit-text-size-adjust: 100%;
}
body {
margin: 0;
}
main {
display: block;
}
h1 {
font-size: 2em;
margin: 0.67em 0;
}
To use a CSS reset or normalize stylesheet in your project:
Remember to consider the CSS Cascading rules when implementing resets or normalizing stylesheets alongside your custom styles.
By implementing CSS resets or normalizing stylesheets, you create a solid foundation for your web projects. This approach ensures consistent styling across browsers and simplifies the process of applying custom styles.
For more information on related topics, explore CSS Specificity and CSS Inheritance to further enhance your understanding of CSS styling principles.