Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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,354 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,603 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.