ProNextJS
    Loading
    lesson

    Styling Next.js App Router Applications

    Jack HerringtonJack Herrington

    In this section, we'll explore some different options for how to style a Next.js App Router application. CSS is essential for creating visually appealing and well-performing applications, and choosing the right approach can greatly impact your developer experience.

    Styling Challenges with React Server Components

    The introduction of React Server Components (RSCs) in the App Router has brought some challenges when it comes to styling. RSCs cannot use hooks or context, which means that popular CSS libraries like Emotion and Material UI may not be compatible out of the box. This can be a pain point, as it requires all components styled with such libraries to be client components, limiting the benefits of the App Router.

    Styling Options for the App Router

    Fortunately, the popularity of React and Next.js has led to the development of viable solutions that make CSS easy to use and performant in the App Router. In this section, we'll explore various styling options, including:

    • Built-in CSS Modules
    • Tailwind CSS
    • Meta's Stylex, a build-time CSS system
    • Materialize Pigment CSS
    • Making Emotion work with the App Router

    Practical Demonstration

    To demonstrate these styling options, we'll start with a simple starter layout consisting of a stack of unstyled products in a single column. Throughout these lessons, we'll transform this layout into beautiful, fully responsive cards with rounded edges.

    We'll cover the following aspects of styling:

    • Basic styling
    • Media queries for responsive design (e.g., 3 columns on desktop to 1 column on mobile)
    • Container queries to change card orientation from vertical to horizontal layout
    • Supporting light and dark mode using the user's preferred color scheme

    By the end of this section, you'll have a clear understanding of how to apply each styling technology and be able to decide which one works best for your application.

    Getting Started

    While you can jump around from technology to technology in this section, it's recommended to start with the CSS Modules section first. In the following sections, we'll assume you're already familiar with the CSS and focus more on the mechanics of applying the CSS using each specific technology.

    With that said, let's dig into the world of styling your Next.js App Router application!

    Transcript