iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

CSS Colors

CSS lets you specify colors in several formats. They all reach the same place — pixels on a screen — but they make life easier in different situations.

Color formats

FormatExampleUse it when…
Namedtomato, rebeccapurpleYou need a quick, memorable color.
Hex#04AA6DYou want a compact form (3, 4, 6, or 8 hex digits).
RGBrgb(4 170 109)You're tweaking individual channels.
RGBArgb(4 170 109 / 0.5)You need transparency.
HSLhsl(155 95% 34%)You want to reason about hue / saturation / lightness.
HSLAhsl(155 95% 34% / 0.5)HSL with transparency.
currentColorborder-color: currentColorYou want to inherit the element's text color.

A quick palette

#04AA6D #2965F1 #E44D26 #ffd333 #282a35 #f1f1f1
Fig 1. Six colors from the iwantcoding.com palette.
Tip: Pick HSL when you need to generate consistent hover or disabled states — bumping the lightness by ±10% is far more predictable than nudging hex digits.

Example

Example
<!DOCTYPE html>
<html>
<head>
<style>
h1 { color: #04AA6D; }
p  { color: rgb(40, 42, 53); background: #f1f1f1; padding: 8px; }
</style>
</head>
<body>

<h1>Hello, color!</h1>
<p>This paragraph has a grey background and dark text.</p>

</body>
</html>
Try it Yourself »

Exercise

Use the hex code for the brand green (#04AA6D) as the heading colour.

h1 { color: ; }

Test yourself

Q1. Which color format includes transparency?
Q2. How many hex digits does `#04AA6D` contain?
Q3. Which CSS keyword inherits the element's current text color?

Discussion

Loading…