This tutorial explains how to create and configure a custom 404 error page for your Netlify-hosted applications, ensuring it replaces Netlify’s default 404 page.

Step 1: Create a Custom 404 Page

  1. Design Your 404 Page

    Create a file named 404.html in the root of your project’s publish directory (often public, build, or dist, depending on your framework).

    This file will serve as your custom 404 page and will be automatically picked up by Netlify for any unresolved paths.

    Example content for 404.html:

    404 - Page Not Found

    404 - Page Not Found

    Sorry, the page you're looking for doesn't exist.

    Return to Home

  2. Customize as Needed

    Add your branding, styles, or links to match your site’s design.

    For SPAs (e.g., React, Vue, Next.js), you can use a framework-specific component (e.g., 404.js for Next.js) or generate a static 404.html during the build process.

Step 2: Place the 404 Page in the Correct Directory

Step 3: Configure Redirects for SPAs (Optional)

For SPAs, client-side routing can cause 404 errors when users refresh or directly access routes (e.g., yoursite.com/about). To handle this, configure Netlify to redirect all unmatched routes to your index.html while ensuring the custom 404 page is served for truly invalid routes.

Step 4: Deploy to Netlify

  1. Push Changes to Your Repository

    Commit your 404.html (or framework-specific 404 file) and _redirects or netlify.toml file to your Git repository.

    Ensure your build command (e.g., npm run build) generates the necessary files in the publish directory.

  2. Configure Netlify Build Settings

    In the Netlify dashboard, go to your site’s “Deploys” settings.

    Verify the build command (e.g., npm run build) and publish directory (e.g., build/ or public/).

    Deploy your site by pushing changes to your connected Git repository or manually uploading the publish directory.

  3. Test the Deployment

    Navigate to a non-existent route (e.g., yoursite.netlify.app/does-not-exist).

    Confirm that your custom 404 page is displayed instead of Netlify’s default 404 page.

Step 5: Test and Troubleshoot

Step 6: Optional Enhancements

Notes

By following these steps, you’ll have a custom 404 page that aligns with your brand and provides a better user experience than Netlify’s default 404 page.

Comments

Approved comments appear below. Log in once with GFAVIP — it applies across the whole site. GFAVIP login

View comments archive