RGB to HEX Converter
Convert RGB color values to HEX codes instantly. Enter red, green, and blue values (0–255) and get the corresponding HEX code with a live color preview.
How RGB to HEX conversion works
Each RGB value (0–255) is converted to a two-digit hexadecimal number. Red 255 → FF, Green 87 → 57, Blue 51 → 33, combined as #FF5733. The formula converts each decimal channel to base-16 and pads single-digit results with a leading zero.
// JavaScript — RGB to HEX
function rgbToHex(r, g, b) {
return "#" + [r, g, b]
.map(v => v.toString(16).padStart(2, "0"))
.join("");
}
rgbToHex(255, 87, 51); // "#ff5733"
# Python
def rgb_to_hex(r, g, b):
return f"#{r:02x}{g:02x}{b:02x}"
rgb_to_hex(255, 87, 51) # "#ff5733"
/* CSS — both formats are equivalent */
color: rgb(255, 87, 51);
color: #ff5733;Shorthand HEX codes
When each hex pair has identical digits (e.g., #AABBCC), the code can be shortened to #ABC. However, #FF5733 cannot be shortened because 57 and 33 have different digits. CSS supports both 3-digit and 6-digit HEX codes. Modern CSS also supports 8-digit hex for alpha transparency: #FF573380 is 50% transparent.
Frequently Asked Questions
How do I convert RGB 255, 0, 0 to HEX?
RGB(255, 0, 0) = #FF0000. Red: 255 → FF, Green: 0 → 00, Blue: 0 → 00. This is pure red.
What is the HEX code for white?
#FFFFFF — all channels at maximum (RGB 255, 255, 255). In shorthand: #FFF.
Related Convert Tools
SVG to JSX Converter
Convert SVG to JSX or a React/TypeScript component — camelCase attributes, style objects, forwardRef, memo, props spread
OpenAPI to TypeScript
Convert OpenAPI 3.x and Swagger 2.0 specs to TypeScript interfaces and types with $ref resolution, allOf/oneOf/anyOf, enums, and API operation types
JSON to Zod Converter
Convert JSON or JSON Schema to Zod validation schemas with $ref resolution, allOf/oneOf/anyOf, enum, format constraints, and required/optional fields
GraphQL to TypeScript
Convert GraphQL SDL schemas to TypeScript interfaces, types, enums, unions, and operations