Course Content
CSS Basic
0/1
CSS Selectors
0/1
CSS Comments
0/1
CSS Backgrounds
0/1
CSS Borders
0/1
CSS Outline
0/1
CSS Fonts
0/1
CSS Height and Width
0/1
CSS Margins and Paddings
0/2
CSS Icons
0/1
CSS Links
0/1
CSS Lists
0/1
CSS Tables
0/1
CSS Display Properties
0/1
CSS Max-Width Property
0/1
CSS Positioning Elements
0/1
CSS Z-Index Property
0/1
CSS Overflow
0/1
CSS Float
0/1
CSS Opacity
0/1
CSS Forms
0/1
CSS Dropdowns
0/1
CSS Buttons
0/1
CSS Media Queries
0/1
About Lesson

The opacity property in CSS is used to set the transparency of an element, making it partially or fully transparent. The value of opacity is a number between 0 (completely transparent) and 1 (completely opaque).

Syntax:

selector {
opacity: value;
}

Example:

<!DOCTYPE html>
<html lang=”en”>
<head>
    <meta charset=”UTF-8″>
    <meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
    <style>
        .transparent-box {
            width: 200px;
            height: 200px;
            background-color: #3498db;
            opacity: 0.5;
            /* Set opacity to 50% */
        }
        .opaque-box {
            width: 200px;
            height: 200px;
            background-color: #e74c3c;
            opacity: 1;
            /* Set opacity to 100% (fully opaque) */
        }
        img {
            height: 200px;
            background-color: #3498db;
            opacity: 0.4;
        }
    </style>
    <title>CSS Opacity Example</title>
</head>
<body>
    <div class=”transparent-box”>
        This is a transparent box.
    </div>
    <br>
    <img src=”R.jpeg” />
    <br>
    <div class=”opaque-box”>
        This is an opaque box.
    </div>
</body>
</html>

Output: