Open In App

Normalize.css

Last Updated : 28 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Normalize.css is a small CSS file that makes browsers render HTML elements more consistently and in line with modern standards. It was developed by Nicolas Gallagher, co-creator of Twitter Bootstrap, as a modern alternative to traditional CSS resets. Normalize.css preserves default styles for HTML elements, sets base styles for common elements, corrects browser bugs, and improves accessibility by setting font size, line height, and styling form controls. The importance of Normalize.css lies in its approach to rendering elements consistently across all browsers, reducing the need for custom CSS and making it easier to style elements. Normalize.css is available on CDNs and can be downloaded and hosted locally, installed with a package manager, or imported as part of a CSS framework.

Normalize.css is an alternative approach to traditional CSS resets, and it has several advantages over traditional resets. Here are some reasons why Normalize.css is important:

  • Preserves useful defaults: Unlike traditional CSS resets, Normalize.css preserves some useful default styles of HTML elements, such as font sizes for headings and the display property for certain elements. This means that developers don’t have to spend time re-adding these styles that have already been provided by the browser.
  • Cross-browser consistency: Normalize.css is specifically designed to work across all modern browsers, including Chrome, Firefox, Safari, and Internet Explorer. By providing a consistent baseline across all browsers, Normalize.css helps ensure that a website’s layout and design will be consistent and predictable, regardless of the user’s browser or device.
  • Modular design: Normalize.css is designed to be modular, which means that developers can choose to include only the parts of the stylesheet that they need for their project. This can help reduce the overall file size and make it easier to maintain the stylesheet.
  • Less opinionated: Normalize.css is less opinionated than traditional CSS resets, which often impose a particular design style on developers. Instead, Normalize.css provides a neutral, consistent starting point for styling HTML elements, allowing developers to implement their own design style without being restricted by the reset stylesheet.
  • Easier to use: Normalize.css is easier to use than traditional CSS resets because it requires less customization and configuration. Developers can simply include the stylesheet in their project and start using it right away, without having to spend time configuring it to their specific needs.

Overall, Normalize.css is important because it provides a consistent, cross-browser baseline for styling HTML elements, which makes it easier for developers to create consistent and predictable layouts across different devices and browsers. It also provides a modular, less opinionated, and easier-to-use alternative to traditional CSS resets.

 

Features of Normalize.css:

  • Resets styles: Normalize.css resets the default styles of HTML elements to a consistent baseline, eliminating browser inconsistencies and allowing developers to start styling from a consistent base.
  • Preserves useful defaults: Unlike some other reset stylesheets, Normalize.css preserves some useful defaults, such as font sizes for headings and the display property for certain elements.
  • Cross-browser compatibility: Normalize.css is designed to work across all modern browsers, including Chrome, Firefox, Safari, and Internet Explorer.
  • Modular design: Normalize.css is modular, allowing developers to include only the parts they need for their projects.
  • Customizable: Developers can customize the styles provided by Normalize.css to meet their specific needs.
  • Less opinionated: Normalize.css is less opinionated than some other reset stylesheets, meaning it doesn’t impose a particular design style on developers. Instead, it provides a neutral, consistent starting point for styling HTML elements.

Overall, Normalize.css is a useful tool for ensuring a consistent, predictable starting point for CSS styles, regardless of the browser or device being used.

There are several ways to implement Normalize.css into a project:

  • Download and include the CSS file: You can download the latest version of Normalize.css from its website or from a CDN, and then include it in your HTML code using the <link> tag.
<link rel="stylesheet" href="path/to/normalize.css">
  • Install with a package manager: You can also install Normalize.css using a package manager like npm or Yarn. This will allow you to easily update to the latest version in the future.
npm install normalize.css
  • Use a CDN: You can link to a hosted version of Normalize.css from a content delivery network (CDN) like unpkg or cdnjs. This can provide faster loading times and reduce the amount of code you need to host on your own server.
<link rel="stylesheet" href="https://unpkg.com/normalize.css">
  • Use a CSS preprocessor: If you use a CSS preprocessor like Sass or Less, you can import Normalize.css into your stylesheet using an @import statement.
@import 'path/to/normalize.css';

Regardless of how you choose to implement Normalize.css, it’s important to include it at the beginning of your stylesheet, before any other styles. This will ensure that its styles are applied before any other styles, providing a consistent baseline for your layout.

Normalize.css aims to solve the inconsistent default styles of HTML elements across different browsers. Every browser has its own set of default styles for HTML elements, which can make it difficult for web developers to create consistent and predictable layouts. Inconsistent default styles can also cause cross-browser compatibility issues, as different browsers may interpret the same HTML and CSS code in different ways. This can lead to visual inconsistencies and make it difficult to create a website that looks and works the same across all browsers and devices.

Normalize.css addresses this problem by providing a standardized set of styles that normalize the default styles of HTML elements across all modern browsers. By resetting the styles of HTML elements to a consistent baseline, Normalize.css helps ensure that web developers can create predictable layouts and designs, regardless of the browser or device being used.

Approach: To use normalize.css, simply include it in your HTML file before your own stylesheet. It can be included in two ways:

  • Download the normalize.css file and link to it in your HTML file:
<link rel="stylesheet" type="text/css" href="path/to/normalize.css">
  • Include it from a CDN:
<link rel="stylesheet" 
      href=
"https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css">

We will understand Normalize.css & its usage by implementing it in the examples.

Example 1: In this example, we are using the Normalize.css file by downloading it to the local machine. Here, we have downloaded the file & stored it in the current working directory. In order to see the changes, modify the CSS code in the Normalize.css

HTML




<!DOCTYPE html>
<html>
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, 
                   initial-scale=1.0">
    <link rel="stylesheet" 
          type="text/css" 
          href="normalize.css">
  
    <title>Normalize.css</title>
</head>
  
<body>
    <h1 style="color:green">
          GeeksforGeeks
      </h1>
    <h3>Normalize.css</h3>
    <p>Welcome to GeeksforGeeks</p>
</body>
  
</html>


Output:

 

Example 2: In this example, we have created 2 buttons, where the function for 1 button is to add the Normalize.css file by using the CDN link & another button will use to remove the implemented Normailze.css file.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <meta charset="UTF-8">
    <script src=
    </script>
    <meta name="viewport" 
          content="width=device-width, 
                   initial-scale=1.0">
    <script>
        function Click() {
            $(document).ready(function () {
                $('head').find('link').remove();
            });
        }
    </script>
</head>
  
<body>
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
    <h3>Normalize.css</h3>
    <p>
        Welcome to GeeksforGeeks
    </p>
    <button onclick="myFunction()">
        Click Me to Add
    </button>
    <button onclick="Click()">
        Click Me to Remove
    </button>
  
    <script>
        function myFunction() {
            var head = document.getElementsByTagName('HEAD')[0];
            var link = document.createElement('link');
            link.rel = 'stylesheet';
            link.type = 'text/css';
            link.href = 
  
            // Append link element to HTML head
            head.appendChild(link);
        }
    </script>
</body>
  
</html>


Output:

 

Conclusion: Normalize.css is a modern alternative to traditional CSS resets that helps ensure consistent rendering of HTML elements across all browsers. Its approach to preserving useful defaults and correcting browser bugs makes it easier to style elements and improve accessibility. There are several ways to implement Normalize.css into a project, including linking to a CDN, downloading and hosting locally, installing with a package manager, or importing as part of a CSS framework.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads