Write a program to apply the External CSS in HTML.

1
2
    <!-- html code -->
3
    <!DOCTYPE html>
4
    <html>
5
    <head>
6
        <link rel="stylesheet" type="text/css" href="ext.css">
7
    </head>
8
    <body>
9
        <h1>This is a heading</h1>
10
        <p>This is a paragraph.</p>
11
    </body>
12
    </html>
13
14
    <!-- external css code -->
15
16
    h1 {
17
    color: maroon;
18
    margin-right: 50px;
19
    }
20
    body {
21
        background-color: #aaaaaa;
22
    }
23
    

Output

1
2
        No Output Available
3
        

Rate the Code

Reviews are published after a quick safety check (usually within 24 hours).

Reviews are public. Developers can see basic device specifications to respond. Learn more

Core Concept of Applying External CSS in HTML

When you add the CSS rules for any page elements into a dedicated file with a.css extension, that approach is known as external CSS. This file can be used for one page or more than one page.

In this code:

  • External CSS file is connected with <link rel=”stylesheet” type =”text/css” href=”ext.css”>.
  • In the external CSS file, the background color for the body tag and the text color as maroon with right margin to the H1 tag are applied.

Why is it used?

This is the standard and professional approach. When you need to apply consistency to the whole website and don’t want to repeat the code. This is the basic practice to add or apply styles to a page or the whole website.

Real-life Applications

  • Multi-page websites: When there are two or more pages, then external CSS is used.
  • Dark/Light mode switching: To apply different themes of a website, like light, dark, or any other theme. The dhimanp website is the best example of external CSS file embedding because this website contains the external CSS implementation for changing the theme styles.
  • Consistency & Reusability: To maintain consistency and reusability, the external CSS is used.

Benefits of this Program

  • Easy Maintenance: Because all the common CSS code is in a single file, it is easy to update or maintain.
  • Clean HTML code: Due to a dedicated CSS file, the code will be neat and clean.
  • Improves the page Load Speed: Due to a dedicated CSS file, the size of the HTML file will be reduced, so the page load speed will be improved, and SEO will also be improved.
License: This program's source code is open-sourced under the MIT License, while the rest of the program's text content and overall dhimanp platform and brand content remain proprietary under dhimanp.

Submit your modified code

Your submissions are published after a quick safety check (usually within 7 days).

Submissions are public. Developers can see basic device specifications to respond. Learn more

Disclaimer

The information that you shared with us will be publicly visible, and everyone can see your information. And we (dhimanp) are not responsible if anyone misuses this information. We can remove any submitted code at any time for better transparency.

Privacy Policy

If you share your data with us by submitting your code for credit, then we may show your full name, school or college name, and city name on our website.

We are not using this data to track you and are not selling this data to anyone.

If you want to remove your name from our website, you can contact us, and we will remove your name from our website. In the removal process, full credit, including your full name, school or college, city, and code, will be removed from our website.