How to Find the Color Code in an Image (HEX From Any Pixel)
To find the color code in an image, open it in a color picker and click a pixel. The tool reads that pixel's red, green, and blue values, each a number from 0 to 255, and writes them as a six-digit HEX code such as #2A7DE1. You can then convert that HEX code to RGB, HSL, or any other format your project needs.
The click is easy. Getting the right number takes a bit more care. Two pixels a millimeter apart on the same logo can return different codes, and a screenshot can carry a color profile that shifts every value before you click anything.
This guide walks through a real example: pulling a brand blue from a logo screenshot. It covers how a picker gets from a pixel to a HEX code, how to convert that code to RGB and HSL by hand, and why you should sample a flat area or average several pixels instead of trusting one click.
How a color picker turns a pixel into a HEX code
What a pixel actually stores
A standard digital image is a grid of pixels. In ordinary 8-bit images, each pixel has three channels: red, green, and blue (RGB). Each channel is a whole number from 0 (none of that light) to 255 (full intensity). So rgb(0, 0, 0) is black, rgb(255, 255, 255) is white, and rgb(42, 125, 225) is a medium blue.
A color picker decodes the image file, finds the pixel under your cursor, and reports its three channel values. If the image has transparency, there's a fourth channel, alpha, which tells you how opaque the pixel is.
Reading the HEX digits
A HEX code is the same three numbers written in base 16 (hexadecimal), two digits per channel, in the order red, green, blue. Base 16 uses the digits 0–9 and then A–F for 10–15. Each two-digit pair works out to (first digit × 16) + second digit:
2A= 2 × 16 + 10 = 42 (red)7D= 7 × 16 + 13 = 125 (green)E1= 14 × 16 + 1 = 225 (blue)
So #2A7DE1 and rgb(42, 125, 225) are the same color written two ways. The largest two-digit HEX value, FF, is 15 × 16 + 15 = 255, which is why each channel tops out at 255. MDN's hex color reference also covers the shorthand forms, like the three-digit #FFF and the eight-digit version with alpha.
How to find the color code from an image, step by step
Say you need a company's brand blue and all you have is a screenshot of its logo.
- Save the screenshot as PNG if you can. PNG is lossless, so it keeps the exact pixel values. JPG changes them slightly every time it saves (more on that below).
- Open the image in a picker. The free Image Color Picker reads HEX and RGB codes from an uploaded image and also shows its main palette, which helps you spot the dominant brand color.
- Zoom in on the logo. Look for the largest solid area of blue, such as the middle of a thick letter or the inside of a shape. Stay away from edges.
- Click the center of that flat area. Write down the HEX code. In this example it's
#2A7DE1. - Click three or four more spots in the same area. If they all match, you're done. If they differ by a few units, average them (see the worked example below).
- Check the palette. If the main palette shows a blue within a few units of your reading, that's a good sign you sampled the body of the color and not a blended edge.
- Convert the code to whatever format you need.
Converting the HEX code to RGB and HSL
RGB comes straight from the HEX digits, as shown above. HSL (hue, saturation, lightness) takes a few more steps, but it's useful because it describes the color the way people think about it: which hue it is, how vivid, and how light.
Here's the arithmetic for rgb(42, 125, 225):
- Scale each channel to 0–1: R = 42/255 ≈ 0.165, G = 125/255 ≈ 0.490, B = 225/255 ≈ 0.882.
- Find the max, min, and difference: max = 0.882 (blue), min = 0.165 (red), difference = 183/255 ≈ 0.718.
- Lightness = (max + min) ÷ 2 = (225 + 42) ÷ 510 = 267/510 ≈ 0.524, or 52%.
- Saturation = difference ÷ (1 − |2L − 1|). Here 2L − 1 = 24/510, so the divisor is 486/510. That gives (366/510) ÷ (486/510) = 366/486 ≈ 0.753, or 75%.
- Hue: blue is the max, so hue = 60 × ((R − G) ÷ difference + 4) = 60 × ((42 − 125) ÷ 183 + 4) = 60 × (−0.454 + 4) ≈ 60 × 3.546 ≈ 213°.
| Format | Value | Typical use |
|---|---|---|
| HEX | #2A7DE1 |
CSS, design tools, brand guides |
| RGB | rgb(42, 125, 225) |
CSS, image editors, code |
| HSL | hsl(213, 75%, 52%) |
Making lighter or darker variants by hand |
| CMYK (simple formula) | 81%, 44%, 0%, 12% |
A rough starting point for print |
The CMYK row uses the basic math formula (K = 1 − max, then each ink = (1 − channel − K) ÷ (1 − K)). Real print results depend on the paper, the press, and the printer's color profile, so treat this number as a starting point and confirm it with whoever is printing.
You don't have to do this by hand. The Color Code Converter converts between HEX, RGB, HSL, and CMYK and generates tints and shades. It's still worth knowing the math so you can tell when a result looks wrong.
Why neighboring pixels give different values
If you click around the logo, you'll probably get several slightly different codes. There are three usual reasons.
JPG compression artifacts
JPG is a lossy format. It splits the image into small blocks (typically 8 × 8 pixels), simplifies the detail in each block, and throws away information the eye barely notices. A solid blue area can come back as a patchwork of near-identical blues: rgb(41, 124, 226) here, rgb(43, 126, 224) there. Near sharp edges, such as blue lettering on white, JPG also creates "ringing," faint halos of off-color pixels. Lower quality settings make all of this worse. The guide to JPG vs PNG vs WebP explains why PNG is the better choice for logos and flat graphics.
Anti-aliased edges
Screens smooth curved and diagonal edges by blending edge pixels with the background. This is called anti-aliasing. A pixel that's half covered by the blue letter and half by the white page might come out around:
- Red: (42 + 255) ÷ 2 ≈ 149
- Green: (125 + 255) ÷ 2 = 190
- Blue: (225 + 255) ÷ 2 = 240
That's roughly #95BEF0, a pale sky blue that isn't in the brand palette at all. The exact blend depends on how the software renders edges, but the lesson holds: edge pixels are mixtures, not the real color.
Scaled and resized screenshots
When a screenshot is resized, whether by display scaling on a high-resolution screen, by zooming in a browser, or by you shrinking it later, the software calculates new pixels by blending old ones. Thin lines and small text are hit hardest. If the logo is small in your screenshot, zoom the page in so the logo is large on screen, then capture it again.
Sample a flat area or average a few pixels
The fix for all three problems is the same: read from the middle of a solid area, and if the readings still vary, average them.
Worked example. Four clicks inside the logo's blue area return:
| Sample | R | G | B |
|---|---|---|---|
| 1 | 41 | 124 | 226 |
| 2 | 43 | 126 | 224 |
| 3 | 42 | 125 | 227 |
| 4 | 42 | 125 | 223 |
| Sum | 168 | 500 | 900 |
| Average (÷ 4) | 42 | 125 | 225 |
The average is rgb(42, 125, 225), or #2A7DE1. The JPG noise spreads around the true value in both directions, so averaging cancels most of it out. Round to the nearest whole number if the averages come out as decimals.
Two rules of thumb:
- Take samples from the same flat area. Averaging an edge pixel in with the others pulls the result toward the background color.
- If the spread is large, for example readings 20 or more units apart, you're probably looking at a gradient, a shadow, or a texture rather than one flat color. In that case, ask for the official brand guide or the original vector file.
Color profiles: Display P3 vs sRGB
The numbers in a pixel only mean something together with a color space, which defines exactly which red, green, and blue those numbers refer to. Most of the web assumes sRGB. HEX codes in CSS are sRGB by definition, according to the W3C's CSS Color Module Level 4.
Many newer screens, including many Apple devices, can show a wider range called Display P3. Screenshots and photos from those devices are often saved with a P3 profile attached. The same triplet, say (42, 125, 225), is a different, more saturated color in P3 than in sRGB.
What that means in practice:
- If your picker converts the image to sRGB before reading it, you get a web-ready value. Very vivid colors outside the sRGB range may be clipped to the nearest color sRGB can show.
- If a tool reads the raw numbers and ignores the profile, you get P3 numbers labeled as if they were sRGB, and the color will look slightly off when you use it in CSS.
- Two apps can show different codes for the same pixel of the same file, depending on how each one handles color management. Which approach a given app uses depends on the app, the browser, and the operating system.
If exact accuracy matters, convert the screenshot to sRGB in an image editor before sampling, or take the color from a source that's already sRGB, such as the brand's website CSS or its style guide.
Night mode, dark mode, and other screenshot traps
Warm-light filters. Features like Night Shift on Apple devices and Night Light on Windows tint the screen orange in the evening. On most systems the filter is applied at the display, so it usually doesn't change the pixels saved in a screenshot. Behavior can vary by device and app, though, and the filter does change what you see. A correct swatch can look wrong next to the logo while the filter is on, so turn it off before you judge colors by eye.
Photos of a screen. If you photograph a monitor with a phone instead of taking a screenshot, the photo picks up the room lighting, any night filter, the camera's white balance, and the screen's own tint. Never sample brand colors from a photo of a screen.
Dark mode. Many websites and apps show different logo or button colors in dark mode. That's a different color, not a rendering error. Take the screenshot in the mode whose colors you actually want.
Overlays and transparency. Hover states, semi-transparent menus, and drop shadows mix with whatever sits behind them. Close pop-ups and move the cursor away before you capture the screen.
Re-saved copies. A logo downloaded from social media or a chat app has often been recompressed, sometimes several times. Each round adds JPG artifacts, so start from the cleanest source you can find. The guide on compressing images for web explains how quality settings affect this.
Quick reference checklist
- Capture as PNG, at a size where the logo is large on screen.
- Turn off warm-light filters and close overlays. Use the light or dark mode you actually need.
- Sample the center of a flat area. Never sample edges, text outlines, or shadows.
- Take 3–5 samples. If they differ by a few units, average each channel and round.
- If samples differ by 20+ units, it's a gradient or texture. Find the official color.
- For web use, make sure the value is sRGB. Be cautious with P3-tagged screenshots.
- Convert HEX → RGB → HSL as needed. Use the CMYK result only as a rough guide for print.
- Check the final code next to the original image at 100% zoom.
Frequently Asked Questions
Can I get an accurate color code from a photo of a real object, like a painted wall or a fabric?
You can get an approximate code, but not an exact one. The camera's white balance, the lighting, shadows, and the surface texture all change the pixel values, so the same wall can read very differently in daylight and under indoor bulbs. For paint or fabric, use the manufacturer's published color reference, and use the picked value only as a rough match.
Is a HEX code the same as an RGB code?
Yes. For ordinary 8-bit colors they hold exactly the same information in different notation. HEX writes the red, green, and blue values in base 16 with two digits each, while RGB writes them as decimal numbers from 0 to 255. #FF8000 and rgb(255, 128, 0) are the same orange.
Why does my picked color look different when I paste it into a design app?
Usually the source image and the design app handle color profiles differently. The image may be tagged Display P3 while the app works in sRGB, or the reverse. Your monitor's calibration and any night filter also affect what you see. Check that both sides use the same color space before you decide the code is wrong.
Can I get a color from a website without taking a screenshot?
Often, yes. Most desktop browsers' developer tools let you inspect an element and see the color values set in its CSS, which gives you the exact intended code with no compression or scaling. Some browsers also include an eyedropper in their developer tools, though where it lives depends on the browser and version.
Which color format should I send to a designer or printer?
For screens, send the HEX code, and add RGB if they ask for it, since both are standard in web and design tools. For print, send the HEX code too, but ask the printer which CMYK values or spot color system they use, because a CMYK number from a simple formula doesn't account for their paper and press.