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
🎨

CSS

Topic Hub & Articles

CSS Introduction

10 min

CSS Syntax

10 min

CSS Selectors

10 min

Recap Quiz

5 Questions

CSS How To

10 min

CSS Comments

10 min

CSS Colors

10 min

Recap Quiz

5 Questions

CSS Backgrounds

10 min

CSS Borders

10 min

CSS Margins

10 min

Recap Quiz

5 Questions

CSS Padding

10 min

CSS Height/Width

10 min

CSS Box Model

10 min

Recap Quiz

5 Questions

CSS Outline

10 min

CSS Text

10 min

CSS Fonts

10 min

Recap Quiz

5 Questions

CSS Icons

10 min

CSS Links

10 min

CSS Lists

10 min

Recap Quiz

5 Questions

CSS Tables

10 min

CSS Display

10 min

CSS Max-width

10 min

Recap Quiz

5 Questions

CSS Position

10 min

CSS Overflow

10 min

CSS Float

10 min

Recap Quiz

5 Questions

CSS Inline-block

10 min

CSS Align

10 min

CSS Combinators

10 min

Recap Quiz

5 Questions

CSS Pseudo-class

10 min

CSS Pseudo-element

10 min

CSS Opacity

10 min

Recap Quiz

5 Questions

CSS Navigation Bar

10 min

CSS Dropdowns

10 min

CSS Image Gallery

10 min

Recap Quiz

5 Questions

CSS Attribute Selectors

10 min

CSS Rounded Corners

10 min

CSS Gradients

10 min

CSS Shadows

10 min

Recap Quiz

5 Questions

CSS 2D Transforms

10 min

CSS 3D Transforms

10 min

CSS Transitions

10 min

Recap Quiz

5 Questions

CSS Animations

10 min

CSS Tooltips

10 min

CSS Images

10 min

Recap Quiz

5 Questions

CSS Flexbox

10 min

CSS Grid

10 min

CSS Media Queries

10 min

Recap Quiz

5 Questions

Progress
0%

0 / 46 Lessons

CSSCSS Tutorial
Lesson

CSS Colors

10 min reading
Free Course

CSS Colors: Color Formats, Named Colors, Hex, RGB, HSL, and Alpha Transparency

CSS colors define the visual color palette of elements on a web page. You can apply colors to text, surface backgrounds, borders, shadows, and SVG paths using color names, Hex codes, RGB values, or HSL representations.

Color Representation Formats

CSS supports five primary methods to declare colors:

.box-named { color: DodgerBlue; }
.box-hex   { color: #38bdf8; }
.box-rgb   { color: rgb(56, 189, 248); }
.box-rgba  { color: rgba(56, 189, 248, 0.8); }
.box-hsl   { color: hsl(199, 94%, 60%); }

Color format categories:

  1. Named Colors: Standardized keywords like Tomato, DodgerBlue, SlateGray.
  2. Hex Codes (#RRGGBB): Six-digit hexadecimal values representing Red, Green, and Blue intensity from 00 to FF.
  3. RGB / RGBA: Red, Green, and Blue values from 0 to 255. RGBA adds an Alpha opacity channel (0.0 to 1.0).
  4. HSL / HSLA: Hue (0 to 360 degrees), Saturation (0% to 100%), and Lightness (0% to 100%).

Color Model Comparison

flowchart TD
    A["CSS Colors"] --> B["Opaque Color Formats"]
    A --> C["Alpha / Transparency Formats"]
    B --> B1["Color Names (DodgerBlue)"]
    B --> B2["Hex Codes (#38bdf8)"]
    B --> B3["RGB (rgb(56, 189, 248))"]
    C --> C1["RGBA (rgba(56, 189, 248, 0.8))"]
    C --> C2["HSLA (hsla(199, 94%, 60%, 0.8))"]
    C --> C3["8-Digit Hex (#38bdf8cc)"]

Practical Code Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CSS Colors Demonstration</title>
    <style>
        .color-card {
            background-color: #1e293b;
            border-radius: 8px;
            padding: 1.5rem;
            max-width: 500px;
        }
        .text-hex { color: #38bdf8; }
        .text-hsl { color: hsl(142, 71%, 45%); }
        .bg-rgba  { background-color: rgba(37, 99, 235, 0.15); color: #60a5fa; padding: 10px; border-radius: 4px; }
    </style>
</head>
<body style="background-color: #0f172a; color: #f8fafc; font-family: system-ui, sans-serif; padding: 2rem;">

    <div class="color-card">
        <h2>CSS Color Models Overview</h2>
        <p class="text-hex">Hex Code Color: #38bdf8</p>
        <p class="text-hsl">HSL Color: hsl(142, 71%, 45%)</p>
        <div class="bg-rgba">Semi-transparent RGBA background overlay</div>
    </div>

</body>
</html>

Best Practices

  • Ensure WCAG color contrast accessibility: Maintain a contrast ratio of at least 4.5:1 between text colors and background surfaces.
  • Use HSL for theme color variations: HSL makes tweaking lightness (0% to 100%) easy without altering base color hue.
  • Use CSS variables for site color themes: Store brand hex values inside :root variables (--color-primary: #38bdf8;).

Self-Check Challenge

Create a CSS class .overlay that sets a semi-transparent dark background using rgba(15, 23, 42, 0.75)!

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
Lesson Recap Quiz Available

Test Your Knowledge

You've completed this section! Take a quick 5-question quiz to check your understanding.

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum