Tutorial · cloudflare · Published 2026-08-16 · 3 min read

Custom 5xx error pages on Cloudflare

Replace the default Cloudflare 5xx error pages with your own using Error Pages, custom error rules, and the diagnostic error tokens.

Flat editorial illustration showing a planetary shield with concentric orbit rings, one radial segment glowing as a small request dot climbs.
Illustration: this article at a glance.

Two ways to customize

Cloudflare gives you two tools for replacing its default error pages, and they serve different needs.

The user-facing error pages article covers the copy guidance that applies to both routes. This page focuses on the Cloudflare mechanics.

The error tokens

Both routes support tokens that Cloudflare replaces with real values right before serving the response. On a 5xx page you should keep the diagnostic ones, because they give your support team and Cloudflare the exact facts when you troubleshoot:

TokenWhat it becomes
::CLOUDFLARE_ERROR_500S_BOX::The standard 5xx diagnostic box (error code, ray ID)
::CLOUDFLARE_ERROR_1000S_BOX::The standard 1xxx diagnostic box
::RAY_ID::The unique request ray ID
::CLIENT_IP::The visitor IP
::GEO::The visitor country or region

Keep ::CLOUDFLARE_ERROR_500S_BOX:: on a 5xx template: it is what lets you and Cloudflare support identify the exact failing request. Strip it and every 5xx looks identical to the user and to you.

Asset limits matter: a custom error asset fetched from a URL can be at most about 1.5 MB after Cloudflare inlines images, CSS and JS, and Cloudflare minifies content when it fetches an asset. An inline response is smaller still. Keep the page plain and the CSS minimal.

Build a custom error rule

  1. Prepare the page you want to serve, for example /errors/500.html on an accessible URL, containing the error tokens you need.
  2. Go to Rules > Custom errors (Cloudflare supports this on paid plans), create an asset from the URL.
  3. Create a custom error rule matching the 5xx class:
(http.response.code ge 500 and http.response.code le 599)
  1. Attach the asset to the rule and set the response code (for example 530 for all 5xx).
  2. Deploy only after saving, and test with a forced 502 against a URL you control.

For a specific error, matching a single code is cleaner than a blanket: (http.response.code eq 502). For Cloudflare-generated 1xxx errors, match on cf.response.1xxx_code.

What the errors mean

The 502 vs 523 guide and the 521 guide walk each Cloudflare error code. For a custom page, keep those codes visible even when the storytelling changes.

Prevention

Keep every custom template in the zone's source (a branch on the same repo), re-upload the asset after every design change, and always retain the ::CLOUDFLARE_ERROR_500S_BOX:: token on a public 5xx page so a real incident still reports its ray ID.

Need a website built, fixed, optimised, migrated or replaced?

This technical resource is written by CSMBAC, a small design and development studio. If you would rather hand the problem to a professional, the website service page explains how we build enquiry-ready websites.

Explore website services