Gatsby Tutorial
Learn Gatsby step by step: 36 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is Gatsby? Learn what Gatsby is, how it turns React components and data into fast static pages, when to choose it, and how a build differs from a runtime server.
- Install Gatsby and Create a Site Set up Node.js, run npm init gatsby, answer the starter questions, start the dev server and understand the scripts and dependencies of a new Gatsby 5 project.
- Gatsby Project Structure Tour a Gatsby 5 project: src/pages, src/components, static, gatsby-config, gatsby-node, gatsby-browser, gatsby-ssr, and the .cache and public build folders.
- The Gatsby CLI and Dev Server Learn the Gatsby CLI: gatsby develop, build, serve, clean, useful flags, hot reloading, GraphiQL, environment variables, caching and incremental builds explained.
- gatsby-config and the Node APIs Configure a Gatsby site with siteMetadata and plugins, then hook into the build with gatsby-node APIs such as onCreateNode, createPages and sourceNodes.
Pages and Routing
- Pages and File System Routing Create Gatsby pages from files in src/pages, learn how file names map to URLs, nested folders, index and 404 pages, the Head API and the File System Route API.
- Dynamic Routes and Client-Only Pages Handle URLs that are not known at build time in Gatsby: client-only routes with [id].js and [...].js, matchPath, the params prop, and how to fetch data in the browser.
- Link and Navigation Navigate a Gatsby site with the Link component, active styling, partiallyActive, state, navigate() for code-driven redirects, prefetching and external links.
- Layouts and Shared Components Share headers, footers and structure across Gatsby pages with layout components, wrapPageElement, wrapRootElement, children props and Gatsby 5 slices explained.
- Styling in Gatsby Style a Gatsby site with global CSS, CSS Modules, Sass, CSS-in-JS and Tailwind. Learn how scoping works, where to import styles and how to avoid unstyled flashes.
GraphQL Data Layer
- GraphQL Basics in Gatsby Understand the GraphQL data layer in Gatsby: nodes, fields, arguments, aliases, fragments and how a query returns exactly the shape of data your component asks for.
- Page Queries and useStaticQuery Get data into Gatsby components with page queries, query variables from page context, the useStaticQuery hook and StaticQuery, and learn when to use each one.
- GraphiQL and the Data Layer Use the GraphiQL explorer at /___graphql to discover your Gatsby schema, then master filter operators, sort, limit, skip, distinct and group in plural queries.
- Creating Pages Programmatically Generate Gatsby pages from data with createPages, onCreateNode slugs, page templates, context variables, pagination and tag pages, with runnable stand-ins.
Source and Transformer Plugins
- Source Plugins and gatsby-source-filesystem Bring data into Gatsby with source plugins: configure gatsby-source-filesystem, query File nodes, source several folders, and meet CMS and API source plugins.
- Transformer Plugins Learn how Gatsby transformer plugins turn File nodes into content nodes: gatsby-transformer-remark, JSON, YAML, CSV and sharp, with parent and child node relationships.
- Creating Nodes with sourceNodes Write your own Gatsby source with the sourceNodes API: createNode, createNodeId, contentDigest, caching, touching nodes, relations between nodes and fetching a REST API.
- Schema Customization Control the Gatsby GraphQL schema with createSchemaCustomization: type definitions, defaults, @link, @dontInfer, @dateformat and createResolvers to avoid missing-field errors.
Images and Performance
- StaticImage: Optimized Images Without GraphQL Use the StaticImage component from gatsby-plugin-image to resize, convert and lazy-load local or remote images at build time, with props explained.
- Dynamic Images with GatsbyImage and GraphQL Load images from files, Markdown front matter or a CMS with gatsbyImageData queries, getImage and the GatsbyImage component, plus art direction.
- Image Formats, Layouts and Placeholders Choose between WebP, AVIF and JPEG, constrained, fixed and full-width layouts, and blurred or dominant-color placeholders to balance speed and quality.
- Performance: Lighthouse, Code Splitting and Prefetching Understand how Gatsby keeps sites fast: per-page code splitting, link prefetching, Lighthouse metrics, font and script loading, and bundle analysis.
Markdown and MDX Sites
- Markdown Blog Pages with gatsby-transformer-remark Turn Markdown files into blog pages: source them from disk, parse front matter and HTML with remark, create slugs in onCreateNode and pages in createPages.
- MDX in Gatsby: Components Inside Markdown Set up gatsby-plugin-mdx, write MDX with React components and imports, map HTML elements to your own components, and render MDX pages with a template.
- Front Matter, Tag Pages and Pagination Group posts by tag, build one page per tag, split long lists into numbered pages with skip and limit, and add previous and next links in Gatsby.
- SEO in Gatsby: Head API, Sitemap and RSS Add titles, meta tags and structured data with the Gatsby Head API, then generate sitemaps, RSS feeds and robots.txt so search engines and readers find you.
Rendering Modes and Functions
- Rendering Modes: SSG, DSG and SSR in Gatsby Compare static generation, Deferred Static Generation and server-side rendering in Gatsby, with getServerData and defer examples and a guide to choosing.
- Gatsby Functions: Serverless API Routes Create API endpoints in src/api with Gatsby Functions: handlers, dynamic routes, methods, JSON bodies, environment variables, CORS and form handling.
- Client-Only Routes and Authentication in Gatsby Build dynamic app areas inside a static Gatsby site: client-only routes with splat pages, private routes, login state, tokens and where to fetch user data.
- Build Caching and Incremental Builds Understand the .cache and public folders, why builds slow down as sites grow, how to reuse caches in CI, and ways to cut Gatsby build times.
Deployment and Migration
- Deploying Gatsby Sites: Hosts, Env Vars and Path Prefixes Build and deploy a Gatsby site to Netlify, Vercel, Cloudflare Pages or GitHub Pages, manage environment variables safely and set a path prefix correctly.
- Redirects, Headers and Custom 404 Pages in Gatsby Move URLs safely with createRedirect, set cache and security headers, build a useful 404 page and handle trailing slashes in a Gatsby site.
- Upgrading Gatsby and Migrating to Another Framework Plan a Gatsby major upgrade, judge the project's maintenance status honestly, and map Gatsby concepts to Next.js and Astro for a safe, step-by-step migration.
Projects and Practice
- Project: Build a Markdown Blog with Gatsby Plan and build a complete Gatsby blog: folder layout, config, slugs, templates, tags, pagination, images and SEO, with a runnable build-pipeline simulation.
- Project: Portfolio Site with a Contact Function Build a fast Gatsby portfolio: project data from JSON, optimized images, a filterable grid, and a serverless contact function with validation and spam protection.
- Practice: Gatsby Exercises and Review Sharpen your Gatsby skills with runnable exercises on slugs, pagination, image widths and redirects, a debugging checklist, and interview-style review questions.