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 CSS Basics (2014) Basic Selectors ID and Class Selectors

Why in CSS {} doesn't have a semi-colon

I've noticed that, in programming, a semi-colon is used after each command to tell the program to STOP.

Why, when calling a CSS selector, do we not use a semi-colon?

In other words, why is it like this: p {}

rather than: p {};

3 Answers

Basically the } is the STOP. or called Code Block everything inside the curly braces is css the rest isn't. In css we use the semi-colon only to end a line so we can start another one, example:

p {     /* { open the Code Block*/

 color: royalblue;  /*Semi-colon end this line of code so we can jump to the next line*/
   background-color: black  /*Now in the last line we don't need another semicolon because there is nothing else to put below but is always good to put the semicolon at the end of any value so when we're modifying something we don't forget that we need to end the line before starting a new one or you know a little semicolon can cause a big headache*/



}  /*Close the Code Block*/
Christopher Loyd
PLUS
Christopher Loyd
Courses Plus Student 5,806 Points

In some traditional programming languages, the semicolon(;) isn't used after the code block ({}) either. C# is an example of this. The semicolon ends a statement, much like the period(.) does in English for a sentence. The code block groups related statements together, much like how we group related sentences in a paragraph.

Emma Willmann
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Emma Willmann
Treehouse Project Reviewer

CSS isn't actually a programming language, it is a stylesheet. I saw someone once say that the difference is that CSS (and HTML) describe presentation, where as a programming language describes function.