Any benefit of using 'rgb (0,0,0)' over '#000'?

in defining color (of text or background), is there any benefit of using rgb rather than #?

Eg:
color: rgb (0,0,0)
vs:
color:#000

It appears to me rgb is longer code, so I would use #000 over RGB(0,0,0) any time, due to cleaner, and shorter code.
But perhaps I’m not aware of why rgb still is in use?

hex values are more common…rgb comes in handy when it comes to setting opacity though.

1 Like

Yeah, I understand rgb is 0-255, vs 00-FF.

Is there any benefit of adding spaces between the comma? rgb (0, 0, 0) vs (0,0,0)?

Readability, maybe? But I’ve read style guides where it’s advised to omit the spaces between.

Hex and RGB are 100% equivalent. No difference in terms of how the code is read by the Web browser, both are fully compatible with every modern browser, including Internet Explorer (RGBA, however, is not compatible with old versions of IE).

People who come from a computer science background are likely more comfortable and familiar with using hex in general, as it’s the number format for many things in computer science (memory addresses, op codes, etc).

People who don’t come from a computer science background but do have a background in digital graphics (think Photoshop, Illustrator, and other graphics programs) are likely more comfortable and familiar with RGB, because those programs display everything in RGB.

Hence, CSS is flexible enough to allow people from both backgrounds to define values in the way that they’re comfortable with. It’s really nothing more than that. Neither scheme is “better” than the other, it’s mostly about using what you’re most comfortable with. If that’s RGB, then use RGB, or if it’s hex, then use hex.

The one thing every front-end developer should know how to do is convert between hex and RGB. It’s really simple and if you ever work with a designer, you’re going to need to do so eventually.

1 Like

To me RGB is more intuitive when I want to play around with trying different colours (I’ll keep spelling it the Canadian/British way outside of actual coding). It’s all numbers so it’s easier to change for example from RGB(120,120,120) to RGB(180,180,180) when I want a lighter shade of grey. The same in hex is from #787878 to #B4B4B4 - to the untrained that’s not quite as obvious. Copy/pasting HEX is however generally more straightforward.

Well, if people are going to be coding, they might as well get used to hex.
I mean, a lot of other coding is in hex.
Coding isn’t like Photoshop.
I do agree that with a 0-256 value is easier to read than 00-FF.
I mean, it takes some time to calculate in the head how much BF8A9D is.
But online calculators are always an option.

Personally, I would like to code in an efficient way.
That means make the code as small as needed. Nothing more, nothing less.