The Wayback Machine - https://web.archive.org/web/20240126210058/https://www.geeksforgeeks.org/internal-css/
Open In App
Related Articles

Internal CSS

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

What is Internal CSS ?

The Internal CSS stylesheet is a set of styles created as part of an HTML document. Internal CSS is a method for defining CSS styles within an HTML document’s <style> element, it is used to provide a unique style for a single HTML document in the <head> section. This means that the CSS is embedded within the <style> tag inside the <head> section of the HTML file.

How to Use Internal CSS ?

To use internal CSS, include CSS rules within a <style> tag inside the HTML document’s <head>. Define styles by selecting HTML elements or classes, and applying styling rules within the tag. All the changes done by the internal CSS can be applied only to a single web page.

Syntax:

<style>
/* Internal CSS starts here */
</style>

 

Example: Here is the basic example of using internal CSS.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>Internal CSS</title>
    <style>
        /* Internal CSS  */
        h1 {
            color: green;
            font-size: 50px;
            text-align: center;
        }
  
        p {
            color: blue;
            font-size: 25px;
            line-height: 1.5;
            text-align: center;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <p>A Computer Science Portal..!</p>
</body>
  
</html>


Output:

chrome-capture-2023-6-27

Example 2: In this example, we are using internal CSS to style a page with a green heading, a blue paragraph, and a centered red button that changes color on hover. The button also includes a link to the GeeksforGeeks website.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>Internal CSS</title>
    <style>
        /* Internal CSS starts here */
        h1 {
            color: green;
            text-align: center;
            font-size: 50px;
        }
  
        p {
            font-size: 25px;
            color: blue;
            text-align: center;
        }
  
        .container {
            text-align: center;
        }
  
        .btn {
            background-color: red;
            color: white;
            border-radius: 5px;
            padding: 10px 20px;
            text-decoration: none;
        }
  
        .btn:hover {
            background-color: #0056b3;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <p>A Computer Science Portal..!</p>
    <div class="container">
        <a href="https://www.geeksforgeeks.org/" 
           class="btn">Click Me</a>
    </div>
</body>
  
</html>


Output:

internal-css

Advantages of Internal CSS

  • Internal CSS retains styles in the HTML file, avoiding conflicts with other pages and making easier management of styles at the local level.
  • Internal CSS has higher specificity than external CSS, which allows you to override external styles more easily within the same HTML file.
  • Internal CSS reduces HTTP requests, enhancing performance.
  • Internal CSS is relatively easy to implement, we can use class and ID selectors in this style sheet.

Disadvantages of Internal CSS

  • Repetition in HTML files.
  • Increased file size.
  • Reduced code reusability.
  • Limited style management across pages.

Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Looking for a place to share your ideas, learn, and connect? Our Community portal is just the spot! Come join us and see what all the buzz is about!


Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 18 Sep, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials