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 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
10,403 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!