SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
HTML
1. HTML Introduction: What is HTML? Learn with Examples 2. Best Free HTML Editors: Notepad to VS Code for Beginners 3. HTML Basic Structure: Doctype, Head, Body Explained 4. HTML Elements Explained: Tags, Content & Empty Elements 5. HTML Attributes List: href, src, alt, width, title & More 6. HTML Headings h1 to h6: Which Heading Tag to Use When 7. HTML Paragraphs: p Tag, br Line Breaks & pre Text 8. HTML Style Attribute: Colour, Font Size & Alignment 9. HTML Text Formatting Tags: bold, italic, mark & More 10. HTML Comments: How to Add Notes & Hide Code in HTML 11. HTML Colors: Names, HEX, RGB & HSL Colour Codes 12. HTML CSS: Inline, Internal & External Stylesheets 13. HTML Links: a Tag, href, New Tab & Email Links 14. HTML Images: img Tag, src, alt, Width & Formats 15. HTML Favicon: Create & Add a Browser Tab Icon 16. HTML Title Tag: How to Write a Good Page Title 17. HTML Tables: table, tr, th, td, colspan & rowspan 18. HTML Lists: ul, ol, dl & Nested Lists Explained 19. HTML Block vs Inline Elements: div, p, span Explained 20. HTML Div Tag: Group Content & Build Page Layouts 21. HTML Class Attribute: Style Many Elements at Once 22. HTML id Attribute: Unique IDs, Links, CSS & JavaScript 23. HTML Iframes: Embed YouTube, Maps & Pages in HTML 24. HTML JavaScript: script Tag, Clicks & First Example 25. HTML File Paths: Relative vs Absolute Paths Explained 26. HTML Head Element: title, meta, charset & viewport 27. HTML Layout: header, nav, main, footer Page Structure 28. HTML Responsive Design: Viewport, Images & Media Queries 29. Semantic HTML Tags: header, nav, main, article & footer 30. HTML Forms: input, label, select, checkbox & Submit 31. HTML Entities: & < > © with Examples 32. HTML Audio & Video Tags: controls, source & Fallback 33. HTML Accessibility: alt Text, Labels, Landmarks & ARIA 34. HTML Meta Tags & SEO: charset, viewport, OG Tags 35. HTML Quotations: blockquote, q, cite, abbr & address
Final Test — Certificate ₹10
Try this code live
Lesson 11 of 35

HTML Colors: Names, HEX, RGB & HSL Colour Codes

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.

Diagram — see how it fits together
Infographic: three ways to write a colour in HTML

Hex codes — the most used

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 and RGBA

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 — the human way

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.

Choosing colours that look good

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.

Tip: Never use pure red text on a pure green background (or the reverse) — it is hard to read and a problem for colour-blind visitors.

Colour formats

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.

FormatValueDescription
Colour namered, tomato, skyblueSimple words. Only 140 standard names exist.
Hex#ff0000Six digits: two for red, two for green, two for blue. The most used format.
RGBrgb(255, 0, 0)Three numbers from 0 to 255, one per colour.
RGBArgba(255, 0, 0, 0.5)RGB plus a fourth number, alpha, from 0 (invisible) to 1 (solid).
HSLhsl(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>
Note: A hex code is read in pairs: #ff0000 means red = ff (255), green = 00 (0), blue = 00 (0). #ffffff is white, #000000 is black, and #808080 is grey.
Tip: Use your browser's colour picker — in Chrome DevTools, click any colour square in the Styles panel and a picker appears. It is the fastest way to find a hex code you like.

Common mistakes

  • Light grey text on a white background — it looks stylish but many people cannot read it.
  • Using too many bright colours on one page — two or three colours are enough.
  • Writing colour in CSS — the property is spelled color.
  • Forgetting the # in a hex code — without it, the browser ignores the value.

Example explained

  • 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.

Example

Example
<!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>

Output

Output — how it looks in the browser
Output of HTML Colors: Names, HEX, RGB & HSL Colour Codes

Try it yourself — live editor

Change the code below and press Run to see the result instantly. No file to save, no login needed.

Result

Frequently asked questions

The questions learners ask most about this lesson — read the question, then open it to see the answer.

1. What are the four ways to write a colour in HTML?

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%).

2. What does a hex code mean?

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).

3. How do I make a colour see-through?

Use RGBA, which adds a fourth number for transparency. For example, rgba(255, 0, 0, 0.5) is red at 50 percent opacity.

Why learn this yourself — and not just ask AI?

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.

Get certified — just ₹10

Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.

Take the test

Prefer watching? Video courses teach the same topics step by step.

Go further with a full course

Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.

Ethical Hacking & Cyber Security Workshop
View
Summer Training in Python Programming 2026
₹3,000
View
Android & iOS App Development using Flutter 2026
₹5,000
View
Browse all courses
HTML — Lessons
1. HTML Introduction: What is HTML? Learn with Examples 2. Best Free HTML Editors: Notepad to VS Code for Beginners 3. HTML Basic Structure: Doctype, Head, Body Explained 4. HTML Elements Explained: Tags, Content & Empty Elements 5. HTML Attributes List: href, src, alt, width, title & More 6. HTML Headings h1 to h6: Which Heading Tag to Use When 7. HTML Paragraphs: p Tag, br Line Breaks & pre Text 8. HTML Style Attribute: Colour, Font Size & Alignment 9. HTML Text Formatting Tags: bold, italic, mark & More 10. HTML Comments: How to Add Notes & Hide Code in HTML 11. HTML Colors: Names, HEX, RGB & HSL Colour Codes 12. HTML CSS: Inline, Internal & External Stylesheets 13. HTML Links: a Tag, href, New Tab & Email Links 14. HTML Images: img Tag, src, alt, Width & Formats 15. HTML Favicon: Create & Add a Browser Tab Icon 16. HTML Title Tag: How to Write a Good Page Title 17. HTML Tables: table, tr, th, td, colspan & rowspan 18. HTML Lists: ul, ol, dl & Nested Lists Explained 19. HTML Block vs Inline Elements: div, p, span Explained 20. HTML Div Tag: Group Content & Build Page Layouts 21. HTML Class Attribute: Style Many Elements at Once 22. HTML id Attribute: Unique IDs, Links, CSS & JavaScript 23. HTML Iframes: Embed YouTube, Maps & Pages in HTML 24. HTML JavaScript: script Tag, Clicks & First Example 25. HTML File Paths: Relative vs Absolute Paths Explained 26. HTML Head Element: title, meta, charset & viewport 27. HTML Layout: header, nav, main, footer Page Structure 28. HTML Responsive Design: Viewport, Images & Media Queries 29. Semantic HTML Tags: header, nav, main, article & footer 30. HTML Forms: input, label, select, checkbox & Submit 31. HTML Entities: & < > © with Examples 32. HTML Audio & Video Tags: controls, source & Fallback 33. HTML Accessibility: alt Text, Labels, Landmarks & ARIA 34. HTML Meta Tags & SEO: charset, viewport, OG Tags 35. HTML Quotations: blockquote, q, cite, abbr & address
Final Test — Certificate ₹10

🤖 KAMALDNP AI Assistant

Ask about courses, website & more

Hi! I'm KAMALDNP AI Assistant. Ask me about our courses, website features, or anything else! 😊
Please wait 5s...
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Please log in to download. You will stay on this page after logging in!

New here? Register now →