Opacity
Opacity utilities make an element more or less see-through.
In this page:
Syntax
<div class="opacity-50">content</div>
Opacity
.opacity-100, .opacity-75, .opacity-50 and .opacity-25 set the whole element's transparency. For colours only, use .text-opacity-* and .bg-opacity-*, which leave the content fully opaque. Opacity affects children too, so choose the right utility.
Note:
bg-opacity changes only the background, not the text on top.
Example: Opacity
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="container">
<div class="bg-primary text-white p-2 mb-1 opacity-100">opacity-100</div>
<div class="bg-primary text-white p-2 mb-1 opacity-50">opacity-50 (text fades too)</div>
<div class="bg-primary bg-opacity-25 p-2 mb-1">bg-opacity-25 (text stays solid)</div>
</div>
</body>
</html>
Live Example
Related Topics
Common Mistakes
- Using opacity when only the background should fade
- Making text unreadable
- Forgetting bg-opacity needs a bg colour class
Chapter Summary
- opacity-25, 50, 75, 100
- bg-opacity and text-opacity affect colours only
- Opacity affects children
- Needs a background class for bg-opacity
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: