DEV Community

Christian Fried
Christian Fried

Posted on

Is it worth keeping your CSS DRY - pros and cons

You can avoid repetition in CSS through techniques like using classes, inheritance and preprocessors like Sass. Here are three pros and three cons associated with avoiding repetition:


Maintainability: By minimizing repetition, your code becomes more maintainable. If you need to make a change, you only have to do it in one place, reducing the risk of errors and making updates faster and more efficient.

Consistency: Reducing repetition helps ensure consistency across your styles. If a particular style is applied consistently through classes or inheritance, it's less likely to deviate from the intended design.

Scalability: Code that avoids repetition is generally more scalable. As your project grows, maintaining a DRY (Don't Repeat Yourself) codebase becomes increasingly important. It allows for easier expansion without a proportional increase in complexity.


Less intuitive code: Over-reliance on abstraction methods (like using mixins in preprocessors or UDJO (using declarations just once)) can result in code that is less intuitive, especially for developers who are not familiar with the specific abstractions or conventions used in the project.

It seems that the pros far outweighs the cons. That is avoiding repetition in CSS has benefits in terms of maintainability, consistency and scalability. However, it can result in less intuitive code.

What are your thoughts? How do you avoid repetition and keep your CSS DRY?

Top comments (0)