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.
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.
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).
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.
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.
| Input | Accepted range |
|---|---|
| Red, green, blue | 0 to 255, including decimals |
| Hue | Degrees; negative angles wrap around the color wheel |
| Saturation and lightness | 0 to 100% |
| Alpha | 0 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.
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.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.Related Tools
Build and preview common CSS Grid layout patterns.
Build linear and radial gradients with custom color stops.
Remove, replace, and export image metadata.
Generate gradient and image background-image CSS.
Generate uniform or side-specific CSS border declarations.
Generate uniform, corner, and elliptical border-radius CSS.