Open In App

CSS fill-opacity Property

The fill-opacity property is used to set the opacity of the paint server that is applied to the shape. basically is used to set the opacity level of the fill color of an SVG shape. It determines the transparency of the fill, with a value between 0 and 1, where 0 represents completely transparent and 1 represents completely opaque. 

Syntax:



fill-opacity: [0-1] | <percentage>

Property Values:

Example 1: In this example, we are using property Values between 0 and 1.






<!DOCTYPE html>
<html>
<head>
    <title>
        CSS | fill-opacity
    </title>
    <style>
        .opacity1 {
            /* completely
        visible fill */
            fill-opacity: 1.0;
 
            fill: green;
        }
 
        .opacity2 {
            fill-opacity: 0.5;
 
            fill: green;
        }
 
        .opacity3 {
            fill-opacity: 0.25;
 
            fill: green;
        }
 
        .opacity4 {
            /* completely
        transparent fill */
            fill-opacity: 0;
 
            fill: green;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
    <b>
        CSS | fill-opacity
    </b>
    <div class="container">
        <svg height="250px"
             width="500px"
             xmlns="http://www.w3.org/2000/svg"
             version="1.1">
            <circle class="opacity1" cx="100" cy="100" r="50" />
            <circle class="opacity2" cx="250" cy="100" r="50" />
            <circle class="opacity3" cx="400" cy="100" r="50" />
            <circle class="opacity4" cx="400" cy="100" r="50" />
        </svg>
    </div>
</body>
</html>

Output:

 

Example 2: In this example, we are using property Values in percentage.




<!DOCTYPE html>
<html>
<head>
    <title>
        CSS | fill-opacity
    </title>
    <style>
        .opacity1 {
            /* completely visible
        fill */
            fill-opacity: 100%;
 
            fill: green;
        }
 
        .opacity2 {
            fill-opacity: 50%;
 
            fill: green;
        }
 
        .opacity3 {
            fill-opacity: 25%;
 
            fill: green;
        }
 
        .opacity4 {
            /* completely
        transparent fill */
            fill-opacity: 0%;
 
            fill: green;
        }
    </style>
</head>
 
<body>
    <h1 style="color: green">
        GeeksforGeeks
    </h1>
    <b>
        CSS | fill-opacity
    </b>
    <div class="container">
        <svg height="250px"
             width="500px"
             xmlns="http://www.w3.org/2000/svg"
             version="1.1">
            <rect class="opacity1" x="25" y="10" height="150" width="100" />
            <rect class="opacity2" x="175" y="10" height="150" width="100" />
            <rect class="opacity3" x="325" y="10" height="150" width="100" />
            <rect class="opacity4" x="325" y="10" height="150" width="100" />
        </svg>
    </div>
</body>
</html>

Output: 

Supported Browsers: The browser supported by the fill-opacity property are listed below:


Article Tags :