Opacity and RGBA Transparency
Control element transparency using the opacity property and rgba() color values.
Opacity and RGBA Transparency is a free CSS Academy lesson on CoddyKit. This is lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CSS Academy learning path, and your progress syncs across the web and the CoddyKit app. The CSS Academy course includes 4 lessons in total.
The opacity Property
The opacity property sets the transparency of the entire element including its children and content. Values range from 0 (fully transparent) to 1 (fully opaque).
<div class="overlay">Overlay at 50% opacity</div>
opacity Affects All Children
A key caveat: opacity affects the whole element tree. Text, images, and child elements inside an element with opacity: 0.5 are all 50% transparent — you cannot make children more opaque than their parent.
RGBA for Transparent Color Only
To make only the background color transparent without affecting text or children, use rgba() instead of opacity:
<div class="card">Card with transparent background, opaque text</div>
RGBA vs opacity Comparison
Use this mental model:
opacity: 0.5— whole element + children become transparentrgba(r,g,b,0.5)— only the color value is transparent; children remain unaffected
HSLA Transparency
The same principle applies to hsla(). The fourth argument is the alpha channel (0–1):
<div class="tooltip">Tooltip with HSLA background</div>
Modern Space-Separated Syntax
Modern CSS allows a slash separator for alpha in rgb() and hsl() without the "a" variant:
<div class="modern-rgb">rgb(0 0 0 / 0.5)</div>
<div class="modern-hsl">hsl(0 0% 0% / 0.5)</div>
opacity: 0 vs visibility: hidden vs display: none
All three hide elements but differently:
opacity: 0— invisible but still takes up space and is clickablevisibility: hidden— invisible, takes up space, not clickabledisplay: none— removed from layout entirely
Transition with opacity
Because opacity is composited on the GPU, it is one of the cheapest CSS properties to animate. Fade-in/out effects should always use opacity transitions rather than background-color.
<div class="modal visible">Fades in via opacity transition</div>
Transparent Background Pattern
To give an element a translucent background while keeping text fully legible, use rgba() on background-color:
<div class="glass-card">Glass effect card</div>
Alpha in Border and Box-Shadow
Use RGBA in border-color and box-shadow to create subtle, transparent effects:
<div class="card">Card with alpha border & shadow</div>
Accessibility Reminder
Low-opacity text reduces readability and may fail WCAG color contrast requirements. Always verify contrast ratios when using transparency on text. Ensure a minimum 4.5:1 ratio for normal text.
Quick Check
An element has opacity: 0.3. What happens to text inside it?
Recap
opacity makes an entire element and its children transparent. Use rgba() or hsla() for transparent colors without affecting children. Opacity transitions are GPU-accelerated and performant. Always check contrast ratios when using transparency on text.
Learn CSS with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 40
- Lessons
- 159
Frequently Asked Questions
Is the “Opacity and RGBA Transparency” lesson free?
Yes — the full text of “Opacity and RGBA Transparency” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CSS Academy course, upgrade to CoddyKit PRO. The CSS Academy course includes 4 lessons in total.
What will I learn in “Opacity and RGBA Transparency”?
Control element transparency using the opacity property and rgba() color values. You practise CSS Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start CSS Academy?
No prior experience is required. CSS Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 4 of 4.
How long does the “Opacity and RGBA Transparency” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this CSS Academy lesson?
Yes. Every CSS Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Color Values: Named, Hex, RGB, HSL
- Background Color and Image
- Gradients: Linear and Radial
- Opacity and RGBA Transparency