-1

Is there any performance difference between:

p {
  margin:0px;
  padding:0px;
}

and omitting the final semicolon:

p {
  margin:0px;
  padding:0px
}

Thanks in advance!

8
  • 10
    So all your other css, html and server-side processing is so streamlined that you worry about browsers' ability to parse css down to a semi-colon? Commented Mar 12, 2010 at 15:03
  • 8
    It took me a minute to figure out what the difference was Commented Mar 12, 2010 at 15:04
  • I edited to clarify that semicolon bit. Commented Mar 12, 2010 at 15:09
  • @klausbyskov I doubt it but why not asking... Commented Mar 12, 2010 at 15:10
  • Sounds like a bet between coworkers Commented Mar 12, 2010 at 15:17

5 Answers 5

5

No there is not, the browser doesn't care about the trailing semicolon, even in IE6. The parser checks for it as a delimiter that's it.

If anything, since the browser is basically performing tokenization not much more complex than .split(';'), the second may be faster in a probably not measurable way simply because of the lack of an extra null token. But...the difference would be infinitesimal, and you do not need to worry about it either way.

Sign up to request clarification or add additional context in comments.

1 Comment

And more to the point, leaving out the final semicolon is a maintenance issue to be avoided.
2

I highly doubt it. But, of course, no one has ever measured such a thing independently!

Comments

1

I think the main difference will be in the increased css file size. but even if your css file was too big it'll just increase by few bytes. so in short I think it is ok not to care about it.

Comments

0

No, ";" is seperator.

I think we can't talk about performance in CSS.

Comments

0

You're actually better off using a CSS minifier. In short, it will remove all of the unnecessary spaces and bloat (e.g., changing #ffffff to #fff where appropriate, removing comments, etc). Some of them will automatically remove the last semicolon in each block. Be aware this can cause issues, as @t-j-crowder mentioned, if you later add lines to the end of the block and forget to add back the semicolon!

Also, make sure you're using external CSS files where possible and store them on the same server/ FQDN. If you can, combine your external CSS files into one so you minimize the number of requests the browser has to make.

This will speed up the download time and give you the biggest bang for your buck in terms of optimization. If the browser caches the files, subsequent visits to the same page (or to different pages using the same stylesheets) will be faster.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.