Are there any good reasons to use decimal hexadecimal values ​​for RGB color values ​​in CSS?

rgb(255,255,255) notation is available with CSS1. But #ffffff seems a lot more popular.

Obviously, this is a little more compact. I know that hex is more connected with basic bytes and understands that when performing arithmetic these values ​​will have advantages, but this is not what you are going to do with CSS.

Color values ​​are typically created by designers (such as myself) who never meet with hexadecimal notation elsewhere and are more familiar with decimal notation, which is the main way to indicate color in the applications they use, in fact that I I met a lot of people who do not understand how this hexadecimal value is divided into RGB components and assumes that it is not directly related to color, for example, with reference to the Pantone color system (for example, PMS432).

So for some reason not to use a decimal digit?

+52
css colors rgb hex
Jul 23 '09 at 12:28
source share
12 answers

Hash values ​​are easier to copy and paste from your favorite image editor.

RGB values ​​are easier to manipulate with Javascript.

(My favorite Hex color value is #EDEDED, and the site we created for a client involved in motorsport had a background color of # F1F1F1 :-)

Ed.

+28
Jul 23 '09 at 12:33
source share

It is worth noting that if you want to enter an RGBA value, hexadecimal notation is not supported; those. you cannot fake it with #FFFFFFff. In fact, the alpha value must be a number from 0.0 to 1.0 inclusive. (Check out this page for browser support - as always, IE leads the package here;))

HSL and HSLA color support, which is very convenient for the designer, also has the same RGB () style syntax. If a developer needs to use both types of color values ​​in the same stylesheet, they can select decimal values ​​by hexadecimal codes for consistency.

+16
Jul 23 '09 at 12:57
source share

I think what are you used to. If you are used to HTML, you are likely to use HEX since it was just used in HTML. If you work against the background of design using Photoshop / Corel / PaintShopPro, etc., then you most likely use RGB notation, although at present many programs also contain a HEX value field.

As already mentioned, RGBA may be a reason to just go with the designation RGB - consistency.

Although, I think it also depends on the scenario. If you are comfortable with both, you can simply switch between them: #fff much 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 all depends on preferences and readability - if you support a huge CSS file, being able to look at the color value and know what color it is, this is a really good advantage. It is even more beneficial to use something like LESS or Sass to add some kind of programmability to CSS - for example, constants. Therefore, instead of saying:

 #title { color: #abcdef; } 

Instead of LESS, you can do the following:

 @base-color: #abcdef; #title { color: @base-color; } 

Maintaining CSS is becoming a problem.

If you are worried about browser rendering performance, then this may also be another factor for your choice.

So, it boils down to the following:

  • Friendly
  • Preference
  • maintainability
  • Performance
+7
Aug 26 '10 at 13:54
source share

HTML has traditionally always used hexadecimal colors, so it has been ported to CSS. Think <font color="#ffffff">

+6
Jul 23 '09 at 12:34
source share

The main reason, in your opinion, is compactness. #ffffff can even be shortened to shorthand for #fff .

Another possible reason is that there is an increase in performance due to the browser preserving the problem of converting rgb notation.

+6
Jul 23 '09 at 12:40
source share

Different things will take one hexadecimal value, where they can have different ways of entering three decimal values. There's also the fact that it's always 6 characters (or 3, admittedly - plus #), which makes it easier to scan a list of them.

Just a few random thoughts to add to the mix ...

+4
Jul 23 '09 at 12:35
source share

CSS was invented by software developers, not designers. Software developers live and breathe six. From my old C64 days, I can still read most hexadecimal numbers without a second thought. A9, anyone?

+4
Jul 23 '09 at 12:44
source share

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 an opacity value. The advantage is that I do not need to convert the hex value to rgb before adding opacity:

 rgba(82, 110, 188, 0.5) 
+4
May 18 '14 at 9:30
source share

Probably a touch of speed when the color is interpreted by the browser. Otherwise, some design people may know how to make colors from RGB components when they write code, and some others from the programming background are probably more likely to use HEX values.

+2
Jul 23 '09 at 12:34
source share

there is no good reason other than personal preference.

+1
Jul 23 '09 at 12:29
source share

I may have been doing HTML for too long, but it's easier for me to think about HEX values. A lot of the predefined color palette for HTML maps neatly displays HEX values. Using the shortened format also gives you automatic "web safe" colors, although this is not a problem on days of 32-bit color displays.

+1
Jul 23 '09 at 12:44
source share

HEX is most often due to historical reasons.

Before CSS was common in web development, colors were specified in HTML tags, and the most commonly used and supported way to specify colors was to use HEX values.

+1
Nov 29 '13 at 23:33
source share



All Articles