Colors are everywhere on the web — and every single one of them is defined using a color code in HTML and CSS. Whether you're looking for a specific hex code, trying to understand the difference between RGB and HSL, or building a complete color palette for a project — this is the only guide you need. Everything is here.
Copy any color code from this guide and paste it directly into our free HTML Editor Online Pro to see it render live. Test colors on your own HTML in real time — no setup needed.
There is not just one way to write colors in HTML and CSS — there are five. Each format has its own strengths. Developers use different formats depending on what they need. Here is every format explained clearly:
You can use any of these formats anywhere CSS accepts a color value — color, background-color, border-color, box-shadow, outline, and even inside linear-gradient(). All five formats are fully supported in every modern browser.
HEX color codes are the most widely used color format in web design. You've seen them everywhere — #ff0000, #3b82f6, #ffffff. But what do these characters actually mean?
A HEX color code is a 6-character string preceded by a # symbol. The six characters are split into three pairs — each pair represents one color channel:
Each pair is a hexadecimal number from 00 to FF. In decimal, that's 0 to 255. So #ff0000 means Red=255, Green=0, Blue=0 — which is pure red. And #00ff00 is pure green. And #0000ff is pure blue.
These are the colors you'll reach for most often in real projects. Not just primary colors — these are the refined, professional shades that actual designers use.
RGB is the color model that screens use to display color — every pixel on your monitor is made up of tiny red, green, and blue lights. RGB in CSS lets you specify each channel from 0 to 255.
RGBA adds a fourth value — Alpha — which controls opacity. The alpha value goes from 0 (completely transparent / invisible) to 1 (completely opaque / solid). This makes RGBA incredibly useful for overlays, shadows, semi-transparent backgrounds, and glassmorphism effects.
Modern CSS tip: In CSS Color Level 4 (supported in all modern browsers), you can write RGBA as just rgb(255 99 71 / 50%) — using spaces instead of commas, and a slash before the alpha value. Both formats work. The old comma syntax is still perfectly valid too.
HSL stands for Hue, Saturation, Lightness. Many experienced designers prefer HSL over HEX or RGB because it is much more intuitive — you can look at an HSL value and actually understand what color it will be, without running it through a color picker first.
The real power of HSL shines when you're building a design system or a consistent color palette. You can take one hue value — say 220 — and create an entire range of shades just by adjusting the lightness. This is exactly how popular CSS frameworks like Tailwind CSS and design systems like Material Design are built.
HTML and CSS support 140 built-in named colors. You can use these names directly in your code instead of memorizing a HEX code. They're real words — tomato, coral, dodgerblue, mediumseagreen. They're especially handy for quick prototyping and learning.
| Swatch | Name | HEX | RGB |
|---|---|---|---|
| red | #ff0000 | rgb(255,0,0) | |
| crimson | #dc143c | rgb(220,20,60) | |
| tomato | #ff6347 | rgb(255,99,71) | |
| orangered | #ff4500 | rgb(255,69,0) | |
| hotpink | #ff69b4 | rgb(255,105,180) | |
| lightpink | #ffb6c1 | rgb(255,182,193) | |
| palevioletred | #db7093 | rgb(219,112,147) | |
| mediumvioletred | #c71585 | rgb(199,21,133) |
| Swatch | Name | HEX | RGB |
|---|---|---|---|
| orange | #ffa500 | rgb(255,165,0) | |
| darkorange | #ff8c00 | rgb(255,140,0) | |
| gold | #ffd700 | rgb(255,215,0) | |
| yellow | #ffff00 | rgb(255,255,0) | |
| lightsalmon | #ffa07a | rgb(255,160,122) | |
| khaki | #f0e68c | rgb(240,230,140) | |
| papayawhip | #ffefd5 | rgb(255,239,213) |
| Swatch | Name | HEX | RGB |
|---|---|---|---|
| green | #008000 | rgb(0,128,0) | |
| lime | #00ff00 | rgb(0,255,0) | |
| mediumseagreen | #3cb371 | rgb(60,179,113) | |
| seagreen | #2e8b57 | rgb(46,139,87) | |
| lightgreen | #90ee90 | rgb(144,238,144) | |
| darkgreen | #006400 | rgb(0,100,0) | |
| greenyellow | #adff2f | rgb(173,255,47) | |
| lawngreen | #7cfc00 | rgb(124,252,0) |
| Swatch | Name | HEX | RGB |
|---|---|---|---|
| blue | #0000ff | rgb(0,0,255) | |
| dodgerblue | #1e90ff | rgb(30,144,255) | |
| royalblue | #4169e1 | rgb(65,105,225) | |
| skyblue | #87ceeb | rgb(135,206,235) | |
| deepskyblue | #00bfff | rgb(0,191,255) | |
| cyan / aqua | #00ffff | rgb(0,255,255) | |
| darkcyan | #008b8b | rgb(0,139,139) | |
| navy | #000080 | rgb(0,0,128) |
| Swatch | Name | HEX | RGB |
|---|---|---|---|
| purple | #800080 | rgb(128,0,128) | |
| violet | #ee82ee | rgb(238,130,238) | |
| darkviolet | #9400d3 | rgb(148,0,211) | |
| blueviolet | #8a2be2 | rgb(138,43,226) | |
| orchid | #da70d6 | rgb(218,112,214) | |
| plum | #dda0dd | rgb(221,160,221) | |
| indigo (custom) | #6a0dad | rgb(106,13,173) | |
| indigo (named) | #4b0082 | rgb(75,0,130) |
| Swatch | Name | HEX | RGB |
|---|---|---|---|
| white | #ffffff | rgb(255,255,255) | |
| ghostwhite | #f8f8ff | rgb(248,248,255) | |
| whitesmoke | #f5f5f5 | rgb(245,245,245) | |
| lightgray | #d3d3d3 | rgb(211,211,211) | |
| gray | #808080 | rgb(128,128,128) | |
| dimgray | #696969 | rgb(105,105,105) | |
| darkgray | #a9a9a9 | rgb(169,169,169) | |
| black | #000000 | rgb(0,0,0) |
A solid color background is fine. But gradients — smooth transitions between two or more colors — are what make modern websites look genuinely beautiful. CSS makes gradients surprisingly easy to write.
You can use color values in many more CSS properties than just color and background-color. Here is every CSS property that accepts a color value:
Best Practice: Always define your brand colors as CSS Custom Properties (variables) in the :root selector. Then use var(--color-name) throughout your CSS. When you need to change a color, you only change it in one place instead of hunting through hundreds of lines of CSS.
Color contrast is one of the most commonly ignored aspects of web design — and one of the most important. If there isn't enough contrast between your text color and background color, people with visual impairments simply cannot read your content. And Google's accessibility signals are a real ranking factor.
The Web Content Accessibility Guidelines (WCAG) define two levels of contrast compliance:
Never use light gray text on a white background for body copy. It looks "modern" but it fails accessibility standards and drives users away — especially on bright screens or in sunlight. Dark text on a light background or white text on a dark background is always the right choice for readability.
Apply any color from this guide to your HTML and see it live instantly. Use HTML Editor Online Pro — paste your code, preview the result, check how it looks on mobile. Free, no signup, works right now.
🎨 Open HTML Editor Free →Q: What is the HEX code for white?#ffffff — or the shorthand #fff. Both are identical. White is when all three color channels (red, green, and blue) are at their maximum value of 255, which is FF in hexadecimal.
Q: What is the HEX code for black?#000000 — or the shorthand #000. Black is when all three channels are at 0 — no light at all.
Q: What is the HEX code for transparent?
Pure transparent in HEX is #00000000 — the 8-character format where the last two digits (00) represent full transparency. But in CSS, it's much cleaner to just use transparent as a named value, or rgba(0, 0, 0, 0).
Q: Which is better — HEX or RGB?
Neither is "better" — they produce identical colors. Use HEX when you're copying colors from a design tool like Figma or Adobe XD (they output HEX). Use RGBA when you need transparency. Use HSL when you're building a color system and want to create shades easily by adjusting lightness values.
Q: How do I find the hex code of a color on a website?
Use your browser's developer tools. Right-click any element, click Inspect, find the color property in the CSS panel, and you'll see the exact color value used. Chrome DevTools even shows a color picker when you click the color swatch in the CSS panel.
Q: What is the difference between #000 and rgb(0,0,0)?
Absolutely none — they produce exactly the same color: black. Both are completely valid and will display identically in every browser. The choice is purely a matter of personal preference and which format fits better in your workflow.