Open In App

Normalize.css

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:



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:

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:

<link rel="stylesheet" href="path/to/normalize.css">
npm install normalize.css
<link rel="stylesheet" href="https://unpkg.com/normalize.css">
@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:

<link rel="stylesheet" type="text/css" href="path/to/normalize.css">
<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




<!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.




<!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.


Article Tags :