What Is Next.js and Why Use It?

Next.js Course: Beginner to Advanced with Examples · Next.js Introduction · 5 min read · Updated

Library and framework

  1. React gives you components: buttons, forms and lists.
  2. Next.js wraps React and adds routing, server rendering, data loading and image tools.
  3. Together they build your site, page by page.
  4. The visitor, or a search engine, gets a finished page quickly.

Imagine you want to build a house. React is like a very good box of bricks. It gives you strong pieces, but you still have to decide where the walls go, how people walk from room to room, where the pipes run and how the house is delivered. Next.js is like a house plan with the plumbing, the doors and the street address already worked out. You still build your own rooms, but a lot of the boring decisions are made for you. That is the simplest way to understand Next.js.

Next.js is a framework built on top of React. React is a library for building the parts of a screen, such as buttons, forms and lists. A framework is bigger: it also decides how files are organised, how pages are found, how data is loaded and how the finished site is sent to the browser. Next.js is made by a company called Vercel and is free and open source.

What problems does Next.js solve?

When you build a website with plain React, you quickly meet the same questions again and again. Next.js gives a ready answer to each one.

  • How do users move between pages? Plain React needs an extra library for routing. Next.js turns your folders into pages automatically. You will see this in the routing lessons.
  • How does Google read my page? A plain React app often sends an almost empty page and builds the content in the browser. Some search engines and social media previews handle this badly. Next.js can send the finished HTML, so the content is there from the first byte.
  • How do I load data safely? Next.js lets a component read from a database or a private API on the server, so secret keys never reach the browser.
  • How do I make pages fast? Next.js can build pages ahead of time, split code into small pieces and optimise images and fonts for you.
  • Where does my back end live? You can write small API endpoints inside the same project, so a simple site needs only one codebase.

Next.js and React: what is the difference?

Every Next.js page is written with React. If you know components, props and state, you already know most of what you will write. The difference is everything around the components.

  • React alone: you choose a router, a build tool, a way to fetch data and a way to deploy. You get freedom, but also a lot of setup and many decisions.
  • Next.js: one install gives you routing, a build tool, server rendering, image tools and an API layer. You get less freedom, but you start working faster and most Next.js projects look alike, so it is easy to join a new team.

If React is new to you, take the React course on this site first, or at least read the React basics lessons. You will understand Next.js much more easily. This course does not repeat what a component or a hook is. It builds on it.

Main features, in plain words

  • File-based routing. Create a folder and a file, get a URL.
  • Server Components. Components that run on the server and send only the result to the browser.
  • Different ways of rendering. Build a page ahead of time, build it on each request, or mix both. The next lesson explains these.
  • Built-in optimisation. Images, fonts and scripts are handled for you.
  • Route Handlers and Server Actions. Small server-side pieces for APIs and forms.
  • TypeScript support. The project can be set up with TypeScript from the first command.

When is Next.js a good choice?

  • A marketing site, blog or documentation site that must rank well in search.
  • A shop, a job board or a course site with many pages.
  • A web app with logins and dashboards, where some pages are public and some are private.
  • A project where you want the front end and a small back end in one place.

When might you not need it?

Not every project needs a framework. A tiny tool that lives behind a login and never needs to be found by search engines may be fine as a plain React app. A very small static page may be fine as plain HTML. And if your team already has a strong separate back end, Next.js can still be used only for the front end. Choose Next.js because a real need points to it, not because it is popular.

What you need before you start

  • Basic HTML and CSS.
  • JavaScript with ES6 features such as arrow functions, destructuring and async/await.
  • React basics: components, props, state and hooks. Our React course covers them.
  • A computer with Node.js 20.9 or newer installed. The next lessons show how.

Your task

  1. Write three sentences in your own words: what is Next.js, what is the difference from React, and which problem sounds most useful to you.
  2. Look at two websites you use often. Guess whether each one needs good search ranking, and whether it could be a plain React app.
  3. List the React topics you are not sure about. Revise them before lesson 4.

How to check it worked

  • You can explain Next.js as a framework built on React.
  • You can name at least four problems it solves.
  • You can give one case where plain React would be enough.

Frequently asked questions

Is Next.js free?

Yes. Next.js is open source and free to use. You pay only for hosting if you choose a paid host. You can also run it on your own server.

Do I need to know React before Next.js?

Yes. Every Next.js page is made of React components, so learn components, props, state and hooks first.

Is Next.js a front end or a back end tool?

Both. It builds the pages users see and it can also run server code, such as reading a database or handling a form. Large systems often still keep a separate back end.