CSS Background Color Generator

Convert RGB, RGBA, HSL, and HSLA values into a ready-to-use CSS background-color declaration, complete with a live transparency preview. Or paste an existing HEX, RGB, HSL, or background-color declaration to break it back down into every equivalent format.

Generated CSS and normalized color values will appear here.

What does the CSS background-color property do?

The background-color property sets the solid or semi-transparent color that fills an element behind its content. It accepts several CSS color formats - HEX, RGB, RGBA, HSL, and HSLA and this generator converts between all of them so you can go from a color picker's RGB values, or a designer's HSL spec, straight to a declaration you can paste into a stylesheet.

Use the Values to CSS tab to build a color from scratch by entering RGB or HSL channels. Use CSS to Values when you already have a color, a HEX code, an rgba() string, or a full background-color: ...; line and want to see its RGB, HSL, and HEX equivalents at a glance.

RGB vs. HSL vs. HEX: which format should you use?

HEX (#0F172A) is the most compact way to write an opaque color and is what most design tools export by default, but it's hard to edit by eye. RGB (rgb(15, 23, 42)) maps directly onto how screens mix red, green, and blue light, which makes it a natural fit when you're matching a color from an image or a brand palette. HSL (hsl(222 47% 11%)) separates hue, saturation, and lightness, so nudging the lightness value alone gives you a consistent tint or shade. This is useful for building hover states or a color scale from one base color.

None of the three formats support transparency on their own. To add an alpha channel, use RGBA or HSLA instead, or the newer space-separated syntax with a slash, such as hsl(222 47% 11% / 0.5).

How transparency and alpha affect a background color

A panel set to RGB 15, 23, 42 with alpha 0.5 will look lighter over a white page than over a dark one, because alpha controls how much of the surface underneath shows through. It does not lighten the color itself. Changing alpha and changing the RGB or HSL channels are two different adjustments, and it's easy to conflate them when a color looks "off."

Use an opaque background (HEX or fully opaque RGB/HSL) when an element should look identical no matter what's behind it. A solid card or a button, for example. Use RGBA or HSLA when you want the page background, an image, or content behind the element to blend into the result, such as a translucent overlay or a frosted header bar.

Apply the generated background-color directly to the element that needs it. Setting opacity on the whole element instead will also fade its text and children, which is a common cause of washed-out buttons and low-contrast labels.

When comparing colors side by side, change one variable at a time: hold alpha fixed while comparing tints, or hold the RGB/HSL channels fixed while comparing transparency levels. Adjusting both at once makes it hard to tell which change actually improved the result.

Reading the generated CSS output

The result starts with a ready-to-use background-color declaration, followed by the same color written as HEX, RGB, RGBA, HSL, and HSLA. Copy just the declaration line into your stylesheet, or copy the full block as a quick reference for design notes. A six-digit HEX code always describes the opaque base color; once alpha drops below 1, the declaration switches to RGBA so the transparency isn't lost.

InputAccepted range
Red, green, blue0 to 255, including decimals
HueDegrees; negative angles wrap around the color wheel
Saturation and lightness0 to 100%
Alpha0 to 1

RGB output keeps up to six decimal places, HSL rounds to one, and alpha keeps three. HEX always rounds to whole 8-bit channels, which is why converting a fractional RGB value through HEX and back can shift it slightly. The CSS to Values tab reads HEX, RGB(A), HSL(A), and full background-color declarations; named colors (like rebeccapurple) and gradients aren't parsed.

For example, RGB 15, 23, 42 with alpha 0.92 produces background-color: rgba(15, 23, 42, 0.92);. How it actually renders and whether text on top stays readable still depends on what's showing through underneath.

Common questions about CSS background colors

What's the difference between RGB and RGBA?
RGBA is RGB with a fourth alpha channel added. rgb(15, 23, 42) is fully opaque; rgba(15, 23, 42, 0.5)is the same color at 50% opacity, letting whatever is behind the element show through.
How do I convert HEX to RGBA?
Paste the HEX code into the CSS to Values tab, then adjust alpha as needed and switch back to Values to CSS or paste a full background-color declaration if you already have alpha in mind. HEX itself has no alpha channel, so an 8-digit HEX (with two extra characters) or a manual RGBA value is required for transparency.
Why does my transparent background look different on two pages?
Because RGBA and HSLA colors blend with whatever sits behind them. The same alpha value produces a different final appearance over a light background than over a dark one. This is expected, not a bug in the color value.
Does background-color affect text contrast?
Yes. Lowering alpha lets more of the underlying page show through, which can reduce contrast between the background and any text on top. Check contrast against the actual rendered result, not just the RGB or HSL values in isolation.
Should I use HSL instead of RGB for CSS colors?
Both of these work as browsers render them identically. HSL tends to be easier to reason about when you want to adjust one property (like making a color slightly darker) without recalculating all three RGB channels by hand.

Related Tools