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 CSS: Cascading Style Sheets What is CSS?

Tobi Ogunnaike
Tobi Ogunnaike
2,242 Points

How come this works without the correct syntax?

I typed

body { background-color: red }

i.e. without the semi-colon (;) after 'red'

and the background color changed to red? When is the semi colon necessary?

Thanks

1 Answer

It is needed to separate your properties. Since you only have one property inside your declaration, it doesn't change anything. If you add more than one property inside your declaration, it wouldn't work.

You can test this by using this code:

body { background-color: red font-size: 16px }

You will notice that it's not functionnal.

To make sure, always use the semicolon.

Tobi Ogunnaike
Tobi Ogunnaike
2,242 Points

thanks Yann, your explanation is very clear.