Reduce page weight and simplify code overhead with a minimal CSS reset.Jump To The Code
What Is A CSS Reset?
A CSS reset is a snippet of code placed at the beginning of the CSS cascade to set, reset or 'normalize' default styling, establish a predictable starting point for customization and improve cross-browser consistency.
CSS resets in one form or another are a common part of the CSS code that styles website content. Whether added independently or included as part of a front end development framework, a CSS reset is often the first piece of CSS code included in website development projects.
The intended purpose and scope of a CSS reset can vary widely - from a few simple lines to remove default browser styling to a more comprehensive and detailed effort to make HTML elements more uniform between browsers.
Given the way modern web browsers and web standards continue to converge toward a more consistent interpretation and rendering of HTML elements and the CSS that styles them, existing popular CSS resets may be more robust than necessary, particularly for custom designs.
A small CSS reset is an easy way to simplify CSS overhead.
A Minimal Alternative
This minimal CSS reset is designed to remove some default styling on frequently-used elements and add a few common base styles:
As always, be sure to minify the code to reduce file size and logically consolidate with other files for the most efficient file compression.
Obviously any tags or styles can be added, adjusted or omitted as needed, but as is this small CSS reset includes some opinions - particularly what is included and what is omitted.
These few lines focus on the HTML tags most commonly used for a modern website build, with the assumption that other tags will be added as needed or simply styled later in subsequent custom CSS.
Perhaps most notable of what is omitted is applying
box-sizing:border-box to all elements as is often done with the
* universal selector.
Many popular CSS resets include a declaration to set all elements to use
box-sizing:border-box rather than the default
content-box value. Since it will most likely be needed only occasionally, it can be added only where needed.
The very last declaration -
font-size:1.25em - may be the most opinionated.
Given that most web browsers use a default base font size of 16px,
font-size:1.25em increases that value to 20 pixels, which is both highly legible and also a good basis for em-based sizing, with each .05em equivalent to 1px - or more specifically, 1 CSS pixel.
Using a relative value like this rather than an absolute pixel value allows content to scale appropriately depending on the browser base font size and scaling/zooming of the page, both of which should remain adjustable by the user.
Minimize Critical CSS
Along with simplifying CSS code overhead, a minimal CSS reset helps reduce the critical CSS resources needed to render the initially-visible or above-the-fold content of the page.
Eliminate render blocking resources and manage critical vs non-critical resources for page speed:Eliminate Render Blocking Resources