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

HTML How to Make a Website Beginning HTML and CSS Add Style to the Page

What if I want to use Hex code to define color? I tried "color: #0000ff;" but it does not work.

I want to use Hex code for color instead, what will the command look like? What if I want to use the RGB color?

Bogdan Cabaj
Bogdan Cabaj
16,349 Points

RGB uses 3 sets of values. Red, Green, Blue. If you are using RGB color you can't use hex.

color: rgb(0,0,255);

color: #0000ff;

Please see w3schools link for CSS Colors reference. http://www.w3schools.com/cssref/css_colors_legal.asp

Do you mean if I am using Hex code to style H1, I should write it like:

<style>

h1 { color: #0000ff; }

</style> <h1>YUE,YU April</h1>

This piece of code does not work. Can you tell me what went wrong?

1 Answer

Hey Yue,

If i'm understanding you correctly, you are wanting to set the color of the h1 with a hex value? If that's the case, the way to do it would be like this:

h1 { color: #0000ff; }

Just remember, if you are using a hex value to define the color of the h1, you CAN use an RGB value as well, however, whichever one is below the other in the code, it will over ride the first color, and that will be the predominate color. For example, if I was to do something like this:

h1 { color: #0000ff; rbg(0,0,255); }

This code would be pointless because the rgb is taking control because it comes after the hex color! Hope this made sense! Feel free to leave a reply if you would like further explanation!