A couple of questions concerning this:
- Is it good practice?
- Will it, on a large scale, result in better load times?
- Can it result in browsers ‘breaking’?
- Is the same true for the last function in JavaScript (/jQuery)?
What I mean is stuff like this:
#myElement {
position: absolute;
top: 0;
left: 0
}
It’s not good practice to manually exclude semicolons. This is purely because it’s easy to overlook when adding more styles, especially if you’re working in a team:
Imagine you start with:
And then someone adds some styles:
Suddenly the other developer is wasting time figuring out why their
widthdeclaration isn’t working (or worse yet, doesn’t notice that it’s not working). It’s safer to leave the semi-colons in.Most definitely, for every block, you’d save a couple of bytes. These add up, especially for large style sheets. Instead of worrying about these performance gains yourself, it’s better to use a CSS compressor, such as the YUI Compressor to automatically remove the ending semi-colons for you.
No, it’s safe, as browsers implement this part of the specification correctly. The CSS2 specification defines a declaration thusly:
More importantly:
This means that
;is used to separate multiple declarations, but it is not needed to terminate them.JavaScript is a whole different beast with a completely different specification. This particular question has been answered in depth many times before on Stack Overflow.