HTML colour codes — HEX, RGB, HSL and alpha for any colour

Pick a colour and an opacity and get every code CSS and HTML accept, from #34d399 to rgba() and hsl(), along with ready-to-paste CSS rules and inline-style examples.

Live demo · real result from this tool

Colours

Colour codes

FormatValue
HEX#34d399
HEX + alpha#34d399ff
RGBrgb(52, 211, 153)
RGBArgba(52, 211, 153, 1)
HSLhsl(158, 64%, 52%)
HSLAhsla(158, 64%, 52%, 1)
Modern CSSrgb(52 211 153 / 100%)

Snippets

/* CSS */.brand { color: #34d399; }.badge { background-color: #34d399; border: 1px solid #34d399; }:root { --brand: #34d399; } <!-- HTML --><span style="color: #34d399">Coloured text</span><div style="background-color: #34d399; padding: 1rem">Coloured box</div>

Processed on your device — nothing is uploaded.

How to use the HTML colour code generator

  1. Choose a colour with the Colour picker or type its hex code.
  2. Move the Opacity slider (0–100%) if you need transparency.
  3. Read the Colour codes table and copy the format you need.
  4. Copy the Snippets for CSS rules, a CSS custom property and inline HTML styles.

What it does and when to use it

Design files give you a hex code. CSS, SVG, email templates and canvas code may need a different notation, and transparency always needs one of the alpha formats. This tool converts one colour into all of them at once:

Format Example for #1e40af at 75%
HEX #1e40af
HEX + alpha #1e40afbf
RGB / RGBA rgb(30, 64, 175) / rgba(30, 64, 175, 0.75)
HSL / HSLA hsl(226, 71%, 40%) / hsla(226, 71%, 40%, 0.75)
Modern CSS rgb(30 64 175 / 75%)

The swatches show the solid colour and, when opacity is below 100%, the transparent version. For picking colours from an image or building a palette, use the Color Picker.

How it works

The hex code is split into red, green and blue values from 0 to 255; a 3-digit code such as #fff is first expanded to #ffffff. HSL is calculated from those values: lightness is the average of the largest and smallest channel, saturation depends on the gap between them, and the hue is the angle on the colour wheel. The opacity percentage becomes a decimal (75% → 0.75) for RGBA and HSLA, and a 0–255 value written as two hex digits for 8-digit HEX. The calculation runs in your browser.

Worked examples

A blue at 75% opacity. #1e40af gives rgb(30, 64, 175), hsl(226, 71%, 40%) and rgba(30, 64, 175, 0.75). Because the opacity is below 100%, the snippets use the RGBA value and keep the solid hex for the border:

.badge { background-color: rgba(30, 64, 175, 0.75); border: 1px solid #1e40af; }

Short hex. #fff is read as #ffffff: rgb(255, 255, 255) and hsl(0, 0%, 100%). Greys always have a saturation of 0%.

A colour name. Typing blue returns “Enter a hex colour such as #34d399.”

Limits and tips

  • Transparency mixes with whatever is behind the element, so the colour you see depends on the background.
  • Check that text colours have enough contrast with their background before you publish.
  • To put a colour into a styled button, the HTML Button Generator takes an accent colour. To write characters such as © in HTML, see the HTML Character Entity Finder.

Frequently asked questions

Which format should I use in CSS?
They all describe the same colour, so use whichever your team reads most easily. HEX is the most common in design files. HSL is easier to adjust by hand, because you can change lightness without touching the hue. For transparency, use RGBA, HSLA, 8-digit HEX or the modern rgb() form with a slash.
What do the last two digits of an 8-digit HEX code mean?
They are the opacity, from 00 (fully transparent) to ff (fully opaque). 75% opacity is 0.75 × 255 = 191.25, which rounds to 191, or bf in hexadecimal, so #1e40af at 75% is #1e40afbf.
Can I type a colour name such as blue?
No. The tool reads hex codes only, either 3 or 6 digits, with or without the #. A colour name returns a message asking for a hex colour. Most colour pickers and design tools show the hex code you need.
Why do the HSL values look rounded?
The hue is rounded to a whole degree and saturation and lightness to whole percentages, which is how most people write HSL. Converting the rounded HSL back can be off by one RGB step.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close