Background Colour
CSS can be used to change the background colour of a webpage or individual HTML elements.
The background-color property is used to set the colour behind an element, such as a heading, paragraph or the entire webpage.
Example
body {
background-color: lightblue;
}
This CSS rule changes the background colour of the entire webpage to light blue.
- body – the selector, which identifies the HTML element to change
- background-color – the property, which changes the background colour
- lightblue – the value, which specifies the colour
Background Colour Example
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
<style>
body {
background-color: lightyellow;
}
h1 {
background-color: lightblue;
}
p {
background-color: lightgreen;
}
</style>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is a paragraph on my webpage.</p>
<p>This is another paragraph.</p>
</body>
</html>