Introduction
Background color helps make parts of a webpage look nice and easy to see by adding color behind text or images.
Jump into concepts and practice - no test required
selector {
background-color: color-value;
}body {
background-color: lightblue;
}.highlight { background-color: #ffeb3b; }
header {
background-color: rgb(255, 99, 71);
}<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Background Color Example</title> <style> body { background-color: #f0f8ff; font-family: Arial, sans-serif; margin: 2rem; } header { background-color: #4caf50; color: white; padding: 1rem; border-radius: 0.5rem; } .note { background-color: #ffeb3b; padding: 0.5rem; margin-top: 1rem; border-radius: 0.3rem; } </style> </head> <body> <header> <h1>Welcome to My Website</h1> </header> <p>This page shows how background colors can make things look better.</p> <div class="note">This yellow box uses background color to stand out.</div> </body> </html>
background-color do?background-color property sets the color behind the content and padding of an element.color, borders by border, and font style by font-style.background-color.property: value;, so background-color: blue; is correct.div {
background-color: #ff0000;
}#ff0000 means full red, zero green, zero blue.p {
background-color = yellow;
}#d3d3d3 and rgb(211,211,211) represent light gray; color names like 'lightgray' also work.