DEV Community

Christian Fried
Christian Fried

Posted on

1

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:

Pros

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.

Cons

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?

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more