How to add a background color

If you like to set a background color on a div or any other html element you can use this code…

background-color: #000;

This would make the background of the div black. You can use any color code you like. Use a color picker to find your preferred color. If you need to add transparency to the background color you can use rgba like this…

background-color: rgba(0,0,0,0.5);

In the example above we set the red, green and blue color to zero. This would result in a black color. The last value defines the degree of transparency. In this case 50% transparent.

  Written by: Michael from Beginnrtuts.com     25-10-2022     Written in: CSS tutorials

One comment

  • Austin says:

    This tutorial was really helpful! I finally understand how to add a background color to my website . Thank you so much for the clear and easy-to-follow instructions.

Leave a Reply

Your email address will not be published. Required fields are marked *