KoderSolution Logo
HomeArticlesTutorialsForumAI LabRun Code
KoderSolution Logo

The world’s most advanced technical ecosystem for modern software engineers. Learn, build, and grow with next-generation developer tools and resources.

Engineering Newsletter

Join 100,000+ engineers receiving curated high-signal content weekly.

Platforms

  • Technical Articles
  • Interactive Tutorials
  • AI Coding Lab
  • Developer Forum
  • Developer Tools

Pages

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of Service
  • Refund Policy
  • Disclaimer
  • Advertisement

Popular Topics

  • PHP
  • Laravel
  • Python
  • React.Js
  • MySQL
© 2026 KoderSolutionAll Rights Reserved
Developed Bymaksudur.dev
🌐

HTML

Topic Hub & Articles

HTML HOME

3 min

HTML Introduction

5 min

HTML Editors

10 min

Recap Quiz

5 Questions

HTML Basic

10 min

HTML Elements

10 min

HTML Attributes

10 min

Recap Quiz

5 Questions

HTML Headings

10 min

HTML Styles

10 min

Recap Quiz

5 Questions

HTML Paragraphs

10 min

HTML Formatting

10 min

HTML Quotations

10 min

HTML Comments

10 min

Recap Quiz

5 Questions

HTML Colors

7 min

HTML CSS

10 min

HTML Links

10 min

Recap Quiz

5 Questions

HTML Images

10 min

HTML Favicon

10 min

HTML Page Title

10 min

Recap Quiz

5 Questions

HTML Tables

10 min

HTML Lists

10 min

HTML Block and Inline

10 min

Recap Quiz

5 Questions

HTML Classes

10 min

HTML Id

10 min

HTML Iframes

10 min

Recap Quiz

5 Questions

HTML JavaScript

10 min

HTML File Paths

10 min

HTML Head

10 min

Recap Quiz

5 Questions

HTML Layout

10 min

HTML Responsive

10 min

HTML Computercode

10 min

Recap Quiz

5 Questions

HTML Forms

10 min

HTML Form Attributes

10 min

HTML Form Elements

10 min

Recap Quiz

5 Questions

HTML Input Types

10 min

HTML Input Attributes

10 min

HTML Input Form Attributes

10 min

Recap Quiz

5 Questions

HTML Canvas

10 min

HTML SVG

10 min

HTML Media Intro

10 min

HTML Video

10 min

HTML Audio

10 min

Recap Quiz

5 Questions

HTML YouTube

10 min

HTML Geolocation

10 min

HTML Drag/Drop

10 min

HTML Local Storage

10 min

Recap Quiz

5 Questions

HTML Session Storage

10 min

HTML Web Workers

10 min

HTML SSE

10 min

Recap Quiz

5 Questions

HTML Semantics

10 min

HTML Accessibility

10 min

HTML Entities

10 min

Recap Quiz

5 Questions

HTML Symbols

10 min

HTML Emojis

10 min

HTML Charset

10 min

Recap Quiz

5 Questions

HTML URL Encode

10 min

HTML XHTML

10 min

HTML Global Attributes

10 min

Recap Quiz

5 Questions

HTML Event Attributes

10 min

HTML Color Groups

10 min

HTML URL Paths

10 min

Recap Quiz

5 Questions

HTML Summary

10 min

Progress
0%

0 / 61 Lessons

HTMLHTML Tutorial
Lesson

HTML Colors

7 min reading
Free Course

HTML Colors: Color Names, Hex, RGB, and HSL Values

HTML colors define the visual color palette of elements on a web page. You can apply colors to text, background surfaces, borders, and shadows using color names, Hex codes, RGB values, or HSL representations.

HTML Color Representation Formats

Web browsers support four primary methods to declare colors in HTML and CSS:

  1. Color Names: Standardized color keywords like Tomato, DodgerBlue, MediumSeaGreen, and SlateGray. HTML supports 140 standard color names.
  2. Hexadecimal Codes (HEX): Six-digit hexadecimal values representing Red, Green, and Blue intensity from 00 to FF (e.g., #ff6347 or #0f172a).
  3. RGB / RGBA Values: Color functions defining Red, Green, and Blue values from 0 to 255 (e.g., rgb(255, 99, 71)). RGBA adds an Alpha channel (0.0 to 1.0) for background transparency.
  4. HSL / HSLA Values: Color functions based on Hue (0 to 360 degrees), Saturation (0% to 100%), and Lightness (0% to 100%). HSLA includes Alpha opacity.

Color Model Comparison

The diagram below shows how different color formats define colors and handle transparency:

flowchart TD
    A["HTML Colors"] --> B["Opaque Color Formats"]
    A --> C["Alpha / Transparency Formats"]
    B --> B1["Color Names (DodgerBlue)"]
    B --> B2["Hex Codes (#2563eb)"]
    B --> B3["RGB (rgb(37, 99, 235))"]
    C --> C1["RGBA (rgba(37, 99, 235, 0.8))"]
    C --> C2["HSLA (hsla(221, 83%, 53%, 0.8))"]
    C --> C3["8-Digit Hex (#2563ebcc)"]

Practical Code Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>HTML Colors Example</title>
</head>
<body style="background-color: #f8fafc; font-family: sans-serif; padding: 20px; color: #334155;">

    <!-- Heading styled with named color -->
    <h2 style="color: DodgerBlue; text-align: center;">HTML Color Formats Overview</h2>

    <!-- Card container with hex background and styled border -->
    <div style="background-color: #ffffff; border: 2px solid #e2e8f0; border-radius: 8px; padding: 20px; max-width: 600px; margin: 0 auto;">
        
        <!-- Text with RGB color -->
        <p style="color: rgb(220, 38, 38); font-weight: bold;">
            Red text defined using RGB: rgb(220, 38, 38)
        </p>

        <!-- Paragraph with HSL background -->
        <p style="background-color: hsl(142, 71%, 45%); color: #ffffff; padding: 10px; border-radius: 4px;">
            Green callout container using HSL: hsl(142, 71%, 45%)
        </p>

        <!-- Box with semi-transparent RGBA background -->
        <div style="background-color: rgba(37, 99, 235, 0.15); color: #1e40af; border-left: 4px solid #2563eb; padding: 12px;">
            This alert box uses RGBA with 15% opacity for a smooth overlay effect.
        </div>

    </div>

</body>
</html>

Best Practices

  • Ensure WCAG color contrast accessibility: Always maintain a high contrast ratio (at least 4.5:1 for normal text) between foreground text colors and background surfaces so users with visual impairments can comfortably read content.
  • Use HSL for dynamic design system themes: HSL makes adjusting color shades much easier than Hex or RGB because you can tweak lightness (0% to 100%) without changing the base hue angle.
  • Store brand colors in CSS variables: Avoid hardcoding hex strings directly across dozens of inline style attributes. Declare colors inside CSS custom properties (--primary-color: #2563eb;) for clean theme maintenance.

Self-Check Challenge

Create an HTML <div> callout box styled with a dark navy background (#0f172a), teal border (#14b8a6), light cyan text (#e0f2fe), and a semi-transparent shadow using RGBA!

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Recommended Courses & Books

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum