4 min read · Free · No login needed
HTML colours are set with CSS. You can write a colour as a name (red), a hex code (#ff0000), an RGB value (rgb(255, 0, 0)), or an HSL value (hsl(0, 100%, 50%)). All four describe the same red — they are just different ways of writing it.
A hex code starts with # followed by six characters: two for red, two for green, two for blue. Each pair goes from 00 (none) to FF (full). So #000000 is black, #ffffff is white, and #e13611 is the orange-red used on this website. Hex codes are exact, short, and every designer uses them.
rgb(255, 0, 0) means red 255, green 0, blue 0. Each number runs from 0 to 255. Add a fourth number for transparency: rgba(255, 0, 0, 0.5) is the same red at 50% opacity, so whatever is behind it shows through.
HSL stands for Hue, Saturation, Lightness. Hue is the colour on a wheel (0 = red, 120 = green, 240 = blue). Saturation is how strong the colour is. Lightness is how bright it is. Many designers prefer HSL because it is easier to think in: "make this a bit lighter" just means raising the lightness number.
Pick one main colour, one dark colour for text, and one accent colour for buttons and links. Keep the contrast high — dark text on a light background is the easiest to read. A good free tool is Google's colour picker or coolors.co, where you can test combinations before using them.
HTML and CSS accept colours in several formats. They all describe the same thing — a mix of red, green, and blue light. Pick the format that is easiest for the job at hand.
| Format | Value | Description |
|---|---|---|
| Colour name | red, tomato, skyblue | Simple words. Only 140 standard names exist. |
| Hex | #ff0000 | Six digits: two for red, two for green, two for blue. The most used format. |
| RGB | rgb(255, 0, 0) | Three numbers from 0 to 255, one per colour. |
| RGBA | rgba(255, 0, 0, 0.5) | RGB plus a fourth number, alpha, from 0 (invisible) to 1 (solid). |
| HSL | hsl(0, 100%, 50%) | Hue (0–360), saturation, lightness. Easy to make lighter or darker shades. |
The same red written three ways — the result on screen is identical:
<p style="color: red;">Red</p> <p style="color: #ff0000;">Red</p> <p style="color: rgb(255, 0, 0);">Red</p>
#ff0000 means red = ff (255), green = 00 (0), blue = 00 (0). #ffffff is white, #000000 is black, and #808080 is grey.colour in CSS — the property is spelled color.# in a hex code — without it, the browser ignores the value.style="color: #e13611;" paints the first paragraph orange-red using a hex code — #e13611 is the exact shade, written as three pairs of digits for red, green and blue.style="background-color: rgb(255, 235, 200);" fills the second paragraph with a light orange background using RGB numbers (255 red, 235 green, 200 blue).style="color: hsl(210, 80%, 40%);" colours the third paragraph blue using HSL — hue 210 (blue on the colour wheel), 80% saturation, 40% lightness.<!DOCTYPE html>
<html>
<head>
<title>Colors</title>
</head>
<body>
<p style="color: #e13611;">Orange-red text (hex).</p>
<p style="background-color: rgb(255, 235, 200);">Light orange background (RGB).</p>
<p style="color: hsl(210, 80%, 40%);">Blue text (HSL).</p>
</body>
</html>
Change the code below and press Run to see the result instantly. No file to save, no login needed.
The questions learners ask most about this lesson — read the question, then open it to see the answer.
As a name like red, a hex code like #ff0000, an RGB value like rgb(255, 0, 0), or an HSL value like hsl(0, 100%, 50%).
It starts with # followed by six characters: two for red, two for green, two for blue. Each pair goes from 00 (none) to FF (full).
Use RGBA, which adds a fourth number for transparency. For example, rgba(255, 0, 0, 0.5) is red at 50 percent opacity.
AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.
Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.
Take the testPrefer watching? Video courses teach the same topics step by step.
Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.
Browse all coursesAsk about courses, website & more
Request human callback:
Please log in to download. You will stay on this page after logging in!
New here? Register now →