How to add Opacity to Background color in CSS?

Hello Developers, In this blog, you will learn to add opacity to the background color in CSS. Opacity property defines the transparency of the image. Let us learn in detail about it:- 

Opacity to background color in css

To Add the opacity property to the background color. Firstly  we need to set the background color of the webpage. After setting the color of the webpage we will add the opacity attribute to the code. 

 

The value of the opacity property is from 0.0 to 1.0. The higher the value the more will be transparency of the background color the less the value the less is its transparency. The Code and output for the program are:-

The Code and Output for this Opaity color is:-

<!DOCTYPE html>
<html>
    <head>
        <title> Background Opacity </title>
        <style>
            body{
                background-color: darkgoldenrod;
                opacity: 0.4;
            }
        </style>
    </head>
    <body>
        <h1> Codeblockx </h1>
        <h2> Solution of all your coding question </h2>
    </body>
</html>

OUTPUT

Comparison of Opacity at Different Value :-

Value=0.2

Opacity in html

Value=0.5

opacity to background in html

Value=0.8

Opacity to background

Hope this blog post was helpful to you and you have got the answer to your question. Thank you for visiting our blog. If you have any doubts about any coding questions then let us know in the comments section we will answer them as soon as possible.  Till then check out some more blog post on html.

Leave a Comment

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