too windy
Photo by Khamkéo Vilaysing / Unsplash

Styling in Next.js: my not so humble opinion(s)

styled-next + sass is my choice for scalable styling in nextJS

Ah, the ever-changing world of web and mobile application development! If there’s one thing more reliable than the sun rising, it’s the web development community flocking to the next big thing. In the vast and ever-evolving landscape of web development, I've navigated countless trends, ridden waves of popular libraries, and often revisited the drawing board. As someone who has been a part of the creation and scaling of numerous commercial web and mobile applications, the allure of the 'new' often competes with the wisdom drawn from the 'old'. Today, as I ponder over the styling paradigms in Next.js and the meteoric rise of libraries like Tailwind, I find myself turning back the pages, seeking patterns from the past.

A Brief Journey Through CSS Evolution

  • Global CSS: Ah, the good ol' days, where CSS was as global as our naïve optimism. A time when a single style could wreak havoc across a whole site. Delightfully chaotic!
  • BEM & Those Naming Conventions: Just when things seemed out of hand, BEM pranced in, whispering sweet nothings like "modularity" and "scalability". What's in a name? Turns out, a lot.
  • Modular CSS: Components became our new best friends, and with that, the idea of keeping our CSS nicely wrapped up inside them. Imagine clothes tailored just for you, or in this case, your component!
  • CSS-in-JS: Then, in a plot twist nobody asked for, someone thought, "Hey, why not put CSS inside JavaScript?" And thus, CSS-in-JS was born, merging the worlds of styles and scripts, for better or for worse.

Modern Libraries: A Double-Edged Sword?

  • Bootstrap & Tailwind: Tailwind, with its utility-first approach, and Bootstrap, with its comprehensive components, have risen to the forefront of CSS styling in recent years. On the surface, they offer rapid prototyping and visually consistent results. But herein lies my reservation: over the years, I've seen many such tools come and go, and what they often share is the facade pattern. They encapsulate complexity with an abstraction layer, which in turn introduces its own syntax, its own quirks. Every new abstraction promises to reduce the learning curve, but it subtly replaces it with the need to understand this new layer itself.
  • The Redux & Sass Affair
    • Let's take a step back and discuss Redux. Many have criticized its verbosity, yet I've always admired and championed it. Why? Because Redux isn't just another layer. It embodies the timeless principles of functional programming, emphasizing stateless data transfers and message passing. These principles help avoid pitfalls like race conditions. While one can argue that Redux comes with its learning curve, the knowledge acquired isn't just "Redux knowledge." It's a broader, universally applicable understanding of how data behaves and how state can be managed in predictable ways.
    • The same can be said for Sass. At its core, Sass augments CSS by introducing constructs that mirror common programming paradigms – like mixins, variables, and nesting. Instead of making you learn an entirely new way of styling, it builds upon what you already know. The ‘learning’ in this case is less about grasping the nuances of a new tool and more about applying familiar programming logic to your styles.

styled-next + Sass = 👍

In my endless quest for the most effective, efficient, and scalable styling solution for Next.js, I've found solace in the fusion of styled-next and Sass. Here's why: styled-next offers a splendid blend of component-centric styling (a la CSS-in-JS) while remaining true to the fundamentals of CSS. Pair that with the power of Sass – its variables, nested rules, mixins, and functions – and you've got a dynamic duo that's hard to beat. Sass enhances our CSS with programming-like capabilities, enabling cleaner, DRY (Don't Repeat Yourself) styles. On the other hand, styled-next ensures that styles remain scoped, efficient, and delightfully modular. It's like having a Swiss army knife that's been fine-tuned for the intricacies of Next.js. While the cacophony of new libraries and tools will always tempt us with their siren songs, I firmly believe that a deep understanding and the judicious use of tried-and-true technologies can set a project on the path to success. In the realm of Next.js styling, styled-next and Sass are, in my seasoned opinion, the winning ticket.

In the grand tapestry of web development, as the colors and patterns constantly evolve, it's the foundational threads that often prove to be the most enduring and valuable. So, as we embrace the new, let's not forget the wisdom that experience has woven into our journey. After all, true style, much like good humor, is timeless.


EVERY WEEK

Articles & tutorials for you

By signing up for the DreamStack mailing list you will receive exclusive app development guides & resources, be the first to hear about new react native features & integration guides, educational workshops, and have access to subscriber only content!

Written by