Web Development
How to Build a Website with React
React is a JavaScript library for building user interfaces, created at Facebook (now Meta) and released as open source in 2013. It powers everything from small portfolios to large web applications, and it is one of the most in-demand front-end skills. This tutorial walks you through building a real multi-page website with React: setting up the project, creating components, handling data and navigation, styling, and deploying. You do not need to be an expert, but you should know basic HTML, CSS and JavaScript first.
Last reviewed: November 2026. React and its tooling update regularly, so check the official documentation at react.dev if a command or version differs from what you see here.
What you need before you start
A code editor such as Visual Studio Code.
A current long-term-support (LTS) version of Node.js, which also installs the npm package manager. Download it from nodejs.org.
A terminal (Terminal on macOS and Linux, PowerShell or Windows Terminal on Windows).
Basic JavaScript knowledge, including variables, functions, arrays, objects and arrow functions.
Step 1: Choose how to set up the project
You may see older tutorials that start with Create React App. The React team deprecated it in early 2025, and it is no longer recommended for new projects. Today the official guidance is to start with a framework such as Next.js or React Router if you need server rendering, routing and data loading built in, or to use a build tool such as Vite for a simple client-side app. For learning React and building a straightforward website, Vite is fast, lightweight and beginner-friendly, so that is what we will use here.
Step 2: Create the project with Vite
Open your terminal and run:
npm create vite@latest my-react-site -- --template react
cd my-react-site
npm install
npm run devThe last command starts a development server, usually at http://localhost:5173. Open that address and you will see the starter page. Every time you save a file, the browser updates instantly, which is called hot module replacement.
The project structure
index.html: the single HTML page that loads your app.
src/main.jsx: the entry point that mounts your React app into the page.
src/App.jsx: the root component.
package.json: lists your dependencies and scripts.
public/: static files such as the favicon.
Step 3: Understand components and JSX
React apps are built from components: reusable pieces of interface written as JavaScript functions that return markup. The markup syntax is called JSX, and it looks like HTML inside JavaScript. A simple component looks like this:
function Welcome() {
return (
<section>
<h1>Welcome to my site</h1>
<p>I build things for the web.</p>
</section>
);
}
export default Welcome;A few rules to remember: component names start with a capital letter, a component must return a single parent element, JSX uses className instead of class, and you can embed JavaScript expressions inside curly braces, for example <h1>Hello, {name}</h1>.
Step 4: Plan the site and create components
For a small business or portfolio site, you might need a header with navigation, a footer, and pages for Home, About, Projects and Contact. Create a src/components folder for shared pieces such as Header.jsx and Footer.jsx, and a src/pages folder for each page. Keeping components small and focused makes them easier to reuse and test.
Step 5: Pass data with props
Props let a parent component send data to a child. A reusable card component can display any project:
function ProjectCard({ title, description, link }) {
return (
<article className="card">
<h3>{title}</h3>
<p>{description}</p>
<a href={link}>View project</a>
</article>
);
}To show a list, keep your data in an array and render it with map, giving each item a unique key so React can track it efficiently:
const projects = [
{ id: 1, title: "Weather App", description: "Live forecasts.", link: "#" },
{ id: 2, title: "Task Tracker", description: "Plan your day.", link: "#" },
];
function Projects() {
return (
<div>
{projects.map((p) => (
<ProjectCard key={p.id} {...p} />
))}
</div>
);
}Step 6: Add interactivity with state
State is data that changes over time and makes the interface update. The useState hook creates it. Here is a simple mobile menu toggle:
import { useState } from "react";
function Header() {
const [open, setOpen] = useState(false);
return (
<header>
<button onClick={() => setOpen(!open)}>
{open ? "Close" : "Menu"}
</button>
{open && <nav>...links go here...</nav>}
</header>
);
}Never change state directly. Always use the setter function, so React knows to re-render.
Step 7: Fetch data with useEffect
To load data from an API when a component appears, use the useEffect hook with the browser's fetch function:
import { useEffect, useState } from "react";
function Posts() {
const [posts, setPosts] = useState([]);
useEffect(() => {
fetch("https://jsonplaceholder.typicode.com/posts?_limit=5")
.then((res) => res.json())
.then(setPosts);
}, []);
return (
<ul>
{posts.map((p) => <li key={p.id}>{p.title}</li>)}
</ul>
);
}The empty array at the end means the effect runs once, after the first render. In a real project, also handle loading and error states, so visitors are never left with a blank screen.
Step 8: Add multiple pages with React Router
A React app built with Vite is a single-page application, so you need a router to show different pages at different URLs. Install React Router with npm install react-router-dom, then define your routes:
import { BrowserRouter, Routes, Route, Link } from "react-router-dom";
function App() {
return (
<BrowserRouter>
<nav>
<Link to="/">Home</Link>
<Link to="/about">About</Link>
<Link to="/contact">Contact</Link>
</nav>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
<Route path="/contact" element={<Contact />} />
</Routes>
</BrowserRouter>
);
}Use the Link component instead of ordinary anchor tags for internal navigation, because it changes the page without a full reload. Check the React Router documentation for the current recommended setup, since the library has evolved across versions.
Step 9: Style your website
You have several good options, and none is wrong:
Plain CSS or CSS Modules: simplest, and CSS Modules scope styles to a component to avoid clashes.
Tailwind CSS: a utility-first framework that lets you style directly in markup and has an official Vite integration.
Component libraries: tools such as Material UI or shadcn/ui provide ready-made, accessible components.
Whichever you choose, design mobile first, use semantic HTML elements such as header, main and footer, and make sure colour contrast and keyboard navigation work.
Step 10: Handle forms
For a contact form, use controlled inputs where state holds each value. A React form cannot send email by itself, because the browser cannot safely hold email credentials. Send the data to a back-end endpoint or a form service, and validate input on both the client and the server. Keep secrets such as API keys out of front-end code, since anything shipped to the browser can be read by visitors.
Step 11: Make it fast and discoverable
Code split pages with
React.lazyso visitors download only what they need.Optimise images and give them dimensions.
Set page titles and descriptions for each route. The important caveat is that a purely client-rendered React app sends mostly empty HTML to crawlers first. Google can render JavaScript, but if SEO is central to your project, such as a blog or shop, choose a framework with server-side rendering or static generation, like Next.js or Astro with React.
Step 12: Build and deploy
When you are ready to publish, run npm run build. Vite creates an optimised production build in the dist folder. You can host that folder on any static host. Popular free choices include Cloudflare Pages, Netlify, Vercel and GitHub Pages. Connect your Git repository, set the build command to npm run build and the output directory to dist, and the platform deploys automatically on every push. For apps with client-side routing, configure a fallback so that any URL returns index.html, otherwise refreshing a page such as /about will produce a 404 error.
Common mistakes beginners make
Mutating state directly rather than using the setter function.
Forgetting the
keyprop in lists, or using the array index when items can be reordered.Putting everything in one giant component instead of splitting it up.
Fetching data in an effect without handling loading, errors or cleanup.
Storing secrets in front-end code.
Reaching for a heavy state management library before it is truly needed. React's built-in state and context are enough for most small sites.
Where to go next
Work through the official tutorial and learning guides at react.dev.
Learn TypeScript, which catches many errors before you run the code.
Try a framework such as Next.js once you understand the fundamentals.
Build two or three real projects, such as a portfolio, a to-do app and a small dashboard that uses an API.
Final thoughts
Building a website with React is a matter of thinking in components: small pieces of interface that receive data, manage their own state and combine into pages. Start with Vite, practise with props, state and routing, and deploy early so you can see your work live. The more small projects you finish, the faster the concepts will click.
- javascript
- react
- vite
- web development