Formulas and sources
Each formula this calculator uses, where it comes from, and what it leaves out. "How it works" shows the same formula with your own numbers.
HEX and RGB
Every mode
Each pair of hex digits in #RRGGBB is a base-16 number from 00 to FF, which is 0 to 255 for red, green and blue. A three-digit code such as #FB0 is read as #FFBB00. HEX and RGB write the same sRGB color two ways, so they convert exactly. A code with an alpha pair (4 or 8 digits) keeps it: the pair is the opacity, 00 to FF, and it fills the Opacity field. A CSS color name reads as its HEX from the named-color table.
Source: Uses the notation in CSS Color Module Level 3, a W3C Recommendation [1], which specifies every RGB color in the sRGB color space of IEC 61966-2-1 [4].
RGB to HSL
Every mode
- R
- red, as 0 to 1 (0 to 255 divided by 255)
- G
- green, as 0 to 1
- B
- blue, as 0 to 1
- H
- hue, in degrees; 360° is added to a negative hue
- S
- saturation, shown as a percentage
- L
- lightness, shown as a percentage
- d
- max - min, the spread of R, G and B
max and min are the largest and smallest of R, G and B; min(L, 1 - L) is the smaller of L and 1 - L. A gray (d = 0) shows H and S as 0. H, S and L are rounded to whole numbers, and a hue can round to 360°, the same color as 0°.
Source: Uses the RGB-to-HSL conversion in CSS Color Module Level 4 [2], a Candidate Recommendation Draft, rounded to whole numbers. HSL typed in Advanced mode goes back to RGB by the conversion in CSS Color Module Level 3 [1].
RGB to CMYK
Every mode
- R
- red, as 0 to 1
- G
- green, as 0 to 1
- B
- blue, as 0 to 1
- C
- cyan
- M
- magenta
- Y
- yellow
- K
- black (key)
Each is shown as a whole percentage, and black (K = 1) shows C, M and Y as 0. A color that is all but black, such as rgb(0, 0, 1), shows K as 100% (it is 99.6%) and C, M and Y as shares of the trace left: 100%, 100% and 0%. It does not know the inks, the paper or a printer's profile, so a printed color can look quite different from the screen.
Source: Uses the naive conversion in CSS Color Module Level 5 [3], a Working Draft, which calls it necessarily approximate. Its own pair, rgb(178 34 34) and cmyk 0%, 81%, 81%, 30%, matches here.
CMYK to RGB
Every mode
- C
- cyan, as 0 to 1 (a percentage ÷ 100)
- M
- magenta, as 0 to 1
- Y
- yellow, as 0 to 1
- K
- black (key), as 0 to 1
- R
- red, 0 to 255
- G
- green, 0 to 255
- B
- blue, 0 to 255
For CMYK typed in Advanced mode or pasted into the HEX field. Each level is rounded to a whole number. A CMYK at whole percentages is itself rounded, so going back can land one away: the draft's firebrick, device-cmyk(0 81% 81% 30%), is red 178.5 before rounding, shown as 179. A CMYK whose C, M and Y all carry ink reads back from RGB with that shared gray in K, and the page says so.
Source: Uses the naive conversion from CMYK in CSS Color Module Level 5 [3], section 6.1, red = 1 − min(1, cyan × (1 − black) + black), which is (1 − C) × (1 − K) for values from 0 to 1. Re-read 2026-11-15.
Contrast ratio (WCAG 2.2)
Every mode
- R
- red, as 0 to 1 with the sRGB curve taken off: c ÷ 12.92 at or below 0.04045, else ((c + 0.055) ÷ 1.055)^2.4
- G
- green, the same way
- B
- blue, the same way
- Lum
- relative luminance, 0 for black to 1 for white
- L1
- the lighter color's Lum
- L2
- the darker color's Lum
Text needs 4.5:1 (AA) or 7:1 (AAA); large text, 18 pt or 14 pt bold, 3:1 or 4.5:1; interface parts and graphics 3:1 against what is beside them. The ratio is cut to two places, never rounded up: 4.499:1 does not meet 4.5:1.
Source: WCAG 2.2, Understanding Success Criterion 1.4.3, with 1.4.6 and 1.4.11 [5]. The page's own text color on the swatch is chosen with the same ratio.
Transparency
Every mode
- Over
- the solid color it makes, each of red, green and blue
- Color
- the color’s level, 0 to 255
- Back
- the background’s level: white, black or the second color
- α
- the opacity, 0 to 1
Rounded to a whole level. #0EA5E9 at 50% is #87D2F4 over white and #075375 over black. The opacity is written as the last HEX pair (0.5 is 80) and as a fourth value in rgba() and hsla(), to three places, so every pair reads back as itself. Contrast with a translucent color is the contrast of what it makes over the background.
Source: Simple alpha compositing over an opaque backdrop, from Compositing and Blending Level 1 [10].
Make it pass
Every mode
Under a pair that misses AA text, AA large or, for the pair typed, AAA, the color is taken to OKLCH. Its lightness is moved in steps of 0.001, darker and lighter, keeping the hue and chroma, until the ratio meets the threshold as the page shows it, cut to two places. The nearer of the two wins. A step outside sRGB is clipped, channel by channel.
Source: The page's own search, with WCAG 2.2's thresholds [5] and CSS Color Module Level 4's OKLCH [6].
Tints and shades
Every mode
- V
- each of red, green and blue, 0 to 255
- p
- the share of white or black, 10% to 90%
Mixed in sRGB, each channel on its own, rounded to a whole number: the common meaning of tint and shade.
Source: Standard arithmetic; no single publisher.
A 50–950 scale
Every mode
- Family lightness
- the OKLCH lightness of Tailwind’s nearest family at that step (its chroma likewise)
- Offset
- this color’s lightness minus the family’s at the step it becomes
- Weight
- 1 at this color’s step, falling to 0 at 50 and at 950
- Ratio
- this color’s chroma over the family’s at its step
The family is the one of Tailwind CSS’s 26 nearest in hue (for a muted color under chroma 0.05, nearest in hue and chroma, so a gray can take a gray family), and this color becomes its step nearest in lightness, unchanged. Each other step keeps the family’s hue turn from step to step. A step past sRGB has its chroma lowered, its lightness and hue kept. Written as Tailwind writes its palette.
Source: The palette of Tailwind CSS v4.3.3 (MIT licence) [11]; the steps are drawn in OkLCh from CSS Color Module Level 4 [6]. The method is this page’s own.
Harmonies
Every mode
- H
- the hue on the HSL color wheel, in degrees
- H'
- the harmony color's hue; saturation and lightness kept
- turn
- complementary 180°; analogous −30° and 30°; triadic 120° and 240°; split-complementary 150° and 210°
On the HSL wheel CSS uses. A painter's red-yellow-blue wheel puts the complements elsewhere.
Source: The HSL wheel of CSS Color Module Level 3 [1]; the turns are a standard convention with no single publisher.
OKLCH, HWB and the nearest CSS name
Every mode
Oklab: linear sRGB to three cone responses by a matrix, their cube roots, then a second matrix to L, a and b; OKLCH is L with chroma C = √(a² + b²) and hue h = atan2(b, a). Checked against the specification's own figures: sRGB blue is oklch(0.452 0.313 264.1). The page writes lightness to 2 places of a percent, chroma to 5 and hue to 2, so its own code reads back as the same HEX. HWB is the hue, whiteness = the smallest of R, G and B, and blackness = 1 minus the largest. Typed or pasted, oklch() goes back by the same matrices, its lightness 0 to 1 or 0% to 100% and a chroma percentage of 0.4; a color outside sRGB is clipped channel by channel. hwb() goes back as the pure hue scaled by 1 − W − B, plus W, and a gray when W + B is 100% or more. The nearest CSS name is the closest of the 148 named colors by straight-line distance in Oklab.
Source: CSS Color Module Level 4: section 8.1 for HWB to sRGB, section 9 for Oklab and OkLCh, section 6.1 for the named colors [6]. Browser support for the oklch and hwb functions from MDN [9].
Blend: the colors between two
Blend mode
- Start
- the start color, in the chosen space
- End
- the end color, in the chosen space
- i
- the step, 0 to n − 1; both ends exact
- n
- how many colors, 3 to 12
Worked on Oklab's L, a and b; on OKLCH's lightness and chroma with the hue the shorter way round (a gray takes the other color's hue); or on the sRGB channels. A step outside sRGB is clipped to it. The CSS is a solid color, the path as nine plain stops (every browser since Chrome 26, Firefox 16 and Safari 7), then the same gradient "in oklab" or "in oklch" (Chrome 111, Firefox 127, Safari 16.2 and later).
Source: CSS Color Module Level 4, section 13.3: Oklab for colors evenly spaced, and HEX colors otherwise blended in sRGB [6]; CSS Images Module Level 4, section 3.1 [7]; browser versions from MDN [9].
Color vision simulation
Every mode
- T
- the authors' 3 × 3 matrix for protanopia, deuteranopia or tritanopia at severity 1.0
Applied to linear RGB, with the sRGB curve taken off first and put back after, each channel clipped to 0 to 1. Full-strength dichromacy only: an approximation, not a diagnosis.
Source: Machado, Oliveira and Fernandes (2009), Table 1 on the authors' page [8].
Sources
- World Wide Web Consortium (W3C). CSS Color Module Level 3, sections 4.2.1, RGB color values, and 4.2.4, HSL color values. W3C Recommendation, January 18, 2022.Our automated tests check this calculator against 4 cases from it.
- World Wide Web Consortium (W3C). CSS Color Module Level 4, section 7.2, Converting sRGB Colors to HSL. Candidate Recommendation Draft, November 12, 2026; a draft that may change.Our automated tests check this calculator against 1 case from it.
- World Wide Web Consortium (W3C). CSS Color Module Level 5, section 6.1, Naively Converting Between Uncalibrated CMYK and sRGB-Based Color. Working Draft, November 14, 2026; a draft that may change.Our automated tests check this calculator against 2 cases from it.
- International Electrotechnical Commission (IEC). IEC 61966-2-1:1999, Multimedia systems and equipment, Colour measurement and management, Part 2-1: Colour management, Default RGB colour space, sRGB. Edition 1.0, October 18, 1999.
- World Wide Web Consortium (W3C). Understanding Success Criterion 1.4.3: Contrast (Minimum), the success criterion, its notes on large-scale text and on rounding; with 1.4.6 and 1.4.11. Understanding WCAG 2.2, read November 15, 2026.
- World Wide Web Consortium (W3C). CSS Color Module Level 4, section 9, Oklab and OkLCh; section 13.3, Color Space for Interpolation; section 6.1, Named Colors. Candidate Recommendation Draft, November 12, 2026; a draft that may change.
- World Wide Web Consortium (W3C). CSS Images Module Level 4, section 3.1, Linear Gradients, and its color-interpolation method. Working Draft, September 30, 2025; a draft that may change.
- Machado GM, Oliveira MM, Fernandes LAF. A Physiologically-based Model for Simulation of Color Vision Deficiency, Table 1 on the authors' page, severity 1.0. IEEE Transactions on Visualization and Computer Graphics, 2009; 15(6): 1291-1298.
- MDN Web Docs. linear-gradient: browser compatibility, the compatibility table, with those of the oklch and hwb color functions. Read November 15, 2026.
- World Wide Web Consortium (W3C). Compositing and Blending Level 1, section 5.1, Simple alpha compositing. Candidate Recommendation Draft, March 21, 2024; a draft that may change.
- Tailwind Labs. Tailwind CSS: Colors, the default color palette reference, 26 families of 11 steps in OKLCH. Tailwind CSS v4.3.3; read November 18, 2026.
What this calculator does not cover
- It converts one sRGB color between HEX, RGB, HSL and CMYK. The CMYK value is a simple formula, not a printer's profile.
- A red, green, blue, hue, saturation or lightness typed with a decimal, such as 197.4, is rounded to a whole number before it is converted.
- RAL and Pantone are named paint and ink colors, matched by their own licensed charts rather than worked out from RGB, so it does not convert to them.
- It reads CSS color names, hwb() and oklch(), but not wide-gamut colors such as Display P3; an oklch() outside sRGB is clipped to fit.
- Opacity is kept in the codes that can carry it. CMYK, the tints, harmonies, color vision and the nearest name are the color at full strength, and Blend takes both its colors solid.
- Contrast is WCAG 2.2's ratio of two colors: it does not know the font size, weight or anti-aliasing of the text, and it is not APCA.
- Make it pass moves the lightness of your color only; a different background, a larger or bolder text, or another hue are fixes it does not weigh.
- Gradients are linear or radial, between two colors; a color in the list that falls outside sRGB is clipped, where a browser maps it more carefully.
- Color vision is simulated at full strength only, for the three dichromacies; the milder forms are not shown.
- For layout dimensions and image sizing, see the Aspect Ratio Calculator.
Sources checked on
How we choose sources and test the calculators: How CalcTrail calculates