Web colors hexadecimal notation - css

Usually colors in hexadecimal notation are presented with a hashtag following 6 hexadecimal characters. What color does the value #AAA produce? Are the other characters derived from the existing ones? Are the missing values just assumed?

#AAA is interpreted as #AAAAAA
When you have 3-hexadecimal colour, the browser is assuming that every single char (or number) gets doubled (so e.g. #ABC is equivalent to #AABBCC)

The six digit colours are traditional 24 bit colours, whereas the three character colour codes are "web-safe" colours...
http://en.wikipedia.org/wiki/Web_colors

Nice question.
Short answer: #xyz is read as #xxyyzz, so the specific example means #aaa becomes #aaaaaa, a gray quite dark tone (68.75%).
Wikipedia calls this shorthand hex form, https://en.wikipedia.org/wiki/Web_colors#Shorthand_hexadecimal_form
CSS does have a formal specification, but it is a very long read. To experiment with the specific colors that CSS allows, maybe browser debuggers is good. jsfiddle is also a possibility: http://jsfiddle.net/mYdb5/
which contains the following simple code:
Color test:<br/>
<div/>
div {
background-color: #aaa;
width:100%;
height:40px;
}

Related

Hex Colors - How to Calculate from 1 Color to Another

I work on .LESS and I am looking for a method how calculate from a hex color to another.
For example: I have #000000, then I do some calculations (lighten, or darken, or mix...) somehow finally it will become #657177.
Let's say:
#header-background: #000000;
#tags: lighten(#header-background, 30%);
I have tried many percentage numbers, but I couldn't get exactly from #000000 to #657177.
Please give a hand.
Thanks!
Try using http://www.w3schools.com/colors/colors_picker.asp since you know what color you are looking for, and it can give you the percentage difference.

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

#FFFFFF or "white" in CSS?

Is there a difference between #FFF (#FFFFFF) and white in CSS? Is one better than the other?
All are supported in the major browsers. It comes down to whichever unjustifiable, deep-seated prejudice you personally have for/against hexadecimal/the English language.
They're all guaranteed to be the same. CSS 3 Color Module (a Proposed Recommendation) defines white as #ffffff.
It later says that values like #rgb are converted to #rrggbb:
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.
That means that #fff is equivalent to #ffffff (by doubling).
there is no difference. I would imagine browsers take "white" and translate it to "#FFFFFF" in the background. its just a matter of personal coding style which you will use. I prefer using hash because its easier to read and recognise as a colour
Technically, there is no real difference. See this list of supported color names by all major browsers. Of course, some will have a preference to one way or the other but for me as long as you keep it consistent it doesn't matter.
I know this question is very old, but Iam trying to explain with my explanation for the new people.
you can use #F instead of #FF only if there are two same characters followed by each other. Example:#00FF00 you can use instead #0F0. That means #F = #FF or #0 = #00 etc...

Are there any good reasons for using hex over decimal for RGB colour values in CSS?

rgb(255,255,255) notation has been available since CSS1. But #ffffff seems to be vastly more popular.
Obviously it's slightly more compact. I know that hex is more closely related to the underlying bytes, and understand that there would be advantages in carrying out arithmetic on those values, but this isn't something you're going to do with CSS.
Colour values tend to be originated by designers (such as myself) who would never encounter hex notation anywhere else, and are much more familiar with the decimal notation which is the main way of specifying colour in the apps they use -- in fact I have met quite a few who don't realise how a given hex value breaks down into RGB components and assumed it didn't directly relate to the colour at all, like a Pantone colour system reference (eg PMS432).
So, any reason not to use decimal?
Hex values are easier to copy and paste from your favourite image editor.
RGB values are easier to manipulate with Javascript.
(My favourite Hex colour value is #EDEDED and a site we made for a client involved in motorsport had a background colour of #F1F1F1 :-)
Ed.
It's worth noting that if you want to input an RGBA value, hex notation is not supported; i.e., you can't fake it with #FFFFFFff. As a matter of fact, the alpha value must be a number between 0.0 and 1.0, inclusive. (Check out this page for browser support -- as always, IE is leading the pack here. ;) )
HSL and HSLA color support -- which is very designer friendly -- is also provided with a similar syntax to the RGB() style. If a designer were to use both types of color values in the same stylesheet, they might opt for decimal values over hex codes for consistency.
I think it's what you're used to. If you're used to HTML, you'll probably use HEX since it's just been used a lot in HTML. If you're from a design background, using Photoshop/Corel/PaintShopPro etc., then you're likely used to the RGB notation - though, a lot of programs these days incorporate a HEX value field too.
As said, RGBA might be a reason to just go with the RGB notation - consistency.
Though, I think it also depends on the scenario. If you're comfortable with both, you might just switch between them: #fff is a lot easier to type than rgb(255,255,255).
Another question is why people will say #fff instead of White (assuming most browsers support this keyword).
It's all a matter of preference and legibility - if you're maintaining a huge CSS file, being able to look at the colour value and know what colour it is, is a really good advantage. Even more advantageous is using something like LESS or Sass to add a kind of programmability to CSS - allowing constants for example. So instead of saying:
#title { color: #abcdef; }
You might instead do the following with LESS:
#base-color: #abcdef;
#title { color: #base-color; }
Maintaining the CSS becomes less of an issue.
If you're worried about the performance of the browser rendering it's result, then that could also be another factor to your choice.
So in summary, it boils down to:
Familiarity
Preference
Maintainability
Performance
The main reason is probably compactness, as you mentioned. #ffffff can even be further shortened to the #fff shorthand notation.
Another possible reason is that there's a perceived performance increase by saving the browser the trouble of converting the rgb notation.
Traditionally HTML has always used hex colours, so that has carried forward into CSS. Think <font color="#ffffff">
I always used hex, but today I prefer to set my values as:
rgb(82, 110, 188)
in my css files, so whenever I want to add opacity I just need to rename rgb to rgba and add the opacity value. The advantage is that I don't have to convert the hex value to rgb before being able to add the opacity:
rgba(82, 110, 188, 0.5)
CSS was invented by software developers, not designers. Software developers live and breathe hex. From my old C64 days, I can still read most hex numbers without thinking. A9, anyone?
Various things will accept a single hex value where they may have different ways of entering three decimal values. There's also the fact that it's always 6 characters (or 3, admittedly - plus the #) which makes it easier to scan down a list of them.
Just a couple of random thoughts to add to the mix...
Probably a touch of speed when the color is interpreted by a browser. Otherwise some people from design background may know how to compose colors from RGB components when they write code, and some others from programming background are probably more inclined to use HEX values.
HEX is most common due to historical reasons.
Before CSS was common in web development, colors were specified within HTML tags and the most commonly used and supported way to specify a color was to use HEX values.
no valid reason, other than personal preference.
Maybe I've done HTML too long, but I find it easier to think in HEX values. A lot of the pre-defined colour palette for HTML maps neatly to HEX values. Using the shortened format also gives you automatic 'web-safe' colours, though this is not really an issue in the days of 32bit colour displays.
I have always preferred HEX in comparison to RGB or HSL simply due to it being easier for me to read while styling.
When it comes to dynamic editing, I would like to use RGB because of the ease of cycling through different colors. This also helps a little when doing CSS gradients.

Resources