Write a program to apply the Internal CSS in HTML.

1
2
3
    <!DOCTYPE html>
4
    <html>
5
    <head>
6
        <style>
7
            body {
8
                background-color: linen;
9
            }
10
            h1 {
11
                color: maroon;
12
                margin-left: 40px;
13
            }
14
        </style>
15
    </head>
16
    <body>
17
        <h1>This is a heading</h1>
18
        <h2>This is the second heading.</h2>
19
    </body>
20
    </html>
21
    

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 Internal CSS in HTML

When the requirement is to add CSS (cascading style sheets) inside the HTML file, then with the help of the <style> tag, the CSS is added internally or embedded inside the HTML page.

In this program, the style tag is used inside the <head> tag.

Why is it used?

  • When you need only one HTML page and don’t want to create an external CSS file.
  • Cleaner than inline CSS, so code maintenance is easier compared to inline CSS.

Real-life Applications

  • Email Templates: In email templates like newsletters or promotional emails, typically internal and inline CSS is used.
  • Single-page landing pages or demos: To test a quick landing page or web app.
  • Online Code Editors & Tutorials: To test the code inside the online editors like MDN or online HTML viewer the inline style is the good choice.

Key Benefits of this Program

  • Everything in a single file: All the HTML and CSS code exists in a single file.
  • Clean Code: Better than inline CSS and easy to maintain.

Limitations of this Program

  • Less Reusability: Because the code is added inside the HTML, common CSS code cannot be shared among multiple files. So, you need to repeat the code.
  • Heavy File Size: Due to CSS inside the HTML, the file size will be large. And the page load speed will be slow. This is not good for SEO.

Alternate Way

You can use the external CSS approach, which can reduce the file size, no need to duplicate the code, and improve the page speed which is good for SEO.

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.