Error pages

Not found, server error and maintenance pages in one card: a big figure in the accent that breaks into dots, one line and the way back.

This page is not here

The link may be old, or the page has moved.

Options

Screen
Colour

Code

import { useState } from "react";
import "./error-pages.css";

const sample = [
  {
    label: "404",
    code: "404",
    title: "This page is not here",
    text: "The link may be old, or the page has moved.",
    actions: [
      { label: "Back to home", href: "#" },
      { label: "Search the site", href: "#" },
    ],
  },
  {
    label: "500",
    code: "500",
    title: "Something broke on our side",
    text: "We have been told. Trying again in a minute usually works.",
    actions: [
      { label: "Try again", href: "#" },
      { label: "Check status", href: "#" },
    ],
  },
  {
    label: "Maintenance",
    code: "15:00",
    title: "Back at 15:00 UTC",
    text: "We are making a few changes. Nothing of yours is lost.",
    actions: [{ label: "Check status", href: "#", quiet: true }],
  },
];

/* One error page: a big quiet figure, a title, one line and its actions.
   The first action is the main one unless it is marked quiet. */
export function ErrorPage({ code, title, text, actions = [] }) {
  return (
    <div className="dh-oops-page">
      <p className="dh-oops-code" aria-hidden="true">{code}</p>
      <h2>{title}</h2>
      <p>{text}</p>
      <div className="dh-oops-actions">
        {actions.map((action, index) => (
          <a className={index === 0 && !action.quiet ? "dh-oops-main" : undefined} href={action.href} key={action.label}>
            {action.label}
          </a>
        ))}
      </div>
    </div>
  );
}

/* All the pages behind a switch, for showing them off. On a real site, render
   one ErrorPage inside the section and card and leave the switch out. */
export function ErrorPages({ pages = sample, start = 0 }) {
  const [chosen, setChosen] = useState(start);
  return (
    <section className="dh-oops">
      <div className="dh-oops-card">
        <div className="dh-oops-switch" role="group" aria-label="Which page" style={{ "--i": chosen }}>
          {pages.map((page, index) => (
            <button type="button" aria-pressed={index === chosen} key={page.label} onClick={() => setChosen(index)}>
              {page.label}
            </button>
          ))}
        </div>
        <ErrorPage key={chosen} {...pages[chosen]} />
      </div>
    </section>
  );
}

export function Example() {
  return <ErrorPages />;
}

This page is not here

The link may be old, or the page has moved.