Skip to content

404 Page with Background Photo

Full-screen Tailwind CSS 404 not found page over a mountain photo with a dark gradient overlay, outlined 404, home and back buttons and quick links.

Also known as: 404 error page, page not found design, not found page with image, error page with photo, custom 404 page

404 Page with Background Photo live demo

Open in new tab

Tailwind CSS code (HTML, CSS, JS)

A full-screen 404 page built with Tailwind CSS that places the "page not found" message over a dramatic photo of mountain peaks above a sea of clouds. An outlined "404", a short on-theme message, a primary "Back to home" button, a "Previous page" button and a row of popular links turn a dead end into a branded moment for travel, outdoor and portfolio sites.

How it works

The root is main.nfp-page, a min-h-screen flex column with isolate and overflow-hidden. Two absolutely positioned layers sit behind the content: .nfp-photo, which loads the background image in style.css with background-size: cover, and a bg-gradient-to-r overlay that is darkest on the left where the text lives. On phones the overlay stays darker across the whole width so the text keeps its contrast over the bright sunset.

The content column holds a small header with a logo link, the .nfp-code "404" (transparent fill with -webkit-text-stroke, so the photo shows through the digits), an error pill, the #nfp-title heading, the buttons and a nav with popular links. The nfp-drift keyframes zoom the photo very slowly for a subtle sense of depth.

The script only handles [data-nfp-back]. The button starts with hidden and is shown when history.length or document.referrer indicate a previous page; a click calls history.back() and falls back to the [data-nfp-home] link if the page did not change. Without JavaScript users simply get the home link.

Customization

  • background-image in .nfp-photo (style.css): use your own photo. The current image comes from Unsplash and should be replaced with an image you own; adjust background-position to keep the focal point visible.
  • aria-label on .nfp-photo: update the description to match your new photo, or replace role="img" with aria-hidden="true" if it is purely decorative.
  • from-slate-950/90 via-slate-950/70 to-slate-950/40 (and the sm:via-slate-950/60 sm:to-slate-950/10 desktop values) on the overlay: raise the opacities for brighter photos or use bg-gradient-to-t for a bottom-up fade.
  • bg-orange-300 on the home button and text-orange-200 on the pill: switch to sky or emerald to match your brand.
  • -webkit-text-stroke in .nfp-code: thicken the outline, or remove the rule for solid white digits.
  • nfp-drift 24s in style.css: slow down the zoom or remove the animation entirely.
  • The links in the nav labelled "Popular pages": point them to your most visited sections.

Use cases

  • Any website: a full-screen photo and outlined 404 make a missing page look intentional
  • Content sites: home and back buttons help visitors recover quickly
  • Ecommerce stores: quick links point lost visitors to popular pages
  • Travel and outdoor brands: a mountain photo with a dark overlay fits the brand mood

Accessibility

The page is a single main labelled by the h1. The decorative "404" is aria-hidden because the pill and heading already state the error. The photo layer has role="img" with a short description, and decorative icons are aria-hidden. Every link and button shows a visible focus-visible ring, the "Previous page" button is only rendered when it can work, and the background zoom stops under prefers-reduced-motion.

Usage notes

This is a full-page template: serve it with an HTTP 404 status from your server, and use absolute URLs for links because the 404 page can appear at any path.

404 Page with Background Photo at a glance

Framework
Tailwind CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Tailwind CSS
Layout
Responsive, works on mobile, dark design
Category
Error Pages
License
Free for personal and commercial use

Questions about this template

Can I use the 404 Page with Background Photo code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Tailwind CSS from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

The Tailwind browser build is for prototyping. In production, compile Tailwind with its CLI or your bundler.

404 Page with Background Photo – free Tailwind CSS error page template
404 Page with Background Photo · free Tailwind CSS error page template

More Error Pages

500 Server Error Page – free Bootstrap 5 error page template

500 Server Error Page

Dark Bootstrap 5 500 error page with a server rack illustration, retry button, status page link, copyable reference ID and service status list.

Simple 404 Page – free Tailwind CSS error page template

Simple 404 Page

Clean Tailwind CSS 404 error page with an animated unplugged-cable illustration, site search, helpful link cards and a go-back button.

Animated 404 Page – free Pure CSS error page template

Animated 404 Page

Playful full-page 404 error template with a floating planet, short message, site search field and home link in pure CSS.