Browsers' default CSS for HTML elements
Easily inspect HTML elements to check browser default CSS with developer tools:
- Right-click on an element, select Inspect.
- Navigate to the Styles pane to see User Agent Stylesheet defaults.
For consistent cross-browser styling, frameworks like Normalize.css are your friends.
Remember: Use developer tools to peek defaults, and Normalize.css to enforce inconsistency.
Understanding browser stylesheets
Exploring browser stylesheet sources
Every browser has its own default stylesheet. These styles are your first line of rendering before your custom style sheet kicks in.
- Chrome has Blink's
html.css
at its heart (View Source) - Firefox rocks it with Gecko's
html.css
(View Source) - Safari prefers WebKit's
html.css
(View Source) - Edge is all game with Blink's
html.css
thanks to Chromium (View Edge Source) - Internet Explorer also had its own defaults once upon a time (View IE Source)
Not all styles are born equal
Each of these sources conforms to the W3C specification but sprinkles some of their own flavor, resulting in minor inconsistencies. 'Tis these discrepancies that keep us engineers on our toes emoji.
The art of browser style normalization
Frameworks like HTML5 Boilerplate provide us with a "main.css" file loaded with rules to iron out these differences.
Normalize.css is another knight in shining armor doing the same job standalone:
CSS filters for an extra kick
CSS filters can be used to create visual effects like a grayscale, sepia, or blur. Tweak it, transform it, but don't forget to check browser compatibility. Can I Use is your compass here.
Practical use of default styles
Taming form elements
Want to harmonize the styling of form elements? Learn the onset styles and then set your own:
Aligning typography
Ensure parallelism in typography across headings (h1
to h6
), paragraphs (p
), and others:
Balancing the box model
Slight differences in box-sizing across browsers can play havoc with your layouts. Reset box-sizing
:
Revealing invisible elements
Some elements can be elusive. When you donβt see an audio
elements without controls, remember, browser defaults still dictate.
Was this article helpful?