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 CSS: Cascading Style Sheets Use ID Selectors

Why do you have to have a main.css page/why can you not just write this code on the index?

Do you have to set up CSS as a separate tab or page or could you have written that code within the main page?

4 Answers

Alex Gervais
Alex Gervais
5,290 Points

You can write it on index.html if you want to, but picture what would happen if your site had 15 different pages. Every time you'd want to say, change the background color, you'd have to go to EACH html page and change it. When you link to an outside .css file, you change one line, in this case one line in 'main.css' and all 15 of your pages that link to it are updated. When you start developing bigger sites, having all your css in your html isn't realistic when you sometimes have to update 500+ pages at once.

That's very helpful! Thanks!

Alex Gervais
Alex Gervais
5,290 Points

You're welcome. Good luck :)

Rahul Ram
Rahul Ram
2,872 Points

hmm let's take it this way. You have to tell your friends about a reunion. you have 2 options,

  1. Go and tell everybody individually.
  2. Make a group on social media and add everyone to the group and make the announcement.

Which one is more efficient? ( P.S answer is 2nd option)

it's the same. Your are CSS file and your friends are HTML documents.

you can either type in the information each HTMLpage or make a single CSS page and just link it to all HTML pages.

It is more tidy that way.