To set the background color to an html element, we can use the css background-color property.

Syntax #

div{
 background-color:yellow;
}

We will use the style attribute to set background color of an element. The style attribute specifies an inline style for an element.

<div style="background-color:yellow">
  This is a block element.
</div>