Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

JSON-LD 404 Error Block for React

A full-height 404 page for a hiking-routes site with a search form, three quick links and, beside it, the page source search engines read: the 404 response line, a noindex tag and JSON-LD with a SearchAction.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

Show what a 404 page tells search engines, next to what it tells people, with this JSON-LD 404 block for React with Base UI. It's the not-found page of Stilebrook, a hiking-routes site: the page's rails run its full height and one band crosses the screen between two rules with a plus mark at each end. At the start is an ordinary 404: the numerals, the heading, one sentence, a Field with an Input and a Shine Button that searches the routes, the only colored control, and three quick links. At the end, in a framed panel with plus marks on its corners, "What search engines read" shows the page source in numbered lines: the response line HTTP/1.1 404 Not Found, marked with an edge at its start, the noindex robots meta tag, and typed JSON-LD for a WebSite whose SearchAction matches the visible form. Copy puts the JSON-LD on your clipboard. On a phone the panel sits under the form and scrolls inside itself. It's built from Field, Input, Shine Button, Copy Button and Guides. For sites that want their 404 to be searchable and honest with crawlers.

FAQ

What stays local, and what is real?

Searching stays local: sending the form checks that the query isn't empty, then says what a real one would do ("Would search for ... Searching is not wired in this demo"). Nothing is sent. Copy is real: it writes the JSON-LD text to your clipboard, and says so for screen readers, or says it couldn't if your browser refuses, which it does on a page that isn't served over HTTPS. To wire the search, send the visitor to SEARCH_PATH with the query in the q field, which is what the form's action and method="get" do by themselves if you remove the submit handler.

Why is the JSON-LD shown but not emitted?

It's a sample of what to put in your page's head, not a script this block adds: a block renders inside the page body, while structured data belongs in the head, where your framework's metadata or layout code puts it. Copy the lines and add them to your head in your framework's way, such as a script element of type application/ld+json in the layout, with the real host and search address in place of Stilebrook's.

Does the markup match the form?

Yes, by construction. SEARCH_PATH and SEARCH_FIELD are typed once: the form's action and the input's name use them, and so does the SearchAction target in the source panel (/search?q={search_term_string}). If you change the search address, change the constant and the panel follows. Google stopped showing the sitelinks search box in late 2024, but the SearchAction markup is still valid schema.org for other consumers.

Is noindex enough for a 404?

No: it's a safeguard, not the fix. The page has to answer with a 404 status, which crawlers treat as "remove this address from the index" over time; a page that answers 200 and says "not found" is a soft 404 that noindex only partly rescues. The block can't set the status, so render it from your framework's not-found route. It shows both lines because the status and the tag are the two things a crawler reads first.

Is the page source usable with a keyboard?

Yes. The panel's scroll region is a tab stop named "Page source, numbered lines", so the arrow keys scroll it sideways and down once it has focus, and the line numbers are hidden from assistive technology so they aren't read in the middle of the code. The Copy button is named "Copy the JSON-LD". The code stays left to right in a right-to-left page.

How does it look on a phone?

The form comes first with its search button full width, so the way forward is on the first screen. The source panel follows, shorter and scrolling inside itself both ways, so a long line never widens the page.

  • Pro

    A full-height 404 page for a knitting-pattern library: the display 404, a heading that names the missing address, an inline command list in a framed panel that shows five popular pages and filters ten as you type, and one button to the homepage.

  • Pro

    A split 404 page for a developer blog host: the failed address in an editable field with its words as chips, and eight typed articles ranked by shared words with one letter of typo allowed, the matched words marked, re-ranking as you edit.

  • Pro

    A full-height 404 page for a documentation host: the headline and a link home at the start, the whole site's sitemap as a keyboard-walkable tree at the end, with a divider between.

  • Pro

    A full-height 404 page for a notes app with only the display numerals, a heading, one sentence that names the missing address as typed text, and one link back to the docs.

  • Pro

    A full-height 404 page for a bookkeeping app whose picture is the way back: a drawn filing drawer with three folders that are links and one dashed slot for the missing page.

  • Pro

    A full-height 404 page for a kids' language app where three digit tiles drop onto a rule one after the other with a small overshoot, in CSS only, and a button replays the drop.