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 How to Make a Website Beginning HTML and CSS Write a CSS Selector and Property

how do i code for a color change on css

css

index.html
<body>
    <h1>Nick Pettit</h1>
</body>

3 Answers

Joshua Farley
Joshua Farley
11,312 Points
body h1 {
    color: blue;
    background: yellow;
}
Denis Murphy
Denis Murphy
14,388 Points

If you want to color the h1 text and just have the background initially around it in a different color:

h1 {

   color: black;

   background: grey;

}

If you want all the background to be grey then you just need a seperate body element:

h1 {

    color: black;


}


body {

      background: grey;
}

While both Denis and Joshua are correct, their suggestions are ideal for an external CSS file. The challenge question is actually asking you to write the style on the html page. Your html should look something like the following:

    <body>
        <style></style>
        <h1>Nick Pettit</h1>
    </body>

You can then insert the CSS within the style tag so that it looks something like this:

    <style>h1 { color: green; }</style>

Which is also equivalent to:

    <style>
        h1 {
            color: green;
        }
    </style>

The semi-colon after green is not necessary, but it's usually considered best practice to include it just in case you add other styles to the h1 element.

I hope that helps!