← Back to React Course | Chapter 14: Performance & Production Deployment | Lesson 13 of 13

SEO Basics for React SPAs

SEO for a React app is like making sure your store has clear signs out front so search engines (and customers) can actually find and understand what's inside, even from far away.

Why Client-Side Rendering Can Hurt SEO

A plain client-side React app's initial HTML is often just an empty <div id=root></div> — the actual content only appears after JavaScript runs. While major search engines have improved at executing JavaScript, this extra step can still affect indexing speed and completeness compared to content that's already in the initial HTML.

Note: For content-heavy, SEO-critical pages (like a blog or marketing site), server-side rendering or static generation (via a framework like Next.js) is the more reliable choice.

Warning: Not every crawler (search engines, social media link previews, some bots) executes JavaScript equally well — pure client-side rendering is a real risk for SEO-sensitive pages.

Managing Page Titles and Meta Tags

Each distinct page in a single-page app should still have its own unique, descriptive <title> and meta description — both important signals for how search engines and shared links represent that specific page. A library like react-helmet-async lets you set these dynamically per route.

Note: Write titles and descriptions that describe that SPECIFIC page's content, not one generic title reused across every route.

Warning: Leaving every page with the same default <title> (like just the app's name) makes it much harder for search engines and users to distinguish between different pages in search results.

Example: Managing Page Titles and Meta Tags

markup
// Run in your local React project (npm install required)
import { Helmet } from 'react-helmet-async';

function ProductPage({ product }) {
  return (
    <div>
      <Helmet>
        <title>{product.name} - My Store</title>
        <meta name="description" content={product.summary} />
      </Helmet>
      <h1>{product.name}</h1>
    </div>
  );
}

⚠️ This example uses an npm package with no CDN build available here — run this in your local React project.

Semantic HTML Helps SEO Too

The same semantic HTML practices that help accessibility — using a real <h1> for the main heading, <nav> for navigation, <main> for primary content — also help search engines understand a page's structure and importance hierarchy, since crawlers use these same signals to interpret content.

Note: A page should generally have exactly one <h1>, clearly describing that page's main topic, with <h2>/<h3> used for logical subsections.

Warning: Using generic <div> elements for everything (instead of semantic tags) gives search engines much weaker signals about your page's actual structure and importance.

Example: Semantic HTML Helps SEO Too

markup
<!DOCTYPE html>
<html>
<head>
  <script src="https://unpkg.com/react@18/umd/react.development.js"></script>
  <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
  <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body>
  <div id="root"></div>
  <script type="text/babel">
function ArticlePage() {
  return (
    <main>
      <h1>How React Works</h1>
      <nav aria-label="Table of contents"><a href="#intro">Introduction</a></nav>
      <h2 id="intro">Introduction</h2>
      <p>React is a JavaScript library for building UIs.</p>
    </main>
  );
}
ReactDOM.createRoot(document.getElementById('root')).render(<ArticlePage />);
  </script>
</body>
</html>
Common Mistakes
  1. Relying entirely on client-side rendering for content that needs to be indexed, since some crawlers may not fully execute JavaScript.
  2. Forgetting to set a unique, descriptive <title> and meta description for each page in a multi-page app.
  3. Not providing meaningful alt text and semantic HTML, which also affects how search engines understand page content.
Chapter Summary
  • A pure client-side-rendered React app can be harder for search engines to index well than a server-rendered page.
  • Server-side rendering or static generation (like via Next.js) produces real HTML content crawlers can read immediately.
  • Each page needs a unique, descriptive <title> and meta description, managed dynamically in a single-page app.
  • Semantic HTML and proper heading structure (h1, h2...) help both accessibility and SEO simultaneously.
Browser Support

No React-version restriction — SEO depends on rendering strategy and semantic markup, not a specific React API.

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.