Setting the background color using External CSS

To set the background color using external CSS, define a CSS rule for the desired element’s background color in an external CSS file, then link the CSS file to the HTML document.

Setting the background color using External CSS Syntax

body {
background-color: rgb(219, 176, 230);
}
h1 {
color: green;
text-align: center;
}
h3 {
text-align: center;
}

Setting the background color using External CSS Example:

Here is the basic implementation of Setting the background color using External CSS

HTML




<!DOCTYPE html>
<html>
 
<head>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
 
<body>
    <h1>w3wiki</h1>
    <h3>Changing Background Color (External CSS)</h3>
</body>
 
</html>


CSS




body {
    background-color: rgb(219, 176, 230);
}
 
h1 {
    color: green;
    text-align: center;
}
 
h3 {
    text-align: center;
}


Output:

Setting the background color External CSS

Explanation:

  • In this example we links an external stylesheet (styles.css) using the <link> tag in the <head> section.
  • CSS in styles.css sets the background to rgb(219, 176, 230); for the entire page.
  • CSS defines styles for <h1> (green color, center-aligned) and <h3> (center-aligned).
  • Renders “w3wiki” in <h1> and “Changing Background Color (External CSS)” in <h3> with specified styles.


Set Background Color using CSS

In CSS, setting the background color involves specifying a color for the background of an element using the CSS `background-color` property. This determines the color displayed behind the content within the element on a webpage.

The background color can be changed in three ways:

Table of Content

  • Setting the background color using Inline CSS
  • Setting the background color using Internal CSS
  • Setting the background color using External CSS

Similar Reads

1. Setting the background color using Inline CSS

Setting the background color using inline CSS involves adding the style attribute to the HTML element and specifying the background-color property with a color value, directly within the element’s opening tag....

2. Setting the background color using Internal CSS

...

3. Setting the background color using External CSS

Setting the background color using internal CSS involves defining a style block within the HTML document’s section and specifying the `background-color` property with a color value for the desired elements....