How is a 3 digit HEX number interpreted as a color value in this example?
background: #fff

Do browsers double up each digit?
Thanks!
WBR

Dani AI

Generated

Short answer: the three-digit shorthand is expanded by repeating each digit to make the six-digit form. As asked about the shorthand and pointed to a reference, here is a concise, practical explanation.

A three-digit hex #RGB becomes #RRGGBB — each single hex digit (0–9, A–F; case does not matter) is doubled to form the full 8‑bit-per-channel value. For example, #1a2 expands to #11aa22. To shorten a six-digit color to three digits you can only do so when each pair matches (for instance #112233 -> #123), otherwise no exact shorthand exists.

Modern CSS also supports four- and eight-digit hex forms that include alpha: #RGBA expands to #RRGGBBAA, and #RRGGBBAA is the full form. Three-digit shorthand and the six-digit form are long supported in browsers; alpha hex forms are newer and may not exist in very old user agents. For authoritative details and browser notes, see the CSS color documentation on MDN: Hex notation and other color formats.

Recommended Answers

All 2 Replies

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.