Custom Error Rules, Error Pages and Stored Assets
How Cloudflare Custom Errors work: Error Pages vs rules, edge assets, precedence, tokens, size limits, and how to configure and verify them.
This page summarises Cloudflare Custom Errors documentation: how to replace default error and challenge pages with Error Pages, Custom Error Rules, and custom error assets on paid plans, including what takes priority and common configuration limits.
Custom Errors: what visitors see when HTTP errors occur
Section titled “Custom Errors: what visitors see when HTTP errors occur”Custom Errors let you show your own content when an HTTP error happens—whether the response comes from your origin, a Cloudflare product (including Workers), or a security challenge.
Use Custom Errors to replace default Cloudflare error pages with your own custom content. Custom error content is shown to visitors when an HTTP error occurs, whether the error comes from your origin server, a Cloudflare product (including Cloudflare Workers), or a security challenge.
— Cloudflare, Custom Errors
You can configure content in two main ways:
| Method | What it does |
|---|---|
| Error Page | HTML for a specific error or challenge type (for example WAF block, 500 class, rate limit). Zone or account level; zone wins over account. |
| Custom Error Rule | Conditional rule in the http_custom_errors phase: when matched, serves inline or stored content for errors with status 400 and above (with documented exceptions for “all requests” matching). |
Custom Errors require proxied DNS for the hostname. They are generally available on all paid plans and are managed from Rules > Overview (rules) and Rules > Settings (assets), with the dashboard UI described in the GA announcement.
Error Pages vs Custom Error Rules: which to use
Section titled “Error Pages vs Custom Error Rules: which to use”Error Pages: branded HTML per error type
Section titled “Error Pages: branded HTML per error type”Error Pages (formerly “Custom Pages”) are the right tool when you want one custom HTML page per fixed error page type—for example WAF block (waf_block), rate limiting block (ratelimit_block), or 1000 class errors (1000_errors).
You can define custom Error Pages for the following errors and challenges: WAF block, IP/Country block, IP/Country challenge, 500 class errors, 1000 class errors, Managed challenge / I’m Under Attack Mode, Rate limiting block.
— Cloudflare, Edit Error Pages
Use Error Pages to customise challenge pages or the default WAF block page. Custom Error Rules do not replace security actions from Cloudflare products such as the default WAF block page—they target origin errors and similar responses (see precedence below).
Custom Error Rules: conditional responses by status or expression
Section titled “Custom Error Rules: conditional responses by status or expression”A custom error rule defines when to serve custom content and what to serve (inline body or a stored asset). Rules use the Ruleset Engine (http_custom_errors phase, action serve_error).
A custom error rule defines the conditions under which Cloudflare will serve custom error content to visitors in case of HTTP errors (status codes 400 and above), and the exact content that will be served to visitors.
— Cloudflare, Custom Errors
Match on http.response.code, Accept, paths, or Cloudflare-specific fields such as cf.response.1xxx_code for 1XXX errors (see below). Inline responses are capped at 10 KB; assets are stored at the edge after fetch (parameters).
When to choose rules: different bodies for API vs browser, override status codes, target specific 5xx/1xxx codes, or reuse a fetched HTML asset across several conditions. When to choose Error Pages: one static branded page per built-in error/challenge type without expression logic.
Precedence: what wins when several settings exist
Section titled “Precedence: what wins when several settings exist”When an error occurs, Cloudflare resolves configuration in a defined order. The first applicable match drives what the visitor sees, with important overrides for WAF block responses defined on the rule itself.
When an error of a specific type occurs, Cloudflare does the following: Search for a configured Error Page at the account level … at the zone level … Search for a matching custom error rule at the account level … at the zone level … If a security rule like a WAF custom rule or a rate limiting rule triggers a custom block response instead of a default Cloudflare WAF block page, the rule-specific block response will have priority over Error Pages or a matching custom error rule.
— Cloudflare, Custom Errors — How it works
Practical summary:
- Zone Error Pages beat account Error Pages.
- Matching custom error rule at zone level beats account rules and, for 500/1000 class cases, beats matching Error Pages (Custom Error Rules).
- Custom WAF
blockresponse in the firewall rule beats Error Pages and custom error rules. - In the
http_custom_errorsruleset, only the first matching rule runs (create rules).
Custom error assets: fetch HTML at the edge and reuse it
Section titled “Custom error assets: fetch HTML at the edge and reuse it”A custom error asset is HTML (plus inlined CSS, JS, and images) fetched from a URL you provide, minified and stored on Cloudflare’s network. After storage, the origin URL need not stay online until you refresh the asset.
When you provide a URL, Cloudflare will gather any required images, CSS, and JavaScript code and save a minified version of the full page in the Cloudflare global network. This resource is called a custom error asset, which you can use in one or more custom error rules in the same scope of the asset (zone or account).
— Cloudflare, Custom Errors
Assets can be created in the dashboard (create rules) or via the Custom Errors API. Zone-level assets use POST to zones/$ZONE_ID/custom_pages/assets; account-level endpoints mirror the same operations (common API calls).
Scope: an asset is only referenceable from rules in the same zone or account where it was stored; assets are not shared across zone vs account (beta announcement).
Size and bandwidth limits for assets
Section titled “Size and bandwidth limits for assets”Processed assets must stay within roughly 1.5 MB after inlining. Large assets are served on every matching error and can consume significant egress (size limits).
Error Pages edited through the Error Pages UI share a 1.5 MB (1,500,000 bytes) limit and must include <head> … </head> (Edit Error Pages, troubleshooting).
Error tokens: placeholders for challenges and diagnostics
Section titled “Error tokens: placeholders for challenges and diagnostics”Custom pages and inline responses can include error tokens replaced before the response is sent.
Page-specific tokens (required on certain Error Page types) include ::CAPTCHA_BOX::, ::IM_UNDER_ATTACK_BOX::, ::CLOUDFLARE_ERROR_500S_BOX::, and ::CLOUDFLARE_ERROR_1000S_BOX:: (error tokens). Challenge-related templates may also use widgets such as ::CF_WIDGET_BOX::, which is replaced for all challenge types (additional configuration).
Diagnostic tokens usable on assets, inline responses, and Error Pages:
| Token | Meaning |
|---|---|
::CLIENT_IP:: |
Visitor IP |
::RAY_ID:: |
Per-request Cloudflare ray ID |
::GEO:: |
Country or region for the IP |
External resources referenced while Cloudflare fetches an Error Page must return 200 OK during that fetch, or publishing can fail (error tokens — Error Pages).
cf.response.1xxx_code: custom pages for specific 1XXX errors
Section titled “cf.response.1xxx_code: custom pages for specific 1XXX errors”For Cloudflare-generated 1XXX errors that share an HTTP status, match the specific code with cf.response.1xxx_code:
cf.response.1xxx_codeInteger — Contains the specific code for 1XXX Cloudflare errors. Use this field to differentiate between 1XXX errors associated with the same HTTP status code. The default value is 0.— Cloudflare,
cf.response.1xxx_code
This field is only available in Response Header Transform Rules and Custom Errors (field reference). Example expression from the docs: (cf.response.1xxx_code eq 1020) with an HTML inline response (example custom error rules). Structured JSON and Markdown for 1XXX errors are noted in changelog availability posts.
Accept header: HTML Error Pages vs JSON for APIs
Section titled “Accept header: HTML Error Pages vs JSON for APIs”With Custom Error Rules on a paid plan, a matching rule’s content is served according to your rule—not only by Accept. Without a matching rule, behaviour depends on Error Pages and default structured responses:
If a Custom Error Rule matches, the rule’s content is served. If no rule matches, falls back to the Error Page (if configured) or the structured JSON response.
— Cloudflare, Error responses — Custom Error Rules configured
If a zone-wide HTML Error Page is set, it is served to all clients including those requesting JSON; to let agents receive default structured JSON or Markdown, remove the Error Page or add rules that match Accept (error responses).
Create Custom Error Rules: dashboard and API outline
Section titled “Create Custom Error Rules: dashboard and API outline”Dashboard workflow
Section titled “Dashboard workflow”From Rules > Overview, choose Create rule > Custom Error Rule, set match conditions (custom expression or all incoming requests per create rules), pick Custom error asset or an inline JSON/HTML/Text/XML response, optionally set response code 400–999, then Deploy or Save as Draft.
API workflow
Section titled “API workflow”- Optionally
POSTa custom error asset to/zones/$ZONE_ID/custom_pages/assets. - Ensure an
http_custom_errorsphase entrypoint ruleset exists (general procedure). PUTrules with"action": "serve_error"andaction_parameterscontaining eitherasset_name+content_typeorcontent+content_type(+ optionalstatus_code) tophases/http_custom_errors/entrypoint.
API tokens need Custom Error Rules > Edit at minimum (required permissions). Use ref on rules for stable IDs in Terraform (example).
WAF rules can instead return a fixed block body via action_parameters.response without using the custom errors phase (create a custom rule via API — Example B).
Validate rules before deployment (dry_run)
Section titled “Validate rules before deployment (dry_run)”Cloudflare validates expressions, actions, entitlements, and quotas before publish. The dashboard validates when you edit rules under Security > Security rules or Rules > Overview (validate rule changes before deployment).
For API changes, add dry_run=true to supported Rulesets API mutations; a dry run performs authorization and validation but does not persist configuration (API validation). Example:
curl --request POST \ "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/rulesets?dry_run=true" \ --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ --header "Content-Type: application/json" \ --data '{ "name": "Custom firewall rules", "kind": "zone", "phase": "http_request_firewall_custom", "rules": [ { "action": "block", "expression": "ip.src.country eq \"GB\"", "description": "Block requests from the United Kingdom", "enabled": true } ] }'Successful dry runs that would return 200 yield result: null (changelog).
Common mistakes when custom error pages fail
Section titled “Common mistakes when custom error pages fail”- WAF blocks Cloudflare’s fetch of your Error Page URL (for example geo block on the US), producing errors such as fetch
403/ code1202—ensure rules do not challenge the Custom Errors fetch path (troubleshooting). - Oversized pages above 1.5 MB after assets are inlined (troubleshooting — custom error page size).
- Missing required token on a challenge or 5xx/1xxx Error Page type (error tokens).
- Expecting Custom Error Rules to skin the default WAF block page—use Error Pages or a custom WAF block response instead (How it works).
- Stale Error Page content after origin changes—use Fetch custom page again in the dashboard (Edit Error Pages).
Enterprise customers can use Rule Preview on firewall rules (last 72 hours sample); it does not simulate other rules and is separate from Custom Errors fetch behaviour.
How to check this on your site
Section titled “How to check this on your site”- In the Cloudflare dashboard, open Rules > Overview and confirm Custom Error Rules are enabled, ordered correctly, and use Trace if needed.
- Under Error Pages, preview each configured page type from the Show link and confirm
stateiscustomizedvia the custom pages API when using automation. - List stored assets with
GET/zones/$ZONE_ID/custom_pages/assetsand checklast_updatedandsize_bytes. - Trigger a test error (for example a controlled
500or a known1xxxin staging) and verify body, status code, and tokens such as::RAY_ID::in the response. - You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page does not match your experience or the linked Cloudflare docs, email yimasynthetic@gmail.com with the page URL and the exact statement you want clarified or corrected.