Changing Background Color using Internal CSS

Here, we are using Internal CSS, in which we used within the <style> tags in the <head> section of an HTML document to apply styling rules, such as setting the background color, to specific elements.

Background Change using Internal CSS Syntax:

<style>
    Body {
        background-color: greenyellow;
    }
</style>

Changing Background Color using Internal CSS Example:

Here, the background color is set to greenyellow using internal CSS within the <style> tags in the <head> section.

HTML
<html>

    <head>
        <title>Internal CSS</title>
        <style>
            Body {
                background-color: greenyellow;
            }
        </style>
    </head>

    <body>
        <h1>Welcome to w3wiki</h1>
        <h2>We are using the Internal CSS</h2>
    </body>

    </html>

Output:

Changing Background Color using Internal CSS Explanation:

  • Here we are creating basic HTML document with <html>, <head>, <title>, <style>, and <body> tags.
  • Styling applied within the <style> tag targeting the <body> element for background color.

How to change Background Color in HTML ?

The background color in HTML refers to the color displayed behind the content of the webpage.to change it, CSS is used, with various approaches available to change the background color. in which we define the background color property within a CSS rule, specifying a color value such as a name, hexadecimal code, RGB, or HSL value. Apply this rule to the desired HTML element.

There are three methods to change the background color of a document:

Table of Content

  • Changing Background Color using bgcolor attribute
  • Changing Background Color using an Inline CSS
  • Changing Background Color using Internal CSS
  • Changing Background Color using External CSS

Similar Reads

Changing Background Color using bgcolor attribute

HTML allows you to alter the background color of an element using the bgcolor attribute. However, it’s crucial to note that the bgcolor attribute is considered deprecated in HTML5, and it’s recommended to use CSS for styling purposes instead....

Changing Background Color using Inline CSS

In HTML., you can change the background color of an element using inline styling. This approach involves directly adding the style attribute to the HTML element and specifying the desired background colour using the ‘background-colour’ property...

Changing Background Color using Internal CSS

Here, we are using Internal CSS, in which we used within the