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 — 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, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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).
.overlay {
background: black;
opacity: 0.5;
}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:
.card {
background: rgba(0, 0, 0, 0.5); /* semi-transparent black */
color: white; /* still fully opaque */
}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):
.tooltip {
background: hsla(200, 80%, 20%, 0.85);
color: white;
}Modern Space-Separated Syntax
Modern CSS allows a slash separator for alpha in rgb() and hsl() without the "a" variant:
background: rgb(0 0 0 / 0.5);
background: hsl(0 0% 0% / 0.5);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.
.modal {
opacity: 0;
transition: opacity 300ms ease;
}
.modal.visible {
opacity: 1;
}Transparent Background Pattern
To give an element a translucent background while keeping text fully legible, use rgba() on background-color:
.glass-card {
background: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(10px);
border: 1px solid rgba(255,255,255,0.3);
}Alpha in Border and Box-Shadow
Use RGBA in border-color and box-shadow to create subtle, transparent effects:
.card {
border: 1px solid rgba(0, 0, 0, 0.12);
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}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.
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, and the CSS Academy course includes 4 lessons in total. 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.
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; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
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