Skip to main content

Custom 404

When a page is not found, the server uses the first available 404 page in this order:

  1. .space/template/404.html
  2. The platform default 404 page

Only .space/template/404.html is used as the 404 page; a 404.html in the site root is ignored. The 404 page is returned with a 404 status, not as a normal page.

Example​

Place this file at .space/template/404.html:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>404 · Page not found</title>
<style>
body { margin: 0; min-height: 100vh; display: grid; place-items: center; font: 16px/1.6 system-ui, sans-serif; }
a { color: inherit; }
</style>
</head>
<body>
<main>
<h1>Page not found</h1>
<p><a href="/">Back to home</a></p>
</main>
</body>
</html>

Relative paths​

When you use .space/template/404.html, the 404 page is actually served from /.space/template/404.html. Relative paths inside it (./style.css, img/a.png) resolve against /.space/template/, not against the path the visitor requested.

Use absolute paths for links and assets in the 404 page (/style.css, /docs/), or put the assets under .space/template/ and reference them relatively.

Static generators​

Many static generators emit a 404.html in the build root (Docusaurus does this by default). The platform does not use it as the 404 page; move it to .space/template/404.html and handle asset paths as described under "Relative paths".

When .space is private​

If the site config sets exposeSpace to false, everything under .space/ is private except the 404 template. The template itself is still served to visitors, because it is the 404 page.


Next: Site config