How do I create a full-width background color that spans the entire viewport?
Asked on Aug 26, 2025
Answer
To create a full-width background color that spans the entire viewport, you can use CSS to set the background color on the `` or `` element, ensuring it covers the entire visible area.
<!-- BEGIN COPY / PASTE -->
<style>
body {
margin: 0; /* Remove default margin */
background-color: lightblue; /* Set desired background color */
}
</style>
<!-- END COPY / PASTE -->Additional Comment:
- Setting the margin to 0 on the body removes any default spacing that might prevent the background from reaching the edges.
- The background color will automatically extend to fill the entire viewport width and height.
- You can change "lightblue" to any color you prefer, using color names, hex codes, or RGB values.
Recommended Links: