Ctrl + K
CSS8 min read

Color Formats Explained (HEX, RGB, HSL)

Understand the most common CSS color formats and how to work with them effectively.

Published: 2026-06-22

Colors are one of the most important aspects of web design and user interfaces. In CSS, developers can define colors using several different formats, with HEX, RGB and HSL being the most common. Although these formats ultimately represent the same colors, each one has advantages depending on the situation. Understanding how they work makes it easier to build consistent and maintainable designs.

Why Multiple Color Formats Exist

Different color formats were created to solve different problems. Some formats are compact and easy to copy from design tools, while others make it easier to adjust brightness, transparency or saturation.

Because modern browsers support multiple formats, developers can choose whichever representation best fits their workflow.

What Is HEX?

HEX is one of the oldest and most widely used color formats on the web. It represents colors using hexadecimal values.

#3b82f6

A HEX color contains six characters after the # symbol. The first two represent red, the next two represent green and the final two represent blue.

How HEX Works

Each color channel uses a hexadecimal value ranging from 00 to FF.

#RRGGBB

For example:

#FF0000 → Red
#00FF00 → Green
#0000FF → Blue

Because hexadecimal values range from 0 to 255, HEX directly maps to RGB values.

Short HEX Syntax

Certain colors can use a shortened three-character format.

#fff

This is equivalent to:

#ffffff

The browser automatically expands each character.

What Is RGB?

RGB stands for Red, Green and Blue. Instead of hexadecimal notation, RGB uses decimal values.

rgb(59, 130, 246)

Each channel ranges from 0 to 255.

The example above represents the same color as:

#3b82f6

Why RGB Is Useful

RGB makes color values more explicit because developers can immediately see the contribution of each color channel.

It is also commonly used when colors are generated dynamically in JavaScript or calculated programmatically.

RGBA and Transparency

RGB can include an alpha channel that controls transparency.

rgba(59, 130, 246, 0.5)

The final value ranges from 0 to 1, where 0 is fully transparent and 1 is fully opaque.

What Is HSL?

HSL stands for Hue, Saturation and Lightness.

hsl(217, 91%, 60%)

Unlike HEX and RGB, HSL focuses on how humans typically think about colors.

Understanding Hue

Hue represents the color's position on a color wheel.

0°   → Red
120° → Green
240° → Blue

Hue values range from 0 to 360 degrees.

Understanding Saturation

Saturation controls the intensity of the color.

0%   → Gray
100% → Full color

Higher saturation values create more vibrant colors.

Understanding Lightness

Lightness controls how bright or dark the color appears.

0%   → Black
50%  → Normal color
100% → White

This makes HSL particularly useful when adjusting color brightness.

Why Designers Like HSL

HSL makes it easy to create color variations. Developers can increase or decrease lightness while preserving the same hue and saturation.

hsl(217, 91%, 40%)
hsl(217, 91%, 60%)
hsl(217, 91%, 80%)

This produces a consistent color scale that is useful for design systems.

HSLA and Transparency

Like RGB, HSL also supports transparency.

hsla(217, 91%, 60%, 0.5)

This behaves similarly to RGBA but uses HSL values instead.

Comparing the Formats

The following examples all represent the same color:

#3b82f6

rgb(59, 130, 246)

hsl(217, 91%, 60%)

The browser converts each format internally before rendering the final color.

When Should You Use HEX?

HEX is compact, widely recognized and commonly exported by design tools such as Figma, Sketch and Adobe XD.

It is often the default choice for static colors in stylesheets.

When Should You Use RGB?

RGB is useful when colors need to be manipulated programmatically or when transparency is required through RGBA values.

JavaScript color calculations often use RGB because the values are easy to process mathematically.

When Should You Use HSL?

HSL is particularly useful when creating design systems, themes and color scales because hue, saturation and lightness can be adjusted independently.

Many developers find HSL easier to reason about than HEX when building consistent visual designs.

Using a Color Converter

Because developers frequently switch between HEX, RGB and HSL, color conversion tools can save time. A color converter instantly transforms one format into another and helps verify that multiple representations correspond to the same color.

Conclusion

HEX, RGB and HSL are simply different ways of describing the same colors. HEX is compact and familiar, RGB is practical for calculations and transparency, while HSL makes color relationships easier to understand. Learning all three formats helps developers work more effectively with modern CSS, design systems and user interfaces.

Related Tools