Understand the idea

A static website serves prepared files rather than building every page from a database at request time. A build step can still generate those files from shared templates.

The browser requests a URL, receives an HTTP response, parses HTML and requests referenced assets. Directory URLs often map to index.html, but the exact mapping belongs to the host. A missing page should return a 404 status as well as a useful message.

Read the example

This is a directory layout, not code to paste into an HTML document.

Text · EXAMPLE
my-site/
  index.html
  about/
    index.html
  assets/
    style.css
  404.html

A small mistake, explained

What goes wrong

Returning the home page with status 200 for every unknown URL makes errors look like successful pages.

How to fix it. Configure and test the host’s missing-page behaviour. A file named 404.html alone is not proof that every host will use it correctly.

Try it yourself

Open a known page and a deliberately nonexistent URL. Compare their response status in the Network panel.

Further reading

MDN — 404 Not Found

Original explanation and example prepared for HTML code FYI with AI assistance. Test the code in your own context. How these guides are made.