CHAPTER 31
CSS Opacity
Learn how to control the transparency of elements using the CSS opacity property.
01. What is CSS Opacity?
The opacity property controls how transparent an element appears.
A value of 1 means fully visible.
A value of 0 means completely transparent.
Values between 0 and 1 create different transparency levels.
02. Syntax
selector {
opacity: value;
}
03. Example
CSS / HTML Example
AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>
<style>
.card {
width: 250px;
padding: 30px;
background: #2563eb;
color: white;
opacity: 0.7;
}
.card:hover {
opacity: 1;
}
</style>
</head>
<body>
<div class="card">
<h2>AIFA Infotech</h2>
<p>
Hover over this card.
</p>
</div>
</body>
</html>
04. Important Points
✓
opacity: 1 means fully visible.
✓
opacity: 0 means completely transparent.
✓
opacity: 0.5 creates approximately 50% transparency.
✓
Opacity affects the entire element including its contents.
05. Common Mistakes
⚠
Using very low opacity that makes text difficult to read.
⚠
Forgetting that child elements are also visually affected.
⚠
Using opacity when a transparent background color would be more appropriate.
06. Real World Use
Opacity is commonly used for hover effects, disabled elements, overlays, image effects and visual transitions.
Ready to Practice? 🚀
Open the AIFA CSS Editor and practice this chapter live.
Try It Yourself →
Practice Exercise
Create an Opacity Card
Create a card with opacity 0.6 and change it to opacity 1 when the user hovers over it.