Color

HEX to RGB: color codes, alpha precision and saved swatches

·

Enter a HEX color and read its RGB channels immediately. ToolMellow also accepts supported RGB, HSL and named colors, preserves decimal alpha, and provides six formats for copying.

This guide explains shorthand HEX, transparency, normalized values and export files. It also shows how invalid input, saved swatches, the visual chooser and an available screen picker affect the current color.

HEX to RGB

Convert a color and check the output you need

Paste a code into the HEX field, with or without its leading #. For example, #0C2238 produces rgb(12, 34, 56). The default color is #7D9065, whose RGB value is rgb(125, 144, 101).

Use the separate RGB or HSL field for a supported CSS color expression or a name such as rebeccapurple. Adjust the RGB, Alpha or HSL controls when you want to edit individual channels, then copy the output format required by your destination.

Manual changes update the current color without automatically saving a swatch. Select Save swatch to keep a useful value in this page. HEX to RGB has no image-upload or image-pixel sampler; use Color Picker for those image workflows.

CSS Color Level 4: hexadecimal sRGB notationRapidTables: HEX to RGB conversion reference

Understand the accepted HEX and CSS input forms

HEX accepts 3, 4, 6 or 8 hexadecimal digits, optionally preceded by #. Shorthand duplicates each digit: #0f0 becomes #00FF00, while #0f08 becomes #00FF0088. The last component of a four- or eight-digit code is alpha.

The HEX field allows up to 9 UTF-16 code units, including #. The separate CSS field allows up to 200. It supports the numeric forms below, 148 CSS named colors and transparent; it does not evaluate the complete CSS color language.

Understand the accepted HEX and CSS input forms
InputExample or ruleMeaning or boundary
3-digit HEX#0f0 or 0f0Opaque RGB shorthand
4-digit HEX#0f08RGB and alpha shorthand
6-digit HEX#0C2238Three 8-bit RGB channels
8-digit HEX#0C223880RGB followed by 8-bit alpha
CSS named colorrebeccapurple148 names; case-insensitive
TransparenttransparentBlack with zero alpha
Numeric RGB or HSLComma forms or space/slash formsIncludes supported rgba/hsla syntax
Other CSS expressionscurrentcolor, var(), calc(), lab(), display-p3Not evaluated here

CSS Color Level 4: hexadecimal sRGB notation

Keep decimal alpha distinct from HEX alpha

Alpha ranges from 0, fully transparent, to 1, fully opaque. Decimal alpha entered in supported RGB/HSL forms or the Alpha control is retained in RGB and HSL output. HEX stores alpha in one byte, so the tool rounds alpha × 255 to the nearest integer.

For rgba(12, 34, 56, 0.5), HEX is #0C223880. Its hexadecimal 80 byte represents 128/255, approximately 0.501961, rather than exactly 0.5. Converting that HEX back cannot recover the original decimal. The preview composites the current color on white, so its visible appearance also depends on alpha.

CSS Color Level 4: hexadecimal sRGB notation

Copy one of six color formats

Each output has its own Copy button. RGB uses integer channels and decimal alpha when needed; HSL expresses the same stored color as hue, saturation and lightness. RGB percent and Normalized RGBA provide different numeric representations of the sRGB channels.

Normalized RGBA divides RGB channels by 255 and rounds the displayed numbers; it is not a conversion to linear-light RGB. CSS variable produces a custom-property declaration. That output option does not add support for entering var(--color) as a color.

Copy one of six color formats
FormatExample at decimal alpha 0.5Use
HEX#0C223880Compact code with quantized alpha
RGBrgba(12, 34, 56, 0.5)Integer channels and decimal alpha
HSLHue, saturation, lightness and alphaHSL-based editing or CSS
RGB percentrgb(4.706% 13.333% 21.961% / 50%)Percentage-channel CSS
Normalized RGBA0.0471, 0.1333, 0.2196, 0.5Numeric channels on a 0–1 scale
CSS variable--color: rgba(12, 34, 56, 0.5);Custom-property declaration

CSS Color Level 4: numeric sRGB color syntax

Work through HEX to RGB conversion examples

For six-digit HEX, split the code into RR, GG and BB pairs. Each pair is a base-16 number between 00 and FF, corresponding to decimal 0 through 255. For example, 0C is 12, 22 is 34 and 38 is 56.

Expand shorthand before reading the pairs. An alpha byte is divided by 255; the Alpha number field may show a rounded decimal even though the stored value retains the byte fraction. An explicitly entered opaque eight-digit code such as #FFFFFFFF can remain eight digits in the HEX output.

Work through HEX to RGB conversion examples
HEX inputRGB channelsAlpha or result
#0000, 0, 0Opaque black
fff255, 255, 255Opaque white
#abc170, 187, 204Expands to #AABBCC
#00080, 0, 0136/255 alpha; #00000088
#12AB34CD18, 171, 52205/255 alpha
#FFFFFFFF255, 255, 255Alpha 1; eight-digit form can remain

RapidTables: HEX to RGB conversion reference

Read display precision without losing the stored alpha

The Alpha number control displays up to six decimal places. HSL channels and RGB percentage output use up to three decimal places; Normalized RGBA uses up to four. These display limits serve different outputs and should not be treated as one universal precision setting.

RGB and HSL output retain the stored decimal alpha, including fractions obtained from an alpha byte. HEX quantizes it to 8 bits. If exact decimal alpha matters to your next step, copy an appropriate decimal representation or keep the swatch JSON rather than relying on a HEX round trip.

Edit RGB, HSL and the visual chooser

RGB channels use integers from 0 to 255. Supported RGB percentage input is converted to integer channels: rgb(50% 0% 100%) becomes #8000FF. Out-of-range values are rejected instead of being clamped as a full CSS engine might do.

In HSL text, saturation and lightness require percent signs. Supported finite hue angles can use degrees, grad, rad or turn units and are normalized; hsl(0.5turn 100% 50% / 25%) gives cyan at alpha 0.25. The separate HSL controls use their labeled numeric units. Choosing a color visually changes RGB while preserving the current alpha.

CSS Color Level 4: numeric sRGB color syntax

Recover from invalid input without copying an old result

Incomplete or unsupported input shows an error while keeping the last valid preview. Copy buttons and Save swatch are disabled during that invalid state. The visible old preview is therefore a reference to the last valid color, not confirmation that the new text was accepted.

Complete or correct the input, or select a saved swatch to restore a valid color. Expressions such as currentcolor, CSS variables, relative colors and wide-gamut functions are outside this parser. A CSS value that works in a browser stylesheet is not necessarily supported in this field.

Save up to 24 swatches in the current page

Select Save swatch after a valid manual edit. The newest saved color appears first, and the list keeps at most 24 entries. Saving an identical serialized RGB/RGBA color does not create a second copy.

Select a saved swatch to make it current again, including its stored alpha. The list is page memory: it is not a persistent account library and does not survive a reload. Copy or download colors you want to retain outside this page.

Download saved colors as JSON or CSS

The swatch JSON download is named toolmellow-swatches.json. Each item includes r, g, b, a and hex, so decimal alpha and the corresponding quantized HEX code are both available.

The CSS download is toolmellow-swatches.css. It creates a :root block with numbered custom properties such as --swatch-1 using RGB or RGBA values. The export contains the saved swatch list; a current color that you have not saved is not automatically added.

Recognize swatches that share HEX but differ in alpha

Two decimal alpha values can round to the same HEX alpha byte. For example, rgba(12, 34, 56, 0.5) and rgba(12, 34, 56, 0.50001) both have HEX #0C223880, while their stored decimal alpha values differ.

The saved swatch list can retain both because it distinguishes their RGB/RGBA serializations. Read the decimal value or the a property in the JSON when the HEX labels look identical. Matching HEX labels alone do not establish identical stored alpha.

Use the screen picker when the browser exposes it

Pick from screen appears when the browser exposes the EyeDropper API. The API requires a secure context and a user action, and browser support varies. A successful selection supplies an opaque sRGB HEX color and automatically remembers it as a swatch; it does not recover an underlying element’s alpha.

Cancelling the picker leaves the current color without a failure notice. A startup failure on HEX to RGB directs you to the manual color inputs. If the button is missing or the picker cannot start, use those inputs or the visual chooser. This converter does not provide a local image sampler.

EyeDropper API: screen color selection requirements

Know what each action retains or resets

The current color, saved list and invalid-input state have different scopes. Clearing saved swatches removes the list while retaining the current color. Reloading starts the workspace again at its default color with no saved swatches.

Copied values and downloaded files exist outside that page state. Keep those outputs before reloading or leaving the page if you need them later. Restarting a pending screen selection aborts the earlier selection; leaving the tool cancels its pending picker work.

Know what each action retains or resets
ActionChanged or clearedRetained
Valid manual editCurrent color and format outputsSaved swatch list
Invalid inputError; copy/save disabledLast valid preview and saved list
Choose visuallyRGB channelsCurrent alpha and saved list
Save swatchSaved list, newest firstCurrent color
Select a saved swatchCurrent color restoredSaved list
Clear swatchesSaved listCurrent color
Reload pageWorkspace reset to #7D9065; list emptiedValues already copied or downloaded outside the page

Understand local conversion and common copy problems

Color parsing, conversion and swatch creation run in the page. Entered color values do not require a conversion upload. Loading the website and its assets can still use the network, and local processing does not guarantee that a first visit works offline.

Clipboard access can be denied by the browser or its context. If copying fails, select the displayed value and copy it manually. Color appearance also depends on the display and surrounding background; a code conversion is not a calibrated display or print proof.

Choose a format and verify the result before reuse

Start with the representation you actually have: a HEX code, a supported numeric CSS value or a CSS name. For a quick opaque conversion, compare the RGB channel values with the HEX pairs. For transparency, also check whether your destination needs byte alpha or decimal alpha.

Converter references help explain the notation, while this page’s controls determine the supported workflow. Use Color Picker for local image pixels, Contrast Checker for text/background contrast and CSS Gradient Generator when you need a gradient rather than a single converted color.

  • Enter the supported value and resolve any error before copying.
  • Check RGB channels and alpha separately.
  • Choose HEX, RGB, HSL, percentage, normalized or CSS-variable output for the destination.
  • Keep a decimal representation when HEX alpha rounding would matter.
  • Save useful colors, then download the swatch JSON or CSS if you need to retain them.
  • Check the pasted result in its actual background and application.

HTML Color Codes: HEX to RGB converter terminologyCSS Color Level 4: hexadecimal sRGB notation

Frequently asked questions

What do three, four, six and eight HEX digits mean?

Three digits expand to six RGB digits. Four expand to eight digits with alpha last. Six digits encode opaque RGB; eight include one alpha byte after RGB. The leading # is optional in the HEX field.

Why does HEX alpha differ from decimal alpha?

HEX alpha has 256 byte values, while supported RGB/HSL output retains decimal alpha. Alpha 0.5 rounds to hexadecimal byte 80, which represents 128/255 rather than exactly 0.5. Keep decimal output or JSON when that distinction matters.

Can I enter RGB, HSL or a CSS color name?

Yes. Use the separate RGB or HSL field for supported comma or space/slash numeric forms, 148 CSS named colors or transparent. HSL text requires percent signs for saturation and lightness. The parser does not evaluate every CSS color expression.

Why does invalid input keep the last valid preview?

The preview keeps the last valid color while an error identifies the invalid new input. Copy and Save swatch are disabled until you correct the input or restore a saved swatch.

How precise are normalized RGBA and percentage outputs?

Normalized RGBA displays up to four decimals; RGB percentage and HSL channel output use up to three. The Alpha number control displays up to six decimals. RGB/HSL output retains stored decimal alpha; HEX rounds alpha to one byte.

Does the visual color chooser preserve alpha?

Yes. The visual chooser changes RGB while keeping the current alpha. A screen-picker result is different: the EyeDropper API supplies an opaque sRGB HEX value.

Do saved swatches survive a reload?

No. Saved swatches are held in the current page and reload resets them. Download toolmellow-swatches.json or toolmellow-swatches.css, or copy the values before leaving.

Can I sample an image on HEX to RGB?

No. HEX to RGB does not include image upload or pixel sampling. Use Color Picker for a local image, then bring its supported color value here if needed.

Why is screen color sampling unavailable?

The button depends on browser EyeDropper support; the API requires a secure context and a user action. If unavailable or unable to start, use the manual inputs or visual chooser. Cancelling does not show a failure notice.

Why can an opaque HEX value still have eight digits?

An explicitly entered eight-digit code can retain its FF alpha byte even though the color is fully opaque. For example, #FFFFFFFF represents white with alpha 1; opaque output is not guaranteed to use only six digits.

Can I enter a CSS variable or a wide-gamut color?

No. The CSS-variable output creates a declaration but does not resolve var() input. Functions such as color(display-p3 ...), lab(), relative colors and other unsupported expressions are not evaluated here.

Why do two saved swatches have the same HEX label?

Different decimal alpha values may round to the same byte. Alpha 0.5 and 0.50001 can both produce #0C223880 for RGB 12, 34, 56, while the swatch JSON retains their different a values.

What is included in the download?

JSON contains the saved list with r, g, b, a and hex. CSS contains numbered --swatch-N custom properties in a :root block. Save the current color first if it should be included.

Does clearing saved swatches reset the current color?

No. Clear swatches removes only the saved list. The current color remains available. Reloading the page resets both the workspace and the list.

Sources and references

Put it into practice.

Related guides