Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS

Chelsea Hulbert
Chelsea Hulbert
2,238 Points

What is the benefit to having these different color values?

Why would one use the rgb/rgba method over hexadecimal or the name of the color? Is the color value a matter of preference or is there an important difference that I'm missing?

Rune Andreas Nielsen
Rune Andreas Nielsen
5,342 Points

From what i know, there used to be a difference because of browser compatibility. In the new modern browsers there shouldn't be a big difference, and you would use either rgba or hex depending on what you like the most.

It´s a good idea to pick only one of them, to keep a standard in your css file.

1 Answer

Tobias Helmrich
Tobias Helmrich
31,601 Points

Hey Chelsea,

there is no real reason to use a specific way to define colors, it's more a matter of personal preference. I mostly use hex values because colors are almost always specified with their hex value, it's also easier to copy and paste the hex value from certain applications than copying all of the three (or four with the alpha value) values for RGB and the way to write hex values in CSS is also way shorter/easier than RGB. The problem with the name of colors is of course that there are less possibilities.

I think it's most important to stay consistent and not mix all of the different ways to add colors together randomly. :)

Chelsea Hulbert
Chelsea Hulbert
2,238 Points

Thanks for clearing that up Tobias, I prefer hex values for that reason as well.