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.
Setting the background color using Inline CSS Syntax
<tag style = " "></tag>
Setting the background color using Inline CSS Example
Below is an example that illustrates the use of inline CSS.
HTML
<!DOCTYPE html> < html > <!--This line changes the color of background--> < body style = "background-color:pink" > < h1 style = "color:green;text-align:center;" > w3wiki </ h1 > < h3 style = "text-align:center;" > How to change color of Background? </ h3 > </ body > </ html > |
Output:
Explanation:
- In this example by using Inline CSS sets the background color of the <body> element to pink using the style attribute.
- Inline CSS also styles headings, making them green and center-aligned.
- Renders headings with “w3wiki” and “How to change color of Background?” in the 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