Open In App

Types of CSS (Cascading Style Sheet)

Last Updated : 08 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

CSS is used to style and layout web pages, controlling the appearance of HTML elements. It allows developers to create visually appealing designs and ensure a consistent look across a website.

Types of CSS

CSS can be implemented in three different ways:

  • Inline CSS
  • Internal or Embedded CSS
  • External CSS

1. Inline CSS

Inline CSS involves applying styles directly to individual HTML elements using the style attribute. This method allows for specific styling of elements within the HTML document, overriding any external or internal styles.

Now, let us understand with the help of the example:

html
<p style="color:#009900; 
          font-size:50px; 
          font-style:italic; 
          text-align:center;">
  	Inline CSS
</p>

Output

Inline-CSS

Inline CSS

2. Internal or Embedded CSS

Internal or Embedded CSS is defined within the HTML document’s <style> element. It applies styles to specified HTML elements. The CSS rule set should be within the HTML file in the head section, i.e. the CSS is embedded within the <style> tag inside the head section of the HTML file.

Now, let us understand with the help of the example:

html
<!DOCTYPE html>
<html>

<head>
    <style>
        .main {
            text-align: center;
        }

        .GFG {
            color: #009900;
            font-size: 50px;
            font-weight: bold;
        }

        .geeks {
            font-style: bold;
            font-size: 20px;
        }
    </style>
</head>

<body>
    <div class="main">
        <div class="GFG">Internal CSS</div>

        <div class="geeks">
            Implementation of Internal CSS
        </div>
    </div>
</body>

</html>

Output

Internal-CSS

internal CSS

3. External CSS

External CSS contains separate CSS files that contain only style properties with the help of tag attributes (For example class, id, heading, … etc). CSS property is written in a separate file with a .css extension and should be linked to the HTML document using a link tag. It means that, for each element, style can be set only once and will be applied across web pages.

Now, let us understand with the help of the example:

HTML
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="main">
        <div class="GFG">External CSS </div>
        <div id="geeks">
            This shows implementation of External CSS
        </div>
    </div>
</body>
</html>
CSS
body {
    background-color: powderblue;
}

.main {
    text-align: center;
}

.GFG {
    color: #009900;
    font-size: 50px;
    font-weight: bold;
}

#geeks {
    font-style: bold;
    font-size: 20px;
}

Output

External-CSS

External CSS

When to Use Inline CSS

  • For quick fixes and small changes that don’t require a separate CSS file.
  • When you need to override other styles for a particular element.
  • If you’re working on emails or HTML-based applications where external CSS is not supported.

When to Use Internal CSS

  • When designing a single-page website.
  • If you need better control over styling than inline CSS.
  • For small to medium-sized projects where external CSS might be unnecessary.

When to Use External CSS

  • For large-scale projects where multiple pages share a common design.
  • When maintainability and scalability are priorities.
  • To improve website performance and load times using CSS caching.

Best Type for Multiple Web Pages

External CSS is the most efficient way to style multiple web pages. It ensures:

  • Consistent styling across the website.
  • Easier maintenance by modifying a single file.
  • Faster page loading due to CSS caching.
  • Better separation of concerns between HTML and CSS.
  • Modern web development best practices recommend external CSS for medium to large-scale projects due to its flexibility and efficiency.

Conclusion

Each CSS type has its advantages and use cases. While inline CSS is great for quick changes, it lacks reusability. Internal CSS is better for single-page websites but becomes inefficient for larger projects. External CSS is the preferred approach for modern web development due to its scalability, maintainability, and performance benefits.



Next Article

Similar Reads