Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Web colors
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Hex triplet == A '''hex triplet''' is a six-digit (or eight-digit), three-[[byte]] (or four-byte) [[hexadecimal]] number used in [[HTML]], [[CSS]], [[SVG]], and other computing applications to represent colors. The bytes represent the red, green, and blue components of the color. The optional fourth byte refers to [[alpha channel]]. One byte represents a number in the range 00 to FF (in hexadecimal notation), or 0 to 255 in decimal notation. This represents the least (0) to the most (255) intensity of each of the color components. Thus web colors specify colors in the [[24-bit color|24-bit RGB color scheme]]. The hex triplet is formed by [[Concatenation|concatenating]] three bytes in hexadecimal notation, in the following order: * Byte 1: red value (color type red) * Byte 2: green value (color type green) * Byte 3: blue value (color type blue) * Byte 4 (optional): alpha value For example, consider the color where the red/green/blue values are decimal numbers: red=123, green=58, blue=30 (a hardwood brown color). The decimal numbers 123, 58, and 30 are equivalent to the hexadecimal numbers 7B, 3A, and 1E, respectively. The hex triplet is obtained by concatenating the six hexadecimal digits together, 7B3A1E in this example. If any one of the three color values is less than 10 hex (16 decimal), it must be represented with a leading zero so that the triplet always has exactly six digits. For example, the decimal triplet 4, 8, 16 would be represented by the hex digits 04, 08, 10, forming the hex triplet 040810. The number of colors that can be represented by this system is 256<sup>3</sup>, 16<sup>6</sup>, or 2<sup>24</sup> = 16,777,216. ===Shorthand hexadecimal form=== An abbreviated, three (hexadecimal)-digit or four-digit form can be used,<ref>{{cite web |url=http://www.w3.org/TR/css3-color/#rgb-color |publisher=W3C |work=CSS Color Module Level 3 |title=4.2.1. RGB color values |date=7 June 2011 |editor1-first=Tantek |editor1-last=Γelik |editor2-first=Chris |editor2-last=Lilley |editor3-first=L. David |editor3-last=Baron |first1=Steven |last1=Pemberton |first2=Brad |last2=Pettit |access-date=19 March 2013 }}</ref> but can cause errors if software or maintenance scripts are only expecting the long form. Expanding this form to the six-digit form is as simple as repeating each digit: 09C becomes 0099CC as presented on the following [[Cascading Style Sheets|CSS]] example: <syntaxhighlight lang="css"> .threedigit { color: #09C; } .sixdigit { color: #0099CC; } /* same color as above */ </syntaxhighlight> This shorthand form reduces the palette to 4,096 colors, equivalent of 12-bit color as opposed to 24-bit color using the whole six-digit form (16,777,216 colors). This limitation is sufficient for many text-based documents. ===Converting RGB to hexadecimal=== {{See also|Hexadecimal#Conversion}} RGB values are usually given in the 0β255 range; if they are in the 0β1 range, the values are multiplied by 255 before conversion. This number divided by sixteen (integer division; ignoring any remainder) gives the first hexadecimal digit (between 0 and F, where the letters A to F represent the numbers 10 to 15. See [[hexadecimal]] for more details). The remainder gives the second hexadecimal digit. For instance, the RGB value 58 (as shown in the previous example of hex triplets) divides into 3 groups of 16, thus the first digit is 3. A remainder of ten gives the hexadecimal number 3A. Likewise, the RGB value 201 divides into 12 groups of 16, thus the first digit is C. A remainder of nine gives the hexadecimal number C9. This process is repeated for each of the three color values. Conversion between number bases is a common feature of calculators, including both hand-held models and the software calculators bundled with most modern [[operating system]]s. Web-based tools specifically for converting color values are also available.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)