Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 72 ยท Getting Started

What Is Next.js?

Learn what Next.js adds to React: routing, server rendering, data fetching, optimization and deployment, plus App Router versus Pages Router explained.

React is a library for building user interfaces. It answers one question very well: given some data, what should this part of the screen look like? It does not answer the questions around that one. How do URLs map to pages? Where does data come from? How do you send real HTML to a search engine? How do you split code so that a visitor does not download your whole app to read one page?

Next.js is a framework built on top of React that answers those questions for you. You still write React components, but Next.js decides how they are bundled, how they are rendered on a server, how requests are routed and how the result is deployed. It is made by Vercel, it is open source, and it is one of the most widely used ways to build React sites, from small blogs to large stores.

This lesson is the map for the whole tutorial. You will see what a framework adds, what the two routers are, and which code runs on the server and which in the browser. If React itself is new to you, start with How React Works first, because every Next.js page is a React component.

What plain React leaves to you

A typical React app created with a bundler template renders entirely in the browser. The server sends an almost empty HTML file and a large JavaScript bundle. The browser downloads the bundle, runs it, and only then are the headings and paragraphs created. That works, but it has costs:

  • Slow first paint. Nothing useful appears until the JavaScript has loaded and run.
  • Weak SEO and link previews. A crawler that does not run JavaScript sees an empty page.
  • You assemble everything yourself. You pick a router, a data-fetching approach, an image strategy and a build setup, and you keep them working together.
  • No server side. Anything secret, such as a database password, has nowhere safe to live. You need a separate backend project.

Next.js keeps React's component model and fills in these gaps.

What Next.js adds

React plus a whole toolbox

Routing Folders and files become URLs.
Server rendering Pages arrive as real HTML.
Data on the server Components can read a database directly.
Optimization Images, fonts and code splitting built in.

One project, one language, front end and back end together.

1 / 3

Here is the same list in more detail:

  • File-based routing. A folder named about containing a page.tsx file becomes the URL /about. There is no route table to maintain. You will build a model of this in File-Based Routing.
  • Server rendering. Components run on the server first, so the browser receives finished HTML. It can show content right away, and crawlers can read it.
  • Data fetching on the server. A component can be an async function that reads from a database or calls an API. Secrets never leave the server.
  • Caching and revalidation. Results can be stored and refreshed on a schedule or on demand. This is a big topic with its own chapter.
  • Optimization. Built-in components handle images, fonts and scripts, and the build tool splits your code per page automatically.
  • Mutations. Server actions and route handlers let you accept form submissions and build HTTP endpoints without a second project.
  • Tooling. TypeScript support, a fast dev server with hot reloading, and a production build are all included.

App Router and Pages Router

Next.js has two routing systems, and you will meet both in the wild.

App Router Pages Router
Folder app/ pages/
Introduced Next.js 13 The original design
Components Server Components by default Client-side React components
Layouts Nested layout.tsx files that keep their state A custom _app file
Data async components, fetch, caching directives getServerSideProps, getStaticProps
Best for New projects Existing projects you maintain

The App Router is the recommended foundation for new work, and it is the subject of this tutorial. It is built on React Server Components, which let most of your UI stay on the server. The Pages Router still works and is still supported, and many production sites use it. You can even use both in one project during a migration. We cover that path in Upgrading and Migrating from Pages Router.

This tutorial targets a recent Next.js release (version 16) with React 19. Next.js changes quickly, so each lesson points out behavior that differs between versions. When in doubt, check the version in your package.json.

What runs on the server and what in the browser

In the App Router, every component is a Server Component unless you say otherwise. Server Components run only on the server. They can be async, they can read files and databases, and they add no JavaScript to what the browser downloads. When a component needs state, effects or event handlers, you opt in by putting the 'use client' directive at the top of its file. That file, and everything it imports, becomes a Client Component: it is rendered on the server once for the first HTML, and then also runs in the browser to become interactive.

A rule of thumb: keep a component on the server unless it needs to react to the user. Later chapters spend a lot of time on this boundary, starting with React Server Components and Client Components and "use client".

Real code and stand-ins on this site

Real framework or stand-in? Next.js needs a Node.js server, a build step and a file system, so it cannot run inside a web page here. Every tsx, command or configuration block in this tutorial is the real thing, shown read-only. Next to it, each lesson has small live examples, called stand-ins, that you can run: React 19 components in the browser, and Node.js programs on our code runner. A stand-in re-creates the idea (for example, turning file paths into routes) in a few dozen lines. It follows the documented behavior but is not the real Next.js, and each lesson says which is which.

The first live example shows why server rendering matters. Both buttons render the same page component. The only difference is what the browser receives in its first HTML response.

What the browser receives first

Switch between the two. In client-only mode the first response contains an empty div, so there is nothing to read until the script runs. In server-rendered mode the list is already in the HTML. (The stand-in uses React's real renderToString, which is the same idea Next.js uses, though Next.js does much more around it.)

The second example is a Node.js stand-in for something Next.js does at build time: it looks at your files and works out which ones are pages and which code runs where. The real build analyzes imports and the module graph; this version only looks at file names and the first line.

Node.js Which file is a page, and where does it run?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Notice that like-button.tsx is the only file marked for the browser, and only because its first line is the 'use client' directive. Everything else stays on the server by default, which is the reason a Next.js page can ship far less JavaScript than the same page in client-only React.

When to choose Next.js

Next.js is a strong fit when you need good SEO, fast first loads, a mix of static and dynamic pages, or a full-stack app in one codebase: marketing sites, blogs, documentation, stores, dashboards and SaaS products. It is less necessary for a small internal tool behind a login that needs no search indexing, where a plain React app is perfectly fine. A framework is a trade: you accept its conventions in exchange for features you would otherwise build yourself.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is the main thing Next.js adds on top of React?

    Next.js is a framework: you still write React components, but it supplies the routing, rendering, bundling and server features React leaves to you.
  2. 2. In the App Router, which kind of component is the default?

    Every component in the app directory is a Server Component unless its file starts with the 'use client' directive.
  3. 3. Why does server rendering help SEO and first paint?

    A client-only app sends an empty shell and builds the page after the script runs. A server-rendered page sends finished HTML first.
  4. 4. Which folder holds routes in the App Router?

    The App Router lives in the app directory. The older Pages Router uses pages.
  5. 5. How do the live examples in this tutorial relate to the real Next.js?

    Next.js needs a Node.js server and a build step, so the lessons show real code read-only and add small runnable stand-ins that follow the documented behavior.

Summary

  • Next.js is a React framework that adds routing, server rendering, data fetching, caching, optimization and backend features to React.
  • The App Router (the app folder) is the recommended system for new projects and is built on Server Components; the Pages Router (the pages folder) is older but still supported.
  • Components are Server Components by default and add no JavaScript to the browser; the 'use client' directive marks Client Components.
  • Server rendering sends real HTML first, which helps first paint, SEO and link previews.
  • On this site, real Next.js code is read-only and each lesson has live stand-ins that show how the ideas work inside.

Next: Creating a Next.js App