Many programming languages go through a code review before deployment. Whether it's a quick once-over, in-depth peer review, or complete unit testing, code reviews help us release code into the wild with confidence.
I started to imagine what a CSS code review might look like. CSS can be written in a number of ways, and the best way is often subjective to the project. I'm definitely not trying to get dogmatic with a post like this, but instead lay the foundation for what could be a starting point for getting the most out of CSS before it is released.
It's fair to wonder why we would want to review CSS in the first place. A review is yet another step that adds time and cost and effort and all that other stuff that seems to hold us up from shipping a product.
At the same time, a code review allows us to step back, take off our battle gear, and give our work an honest assessment—or hand it off to someone else for a fresh perspective. This is what separates us from the machines and, in the end, can save us the headache of having to deal with bug and performance fixes that could have been caught before they were shipped.
There's much more benefit here than just preemptively squashing bugs. I find that splitting a review into specific areas focused on these benefits helps frame the conversation and prioritize those positive outcomes. The benefits for you may be different from what I'll cover here, but these are ones I find myself coming back to time and again.
Let's not dwell on this, but not forget it either. The first job of CSS is to style the page so it looks like it's intended to. It matches the designers mockup or fits the style guide or whatever it's supposed to do. And it can do so with variable content (titles and content of various lengths, images of various sizes, etc.) If it doesn't, that needs to be fixed first.
If the design is responsive, make sure the design does what it's supposed to do fluidly and at each breakpoint.
The goal here is to ensure that CSS is well-written, organized, and documented. Those of us who have inherited projects from other developers know the benefits here. Code that uses a consistent naming convention and includes thorough documentation is easier to dive into and provides instruction for how to maintain and enhance the code in the future.
Questions to ask:
Available resources:
Once CSS is organized and consistent, I tend to turn my attention to how it looks on different browsers and devices. Well-written code is one thing, but it isn't worth much if it doesn't work where and when it should.
Questions to ask:
Available resources:
Now is the time to gauge just how specific the elements in the code are and identify whether there are opportunities to refactor. This creates a responsible cascade of styles where elements are either as modular or as specific as we want them to be.
Questions to ask:
!important
make its way into the code? If so, why was it used and can the code be refactored to avoid using it? Available resources:
Ignore this if the project isn't using a preprocessor. But if it is, there are certainly some extra things to think about.
Questions to ask:
Available resources:
I include performance toward the end of a review not to belittle it, but to make sure it is the cherry on top of our review sundae. Performant CSS is often about refinement and how it is packaged and served, so it seems appropriate for it to cap off the review process—even if performance is always in the back of our minds as we work.
Questions to ask:
<link>
or native @import
)? Can we reduce that number? Can they be served conditionally? Async? Available resources:
I definitely wouldn't say that every question and tool mentioned here is needed or even relevant for all projects. In fact, there are likely more questions and tools to consider. Are there questions you routinely ask before releasing CSS? For example, where would accessibility fit in for you? Please share!
Also, remember that the goal of auditing our code is not to make it perfect. We make compromises in CSS for many reasons (whether intentional or not) and, at the end of the day, just trying to do a good job is more than enough and this is part of that effort.