🌍 NextJS · subject

NextJS Styling and UI Syllabus

The Styling and UI syllabus for NextJS in full: 3 chapters and 9 topics, every one listed below, plus 50 Styling and UI flashcards with answers.

3Chapters
9Topics
50Flashcards

Styling and UI syllabus: all 3 chapters

Expand any chapter to see its topics and sub-topics.

  1. CSS and Sass

    3 topics
    • Global Styles
    • CSS Modules
    • Sass Integration
  2. Styled Components

    3 topics
    • Setup and Configuration
    • Creating Styled Components
    • Theming with Styled Components
  3. Tailwind CSS

    3 topics
    • Setup and Configuration
    • Utility-First CSS
    • Customizing Tailwind

NextJS Styling and UI flashcards — 50 questions with answers

  1. In a Next.js App Router project, where must global CSS be imported so it applies to the entire application?

    In the root layout file (app/layout.tsx or .js). Global stylesheets can only be imported in the root layout, not in individual pages or components (in the App Router).

  2. What is the conventional filename for the global stylesheet in a Next.js project?

    app/globals.css (App Router) or styles/globals.css imported in pages/_app.js (Pages Router).

  3. In the Next.js Pages Router, which single file is allowed to import a global CSS file, and why?

    pages/_app.js (the custom App component). Global CSS affects every route, so Next.js restricts it to _app to avoid conflicts and ordering issues.

  4. What error does Next.js throw if you import a plain global CSS file into a regular page or component (Pages Router)?

    A 'Global CSS cannot be imported from files other than your Custom App' error, instructing you to move the import to pages/_app.js or convert it to a CSS Module.

  5. What is a CSS Module in Next.js and how is it named?

    A CSS file whose name ends in .module.css (e.g., Button.module.css). Its class names are automatically scoped locally to the component that imports it, preventing name collisions.

  6. How do you consume a class from a CSS Module in a React/Next.js component?

    Import it as an object (e.g., import styles from './Button.module.css') and reference classes as properties, such as className={styles.primary}.

  7. How does Next.js guarantee CSS Module class names are unique across the app?

    At build time it transforms each local class name into a unique hashed identifier (e.g., 'primary' becomes 'Button_primary__a1B2c'), scoping styles to that module.

  8. Unlike global CSS, where can CSS Modules be imported in a Next.js app?

    Anywhere: in any component or page. Because their scope is local, there is no risk of global conflicts, so Next.js allows them everywhere.

  9. What is Sass and what two syntaxes does it provide?

    Sass (Syntactically Awesome Style Sheets) is a CSS preprocessor. Its two syntaxes are SCSS (.scss, CSS-like with braces and semicolons) and the older indented syntax (.sass).

  10. What single step is required to enable Sass support in a Next.js project?

    Install the sass package (e.g., npm install --save-dev sass). Next.js has built-in Sass support once the compiler is present; no extra config is needed.

  11. Can Sass be used together with CSS Modules in Next.js, and how are such files named?

    Yes. Name the file with the .module.scss (or .module.sass) extension to get locally scoped, preprocessed styles (a SCSS Module).

  12. Name three core features Sass adds on top of plain CSS.

    Variables ($color), nesting of selectors, mixins/functions, partials with @use/@import, and inheritance via @extend.

  13. In Sass, how do you declare and use a variable for a primary color?

    Declare with a dollar sign: $primary: #0070f3; then reference it, e.g., color: $primary;.

  14. Which Next.js config option lets you customize Sass, such as adding include paths or a global prepend?

    The sassOptions key inside next.config.js (e.g., sassOptions: { includePaths: [...], prependData: '@use ...' }).

  15. What is the recommended modern Sass rule for including another partial, and how does it differ from @import?

    @use loads the partial with a namespace and loads it only once, avoiding duplication and global scope pollution. @import is deprecated because it dumps everything into the global namespace and can load files multiple times.

  16. What is styled-components and which CSS-in-JS technique does it use?

    A CSS-in-JS library that uses tagged template literals to write actual CSS scoped to a React component, generating unique class names at runtime.

  17. Write the basic pattern for creating a styled button component with styled-components.

    const Button = styled.button`\n color: white;\n background: blue;\n`; then render <Button>Click</Button>.

  18. What is the styled-components tagged-template syntax used to style an existing component?

    styled(Component)`...css...` — e.g., const FancyLink = styled(Link)`color: red;`. It wraps and extends the target component's styling by passing className.

  19. How do you make styled-components render different styles based on a prop?

    Interpolate a function that receives props inside the template literal, e.g., background: ${props => props.$primary ? 'blue' : 'gray'};.

  20. Why do modern styled-components use a $ prefix on custom props (transient props) like $primary?

    Transient props (prefixed with $) are consumed by styled-components for styling only and are NOT forwarded to the underlying DOM element, preventing invalid HTML attribute warnings.

Show the other 30 Styling and UI flashcards
  1. What extra setup does styled-components require in the Next.js App Router for correct server-side rendering?

    A style registry using ServerStyleSheet / useServerInsertedHTML in a client 'use client' component, plus enabling the compiler.styledComponents flag in next.config.js so styles are collected during SSR and no hydration mismatch occurs.

  2. Which next.config.js compiler flag enables built-in SWC support for styled-components in Next.js?

    compiler: { styledComponents: true }.

  3. In styled-components, what does the createGlobalStyle helper do?

    It creates a component that injects global CSS (like resets or html/body styles) into the document when rendered, since styled-components are normally scoped.

  4. What is theming in styled-components and which component provides the theme?

    Theming supplies a shared theme object (colors, fonts, spacing) to all styled components via the <ThemeProvider theme={theme}> context wrapper.

  5. How does a styled component access values from the theme provided by ThemeProvider?

    Through the theme prop injected into interpolations, e.g., color: ${props => props.theme.colors.primary};.

  6. How would you define a simple theme object for styled-components with a primary color and base spacing?

    const theme = { colors: { primary: '#0070f3' }, spacing: { base: '8px' } }; then pass it to <ThemeProvider theme={theme}>.

  7. How can a component that is NOT a styled component read the current styled-components theme?

    With the useTheme() hook (or the withTheme HOC), which returns the nearest ThemeProvider's theme object.

  8. How do you implement light/dark mode with styled-components ThemeProvider?

    Define two theme objects (lightTheme, darkTheme) and switch which one you pass to ThemeProvider based on state; all themed components update automatically.

  9. What is Tailwind CSS and what design philosophy does it follow?

    Tailwind is a utility-first CSS framework: you build designs by composing many small single-purpose utility classes (e.g., p-4, flex, text-center) directly in markup rather than writing custom CSS.

  10. Define 'utility-first CSS' as used by Tailwind.

    An approach where styling is applied via low-level, single-purpose utility classes (each doing one thing, like margin or color) directly in the HTML, instead of writing semantic component-level CSS rules.

  11. List two commonly cited advantages of the utility-first approach.

    You rarely write custom CSS or invent class names; styles stay co-located with markup; unused CSS is purged so bundles stay small; consistent design tokens via a shared scale.

  12. What three Tailwind directives are placed in the main CSS entry file to inject Tailwind's styles?

    @tailwind base; @tailwind components; @tailwind utilities; (In Tailwind v4 this is replaced by a single @import "tailwindcss";).

  13. What two config files are typically generated when setting up Tailwind, and by what command?

    tailwind.config.js and postcss.config.js, generated by 'npx tailwindcss init -p' (the -p also creates the PostCSS config).

  14. Why is the 'content' array in tailwind.config.js critical?

    It lists the file globs Tailwind scans for class names so it can tree-shake/purge unused styles. If a file isn't listed, its utility classes won't be generated in the final CSS.

  15. In Tailwind, what do the numeric suffixes in spacing utilities like p-4 or m-2 represent?

    Units on Tailwind's spacing scale, where each unit = 0.25rem (4px). So p-4 = 1rem (16px) padding and m-2 = 0.5rem (8px) margin.

  16. How do you apply a responsive style in Tailwind, e.g., different padding on medium screens and up?

    Prefix the utility with a breakpoint name and colon, e.g., md:p-8. Tailwind breakpoints are mobile-first (min-width based): sm, md, lg, xl, 2xl.

  17. What are Tailwind's default breakpoint pixel values for sm, md, lg, xl, and 2xl?

    sm = 640px, md = 768px, lg = 1024px, xl = 1280px, 2xl = 1536px.

  18. How do you apply a hover or focus state to a utility class in Tailwind?

    Use a state variant prefix, e.g., hover:bg-blue-700 or focus:ring-2. Variants can stack, like md:hover:underline.

  19. What is the recommended way to customize Tailwind's design tokens (colors, fonts, spacing)?

    Add them under theme.extend in tailwind.config.js. Using extend adds to the defaults; setting them directly under theme replaces the defaults entirely.

  20. What is the difference between putting a value under 'theme' versus 'theme.extend' in tailwind.config.js?

    Keys directly under theme override/replace Tailwind's default scale for that property, whereas keys under theme.extend merge with and add to the existing defaults.

  21. How do you add a custom brand color 'brand' with value #1DA1F2 usable as bg-brand or text-brand?

    In tailwind.config.js: theme: { extend: { colors: { brand: '#1DA1F2' } } }. Tailwind then generates bg-brand, text-brand, border-brand, etc.

  22. What is the @apply directive in Tailwind used for?

    @apply lets you compose existing utility classes into a custom CSS rule (e.g., .btn { @apply px-4 py-2 rounded bg-blue-500; }), useful for extracting repeated utility patterns.

  23. How do you write an arbitrary/one-off value in Tailwind when no utility exists, e.g., a top of 117px?

    Use square-bracket arbitrary value syntax: top-[117px] or bg-[#1da1f2]. This generates the exact value on demand without editing the config.

  24. Which plugin does Tailwind recommend for beautiful default typography on prose content, and how is it enabled?

    The @tailwindcss/typography plugin, added to the plugins array in tailwind.config.js; you then apply the 'prose' class to rich text containers.

  25. Compare CSS Modules and styled-components in terms of when styling is resolved.

    CSS Modules are resolved at build time into static, hashed CSS files (zero runtime cost). styled-components (classic runtime) generate class names and inject styles at runtime in the browser, enabling dynamic prop-based styling.

  26. Compare Tailwind (utility-first) with CSS-in-JS libraries like styled-components regarding where styles live.

    Tailwind applies predefined utility classes directly in markup with (mostly) no custom CSS or runtime; styled-components colocates full CSS in JS tagged templates and can compute styles dynamically from props at runtime.

  27. For dynamic, prop/theme-driven styling, which approach is most natural: CSS Modules, Tailwind, or styled-components? Why?

    styled-components, because it can interpolate JavaScript (props, theme, state) directly into the CSS at runtime. CSS Modules and Tailwind are primarily static and need conditional class toggling for dynamic behavior.

  28. Why are CSS Modules and Tailwind often preferred for performance over runtime CSS-in-JS?

    They produce static CSS at build time with no runtime style computation or JS bundle overhead, so there's no per-render styling cost or hydration serialization needed.

  29. What tool commonly processes Tailwind, and what role does it play in the build pipeline?

    PostCSS. Tailwind runs as a PostCSS plugin that scans content files, generates the needed utility classes, and (with autoprefixer) adds vendor prefixes during the build.

  30. In styled-components, what does the css helper (tagged template) provide versus styled?

    The css helper builds a reusable chunk of styles (a fragment) that can be interpolated into multiple styled components or applied conditionally, whereas styled creates an actual renderable component.

NextJS Styling and UI FAQ

What is in the NextJS Styling and UI syllabus?

NextJS Styling and UI is split into 3 chapters: CSS and Sass, Styled Components and Tailwind CSS. Together they contain 9 topics.

How many chapters are in NextJS Styling and UI?

3 chapters, containing 9 topics. The largest chapter is CSS and Sass, with 3 topics.

Are there flashcards for NextJS Styling and UI?

Yes — a 50-card Styling and UI deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.