Color Formats, Gradients and Transparency
What Is It?
CSS supports named colors, hexadecimal, RGB, and HSL values. Alpha changes color transparency without fading all descendants.
Properties, Tags and Attributes Explained
rgb(): Describes red, green, and blue channels; an optional slash sets alpha.hsl(): Describes hue, saturation, and lightness; an optional slash sets alpha.opacity: Fades the entire element including its descendants.radial-gradient(): Creates color stops radiating from a center.conic-gradient(): Creates color stops around an angle.currentColor: Uses the computed color property value.
Each example is a complete HTML page. The CSS is inside the head's style element. Use Try in new tab to edit the CSS or HTML, run your changes, and reset the example.
Example 1: Transparent fill
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Color Formats, Gradients and Transparency</title>
<style>
.demo { background: #dbeafe; padding: 16px; }
p { background: rgb(124 58 237 / 20%); padding: 12px; color: hsl(260 70% 25%); border: 2px solid currentColor; }
</style>
</head>
<body>
<div class="demo"><p>Only the background color has alpha.</p></div>
</body>
</html>What you see: The translucent purple fill leaves the text and border fully opaque.
Example 2: Radial gradient
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Color Formats, Gradients and Transparency</title>
<style>
.demo { height: 140px; background: radial-gradient(circle at top left, #fef08a, #f97316); }
</style>
</head>
<body>
<div class="demo"></div>
</body>
</html>What you see: The gradient radiates from the top left.
Example 3: Conic gradient
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Color Formats, Gradients and Transparency</title>
<style>
.demo { width: 140px; height: 140px; border-radius: 50%; background: conic-gradient(#2563eb 0 60%, #e2e8f0 60% 100%); }
</style>
</head>
<body>
<div class="demo" role="img" aria-label="60 percent complete"></div>
</body>
</html>What you see: The circle has a blue 60 percent segment with an accessible text description.
When and Where to Use It
Use alpha for overlays, HSL for adjusting hue or lightness, and gradients for decoration or a chart with an equivalent text description.
Common Mistake or Useful Tip
Changing opacity on a parent also fades its children; use an alpha background when the text should stay opaque.
Try It Yourself
Change the conic split to 75% and update its text description too.