Opacity in Hex colors of CSS [duplicate] - css

This question already has answers here:
CSS hexadecimal RGBA?
(14 answers)
Closed 1 year ago.
How to apply opacity in Hex colors ?
I am working with CSS Hex colors. I am trying to apply opacity in Hex colors. I need #78909c with opacity 0.2.

The hex representation of colors supports the alpha channel to set opacity.
so, take any color in hex e.g. #ffffff and append 00 to ff (in hexadecimal representation) for opacity, i.e. #ffffff00 - #ffffffff
for your color: #78909c33
20% implies 33 in hex
Here is a demo
Reference: Hexadecimal notation

HEXA - #RRGGBBAA
There's a relatively new way of doing transparency, it's called HEXA (HEX + Alpha). It takes in 8 digits instead of 6. The last pair is Alpha. So the pattern of pairs is #RRGGBBAA. Having 4 digits also works: #RGBA
I am not sure about its browser support for now but, you can check the DRAFT Docs for more information.
§ 4.2. The RGB hexadecimal notations: #RRGGBB The syntax of a
is a token whose value consists of 3, 4, 6,
or 8 hexadecimal digits. In other words, a hex color is written as a
hash character, "#", followed by some number of digits 0-9 or letters
a-f (the case of the letters doesn’t matter - #00ff00 is identical to
#00FF00).
8 digits The first 6 digits are interpreted identically to the 6-digit
notation. The last pair of digits, interpreted as a hexadecimal
number, specifies the alpha channel of the color, where 00 represents
a fully transparent color and ff represent a fully opaque color.
Example 3 In other words, #0000ffcc represents the same color as
rgba(0, 0, 100%, 80%) (a slightly-transparent blue).
4 digits This is a shorter variant of the 8-digit notation, "expanded"
in the same way as the 3-digit notation is. The first digit,
interpreted as a hexadecimal number, specifies the red channel of the
color, where 0 represents the minimum value and f represents the
maximum. The next three digits represent the green, blue, and alpha
channels, respectively.
For the most part, Chrome and Firefox have started supporting this: enter image description here

Related

Why does RGB use 6 hex digits?

I understand that RGB encodes a color with two hex digits corresponding to the Red, Green, and Blue components. For instance, #ff0000 is pure red. And I understand that each hex digit represents a number from 0-15, or 4-bits of information. But how is it possible to represent every color with 32-bits? Why use two digits for Red and Green and Blue? Why aren't there, for instance, three digits per color?
I dont really know if any of this is related to hardware and whether we can even make colors to such detail but a third hex digit for colors means we will have colors with 4096 times more detail, (meaning if we have X color combinations currently, then we will have 4096 * X colors) which we simply dont need, since human eye wont be able to notice the difference, even in our current color system, let alone one much bigger.
So you'd be sacrificing efficiency for nothing in that case, like watching a movie on 600 frames per second while your eye can only process 60.

Why are colors represented by hexadecimal values in CSS? Is there an historical explanation?

In some programming languages, colors are represented by hexadecimal values. For example, using CSS, to change the text color of a header to maroon-ish, you could type:
h1 {
color: #8B1C62;
}
I'm wondering what the reason is for using a base-16 numeral system to represent colors. You could hypothetically use any numeral system to represent the same values, no?
When did this convention start? Does anybody know where I can read about the history of this phenomenon?
The primary use of hexadecimal notation is a human-friendly representation of binary-coded values in computing and digital electronics.
each hexadecimal digit represent 4 bits. half the byte.
a byte value can be in range of 0 to 255 in decimal but it is more easier to read it as 2 Hexadecimal digit from 00 to FF.
a 6 digit color code hold 256X256X256 combination of red, green and blue ! (8-Bit RGB)
read more about color, color spaces and hexadecimal :
http://www.smashingmagazine.com/2012/10/04/the-code-side-of-color/
http://en.wikipedia.org/wiki/Hexadecimal
http://en.wikipedia.org/wiki/RGB_color_model
You can certainly represent colors in any numeral system. Here's what your maroon-ish color looks like in various different systems:
Binary: 10001011 00011100 01100010
8 bits each for red, green, and blue. That's nice, but who wants to type all those numbers?
Decimal: 9116770
Fewer numbers to type, but how do you manipulate R, G, and B individually? And it feels kind of weird to refer to a color as nine million, one hundred sixteen thousand, seven hundred seventy.
Hexadecimal: 8B 1C 62
Even fewer numbers to type, and we can manipulate R, G, and B easily. Seems like a good candidate for representing colors, but let's try one more.
Base-256: ï [^\] b
Nice: we only have to type one character per color component. But I can never remember what number comes after ï or before the file separator control code, so I'd have to whip out the ASCII table every time I write or read a color. But what if we wrote the components in decimal instead?
Base-256, redux: 139,28,98
Much nicer. Not too many characters to type, and it's very clear which numbers represent R, G, and B.
Thus...
The two common ways to represent color values are hexadecimal and base-256-ish, because... it's easy!

RGB LED - Colour Values

I have a series of RGB LED lights hooked up to my Arduino board, and I'm trying to change the values of the LED, only problem is that I cant seem to find anything on a HEX to RGB converter.
Also, the RGB values aren't like the conventional values you get like (255,255,255) = white. They appear to be in some type of byte format (0x0ff)? Which I'm not familiar with at all.
Could someone point me in the right direction in how I can convert a HEX colour like '9cb261' into an RGB byte value?
Thanks
Hex is just a shorthand way of writing the same numbers, in a format that's a little easier to read if you're concerned about which bits are set and which are not.
The number "255" tells you that there are 2 "100s", 5 "10s", and 5 "1s". Put another way, it's 2 "10^2", 5 "10^1", and 5 "10^0".
Hex is the same idea, but instead of using 10 we use 16. Since there might be more than 10 things in each place, we add the characters a - f after 0-9.
Using a short example, "9c" means 9 instances of "16^1" plus c (12) instances of "16^0". This yields 144 + 12, or 156.
The "0x" prefix just tells you that the following string is to be interpreted as a hex string.
To break apart your example, the Hex color 9cb261 is just 3 bytes (9c, b2, 61).
If we convert the bytes back to decimal, it's (9*16+12, 11*16+2, 6*16+1) or (156, 178, 97)
There's a full write-up at Wikipedia's Hexadecimal article.

Css colors (#999 for example) - Why just three digits? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
3 digit Hex color code
Using 3-digit color codes rather than 6-digit color codes in CSS
I have a color that has the following RGB values:
255-223-145
I see that lots of pages have the colors with just three digits, for example:
color: #999;
I wonder why, and how would I convert these rgb values to a three digit color.
Thanks
It isn't a three digit colour, #999 is merely shorthand for #999999 so unless your numbers repeat like #223322 (#232) you can't cut it down.
The question has two bits, to convert hex to rgb, use a tool like this or this online.
#999 is shorthand for #999999, and #ABC is short for #AABBCC. CSS colors can be shortened if you don't need the full six hex digits.
Your color in hex is #FFDF91. The closest three-digit color would be #FD8 (#FFDD88). Close, though not identical.
You can write shortly if you have 2 same digits
FF -> F
99 -> 9
So #999 = #999999 and #FFF = #FFFFFF

Why do 3 digit hex css colors convert to 6 the way they do?

I'm aware that the method to convert a 3 digit hex css color to 6 digit code is by duplicating each hex digit once, as below.
#ABC === #AABBCC
Why does it work this way? Why isn't #ABC equivalent to #A0B0C0?
From the W3C spec:
The three-digit RGB notation (#rgb) is converted into six-digit form (#rrggbb) by replicating digits, not by adding zeros. For example, #fb0 expands to #ffbb00. This ensures that white (#ffffff) can be specified with the short notation (#fff) and removes any dependencies on the color depth of the display.
You can read more about it here: http://www.w3.org/TR/css3-color/
The reason is to be able to code the full range of colors (able to do both the highest and lowest color). For example, if #RGB became #R0G0B0, then #fff would become #f0f0f0, meaning you cannot code white. Conversely, if #RGB became #RfGfBf, then #000 would be #0f0f0f, ruling out black. The system of #RGB = #RRGGBB allows for #000 = #000000 (black) and #fff = #ffffff (white), giving a full range of evenly-spaced colors.
Read more at:
Wikipedia article
W3 Website

Resources