treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Proper Usage of Semicolons

  • I've always been under the impression that every css statement should end in a semicolon. However, many people use semi-colons simply as separators between two css statements. Which is the industry standard?

    I would do it like this:

    .myMethod { color: #8080ff; font-size: 14px; }

    but I've seen it like this

    .anotherMethod { color: #8080ff; font-size: 14px }


    Both seem to work in IE and FF. Does either cause a problem in any other browser?

    I prefer my method; it seems cleaner somehow. But I'd like to know which is "proper" technique.

    Edit: I realized what it is about the second method that bothers me... It's like reading a book where the last sentence in every paragraph is missing a period. :)
  • the semi colon is needed to seperate the properties from one another. The reason you should put the semi colon on the end is so that later if you want to add more rules, you won't need to remember to add it in there. It's better that way. Not adding it to the end of your line is lazy I think.
  • I believe it is actually perfectly valid to leave off that last semicolon and actually would save you a tiny amount of bandwidth to omit it. But... I agree with cybershot, it's ugly, it's lazy, and it invites problems later on.