Back to articles
Why Auto-Formatting Your CSS Catches Bugs You Did Not Know You Had

Why Auto-Formatting Your CSS Catches Bugs You Did Not Know You Had

via Dev.to BeginnersMichael Lip

Inconsistent CSS formatting is not just an aesthetic problem. It hides bugs. Missing semicolons, unclosed brackets, duplicate properties, and specificity conflicts all become harder to spot in messy code. I have tracked down more CSS bugs by reformatting the file first than I care to admit. What proper CSS formatting looks like There is no single standard, but the widely adopted conventions are: One selector per line for multi-selector rules Opening brace on the same line as the selector Each property on its own line, indented Space after the colon Semicolon after every value (including the last one) Closing brace on its own line One blank line between rule sets .header , .header-alt { display : flex ; align-items : center ; padding : 16px 24px ; background-color : #12121a ; } .navigation { margin-left : auto ; } Versus the mess that accumulates in production: .header , .header-alt { display : flex ; align-items : center ; padding : 16px 24px ; background-color : #12121a ;} .navigation

Continue reading on Dev.to Beginners

Opens in a new tab

Read Full Article
7 views

Related Articles