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