Dropping Semicolons from CSS Blocks
Eliminating the terminal semicolons in CSS blocks is a subject of debate. Let's explore the implications of this practice:
Is it Good Practice?
Manual exclusion of semicolons is not recommended. It increases the risk of overlooking semicolons when adding new styles, particularly in collaborative environments.
Impact on Load Times
While removing semicolons saves bytes, it's not a significant factor that would noticeably improve load times. Using CSS compressors, which automatically remove trailing semicolons, is a more efficient solution.
Potential Browser Issues
No, browsers correctly interpret CSS specifications that allow declarations to end without semicolons. The CSS2 specification states that semicolons are used to separate multiple declarations, not to terminate them.
Applies to JavaScript Functions?
The absence of a terminal semicolon in the last function in JavaScript (or jQuery) has been extensively discussed on Stack Overflow. JavaScript follows a different specification and requires semicolons to terminate statements.
The above is the detailed content of Should You Drop Semicolons in CSS Blocks?. For more information, please follow other related articles on the PHP Chinese website!