CSS frameworks like Material UI, Bootstrap, or Pico are popular tools for reducing boilerplate, improving quality, and driving consistency in web development. However, these benefits can be challenging to maintain as a project evolves. This article explores why writing your own CSS is usually a better choice than relying on frameworks and highlights modern CSS features that simplify the process.

Downsides of CSS Frameworks

 CSS frameworks offer a set of common styles and components to expedite the development process, ensure consistency, and handle responsiveness. However, the initial convenience can come with several long-term challenges.

 

  Overriding

 

 – Time-Consuming: Overriding styles from a framework can be more complex than writing custom styles from scratch. Frameworks come with a ton of predefined styles which might clash with your custom needs. This often results in a cascade of overrides, which eats up more time than simply writing initial, clean CSS.

 – Maintenance Headaches: Keeping track of what has been overridden or extended quickly becomes cumbersome. As different team members add their custom styles, tracking the source of conflicting styles can turn into a significant headache.

 – Expertise in Frameworks, Not CSS: When developers spend too much time mastering the specific rules and requirements of frameworks, they may neglect fundamental CSS skills. This can become a disadvantage if they need to work on custom designs that don’t fit neatly within a framework’s confines.

 

  Hard to Enforce Consistency

 

 – Deviation from Design Systems: Teams often start with the intention to follow a framework’s design rules strictly but deviate over time due to unique project needs, resulting in a fragmented design approach.

 – General vs. Specific Needs: Frameworks cater to general use cases, making compromises necessary for specific requirement/project needs. This leads to a situation where custom solutions are shoehorned into a general infrastructure, stretching the framework beyond its intended use.

 

  Difference from Frameworks in Other Languages

 

 – CSS Frameworks vs. Web Frameworks: Unlike web frameworks in other languages (e.g., Flask, Rails), CSS frameworks often require numerous internal adjustments and overrides, making the development process cumbersome.

Write Your Own CSS

 To manage complexities and maintain control, writing your own CSS can be much more efficient in the long run.

 

  Custom CSS Benefits

 

 Start with a basic setup:

 – Reset: Use a CSS reset to ensure consistency across different browsers.

 – Theme: Define theme-specific variables for colors, fonts, and other design elements.

 – Base Styles: Establish base styles for typography, links, and other basic elements.

 – Components: Develop reusable components as needed, making customization straightforward as the project evolves.

 

 

  Starter Codebases

 

 Minimal CSS starters like Pico CSS provide just enough structure to reduce boilerplate without imposing the constraints of a full-fledged framework. This allows for significant customization while keeping things lean and maintainable.

Modern CSS Featuresgn

 Modern CSS provides several features that aid in simplifying the management of styles without additional complexity.

 

 

  Theming

 – CSS Custom Properties: Use variables to define primary colors, font sizes, and other constants, making it easy to create themes that can adapt to user preferences, such as light/dark modes.

 

  CSS Scopes

 – Scoped Styles: Scoped CSS allows for component-specific styling without the risk of unintended side effects spilling over. This feature is gaining browser support, further simplifying style management.

 

  Nested Syntax

 – Ease of Writing: Nested styles in CSS improve readability and maintain logical groupings of styles, thereby making the code easier to understand and maintain.

 

  Helper Functions

 – Value Functions: Modern CSS functions like `calc` and `color-mix` offer enhanced flexibility in defining styles, which reduces the need for multiple variables and keeps the codebase clean.

Non-CSS Complexity

While additional layers of complexity in web development are sometimes inevitable, mitigating as much as you can through efficient CSS management is crucial.

 

  Compile-to-CSS Drawbacks

 – Build Step Complexity: Introducing additional compile steps can clutter the developer workflow. For instance, Sass or Less might require a compilation step that adds to the build time.

 – Environmental Incompatibility: Compile-time and runtime CSS solutions may struggle to integrate seamlessly with modern frameworks like NextJS or Remix, creating bottlenecks in the development process.

 

 

  Semantic CSS

 – Meaningful Class Names: Using semantic class names enhances both maintainability and templating flexibility. Semantic classes make it easier for new developers to understand the purpose and context of styles in the codebase.

 

 

  Modern Layout Options

 – Flexbox and Grid: Utilize modern layout mechanisms for cleaner and more responsive design. Both Flexbox and CSS Grid provide robust methods to create responsive layouts efficiently, moving away from outdated grid systems that are less flexible and harder to maintain.

How to Structure Custom CSS

 Creating a modular and maintainable CSS structure from scratch involves some best practices.

 

  Initial Setup


  1. Minimal Styles: Start with global styles, a CSS reset, and base layout/typography settings.
  2. Component Styles: Develop styles for components like buttons, forms, tables, etc., and integrate them directly into the codebase where they will be used.
 

  Maintenance


  1. Global and Scoped Styles: Use global styles for broad consistency and scoped styles for specific components to prevent style conflicts.
  2. Frequent Refactoring: Regularly refactor CSS to extract common patterns into reusable global styles, thereby keeping the codebase organized and avoiding redundancy.
Conclusion

 Although CSS frameworks offer immediate advantages, such as development speed and consistency, the long-term drawbacks often outweigh these benefits. By opting to build with pure CSS, augmented by modern features, developers can achieve more maintainable and flexible styles. For your next project, starting from scratch or using a minimalist CSS starter kit might provide better control and simplify your approach to styling.


 In conclusion, adopting a custom CSS strategy tailored to your project’s specific needs fosters better maintainability, cleaner code, and more efficient collaboration within development teams. Modern CSS capabilities further empower developers to manage styles effectively without the constraints of rigid frameworks.

TABLE OF CONTENTS

Contact Info

Please leave your contact info and we will contact you back

    YOUR INFO:

    PROJECT OVERVIEW:

    CRITERIA:

    ADDITIONAL INFO: