How to Style HTML Elements with CSS
Background Color
CSS allows you to change the background color of any HTML element. To do this, you use the background-color
property. For example, the following code sets the background color of the body
element to blue:
body { background-color: blue; }
You can also set the background color for specific elements, such as headings, paragraphs, and links. For example, the following code sets the background color of all h1
elements to red: h1 { background-color: red; }
Border
CSS allows you to add a border to any HTML element. To do this, you use the border
property. The border
property takes three values: the width of the border, the style of the border, and the color of the border. For example, the following code adds a 1px wide, solid black border to the body
element:
body { border: 1px solid black; }
You can also add a border to specific elements, such as headings, paragraphs, and links. For example, the following code adds a 2px wide, dashed red border to all h1
elements: h1 { border: 2px dashed red; }
Comments