Best Practices in CSS

1 min read

I find “best practice” a dangerous term to use. It makes us think that we’re supposed to think a certain way, do things a certain way because that is the way of “best practices”. We hardly question it, because of course, why else would it be called that if it wasn’t the best? It makes us feel dirty if we’d try anything else.

Fuck that.

The reason I bring it up is because I write a lot of CSS. For the past few of years I’ve used CSS in a lot of different ways, from, I guess you can call it the traditional way of writing CSS i.e IDs and classes, to modular, extremely modular; almost like inline style kind of modular (yuck!). Some ways were better than others but I learned something from everything. Somewhere along the way I started using literal style classes i.e classes such as .padding-top .red .margin-bottom. I felt like I was “hacking” CSS or something, it didn’t feel right because it wasn’t in style with those “best practices” (kinda like following the crowd) but it did the job and it did well.

Today we have things like OOCSS that really breaks things down so I don’t feel so bad for doing the “hacks” I did. Today, I watched this talk by Andy Hume called “CSS for grownups” (the talk was 2012 but I think it will be relevant for a long time) and about 2/3 into the video he brings up examples identical to my literal style classes and explains that there are nothing wrong with them. He makes the point of them being understandable, readable, flexible and maintainable. He was the only ever person I know to have used such an example.

I’m glad he brought it up because when you’re the only person you know to have ever done something a certain way, sometimes you just question yourself if it was a right choice because no one else has done it even if it was logical all because you’re comparing it to the “best practices”. It’s a small thing I know but I’m actually glad I did something different.

best practice design css