Format Code Now
/
Web & markupCSS Background Color Generator Next: CSS Background Image Generator ›

CSS Background Color Generator

WM-106

Choose a color and an opacity and copy a ready background-color rule in hex, RGB or HSL. The preview sits on a checkerboard so transparency is easy to see.

Runs in your browser. Nothing is uploaded.

Color

#3b82f6
%

Preview and CSS

background-color#3b82f6
Hex#3b82f6
RGBrgb(59, 130, 246)
HSLhsl(217, 91%, 60%)
Most readable text colorBlack, contrast 5.71:1

CSS

.box {
  background-color: #3b82f6;
}

How to use it

  1. Click the color box and pick a color, or type a six-digit hex value.
  2. Set the opacity. Anything below 100 percent writes an alpha value.
  3. Choose whether the CSS is written as hex, RGB or HSL.
  4. Press Copy for the rule, or take any one value from the results table.

Hex, RGB and HSL for the same color

All three notations describe the same color, so use the one your project already uses. Hex is the shortest, RGB shows the red, green and blue amounts from 0 to 255, and HSL describes hue, saturation and lightness, which makes it easier to make a color lighter or darker by hand. The results table lists all three so you can copy whichever you need.

Opacity and readable text

With less than 100 percent opacity the color is written as eight-digit hex, rgba() or hsla(), where the last part is the alpha. The text color row compares white and black against the opaque color using the WCAG contrast ratio and names the better one. It is a quick guide for a solid background, not a full accessibility check.

Questions people ask

How do I make a CSS background color transparent?

Lower the opacity here. The tool writes rgba(), hsla() or eight-digit hex with an alpha value, which makes only the background transparent. Text inside the element stays fully opaque, unlike the opacity property.

What is eight-digit hex?

It is six-digit hex plus two more digits for alpha, from 00 for fully transparent to ff for fully opaque. For example, 50 percent opacity on a color ends in 80 here. Current browsers support it.

Why is my HSL slightly different from the original color?

HSL is rounded to whole degrees and whole percents, so converting it back to hex can land on a nearby color. Use the hex or RGB line when you need the exact original value.

What does the contrast number mean?

It is the WCAG contrast ratio between your color and white or black text. A ratio of 4.5 to 1 is the usual minimum for normal body text, and 21 to 1 is the maximum, black on white.

Can I use a named color like red?

The color picker works with hex values, so pick or type the hex for the color you want. The output is always hex, RGB or HSL rather than a color name.

About this tool

Writes one background-color declaration. Fully opaque colors are written as six-digit hex, rgb() or hsl(); with less than 100 percent opacity they become eight-digit hex, rgba() or hsla(). HSL is rounded to whole degrees and percents, so converting it back can differ from the original color by a small amount. The text color row picks white or black by WCAG contrast ratio against the opaque color; it is a quick guide, not an accessibility audit. The preview sits on a checkerboard so you can see transparency.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.