A red and white lifebuoy with a rope floating on clear turquoise water

Front-End Fallbacks: Keeping Your Website Working When Things Break

Picture a visitor on an ageing tablet, a patchy train connection or a locked-down office laptop. They land on your site, a script fails to arrive, and the booking form simply never appears. No message, no explanation, just an empty gap where the important bit should be. Most of the time they won’t complain. They’ll just leave.

Modern websites lean on a long chain of moving parts: frameworks, third-party scripts, brand-new CSS features and browser APIs. When any link in that chain breaks, a well-planned fallback is the difference between a slightly plainer page and a broken one.

In brief:

  • A fallback decides what happens when a feature is missing; progressive enhancement decides what extra people get when it is present.
  • Robustness is one of the four core principles behind the Web Content Accessibility Guidelines, so this is an accessibility issue as well as a technical one.
  • HTML, CSS and JavaScript each have simple, built-in ways to provide a safety net.
  • Sometimes the best fallback is a helpful message; sometimes it is showing nothing at all.
Raindrops on a clear umbrella with a blurred green forest behind it

Fallbacks or progressive enhancement?

The two ideas are close cousins, but they face in opposite directions. Progressive enhancement looks forward: build a solid baseline, then layer on newer features for browsers that can handle them. Fallbacks look backwards: assume something will eventually fail and decide in advance what the visitor sees when it does.

Go Ad Free

You don’t have to pick one. A sensible approach is to treat progressive enhancement as the guiding principle for every build, then add fallbacks wherever a failure would hurt.

Know what you’re relying on

Before a shiny new feature goes anywhere near a live site, it pays to check how widely it is supported. The cross-browser Interop effort, which has run since 2023, gives a broad picture of what the major browser makers are shipping together. Baseline labels tell you how long an individual feature has been available everywhere, and Can I Use offers a quick support table for almost anything.

One caution: Baseline does not track whether the accessibility side of a feature works properly across browsers. A feature can be “widely available” and still behave poorly for screen reader users, so test with real assistive technology where it matters.

When JavaScript doesn’t turn up

Scripts fail for all sorts of reasons: a flaky network, an aggressive ad blocker, a corporate firewall, a browser extension or a simple error in a third-party file. If a whole application depends on JavaScript, a total failure should send people to a clear, friendly error page that explains what went wrong and what they can do next. Many site generators and frameworks let you design custom 404 and 500 pages for exactly this reason.

For individual components, the long-supported <noscript> element lets you offer an alternative in place. Here’s a simple version for an online booking panel:

<noscript>
  <div class="booking-fallback">
    <h2>Book an appointment</h2>
    <p>Our live booking calendar needs JavaScript,
       which isn't running in your browser right now.
       You can still book by phone or email, and
       we'll confirm your slot the same day.</p>
  </div>
</noscript>

<div id="booking-calendar"><!-- calendar loads here --></div>

A nice touch is a pre-filled email with a short reference code in the subject line, so whoever picks it up knows exactly which part of the site let the visitor down.

Go Ad Free
An orange detour sign with a pedestrian symbol and an arrow pointing right, standing on a pavement

Letting CSS test the water

CSS already ignores rules it doesn’t understand, but the @supports rule gives you proper control. Write dependable styles first, then wrap the newer approach in a feature query. Combining conditions with and means the new code only runs when every piece it needs is available:

/* Works everywhere */
.card-list {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

/* Only where grid and subgrid are both supported */
@supports (display: grid) and (grid-template-rows: subgrid) {
  .card-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  }
  .card {
    display: grid;
    grid-row: span 3;
    grid-template-rows: subgrid;
  }
}

There’s a bonus here too. Each feature query doubles as a note to your future self. A year or two later, search the stylesheet for @supports and you’ll quickly see which workarounds can finally be retired.

Feature-checking in JavaScript

Before calling a newer browser API, check that it exists. A plain if...else is all it takes. This share button uses the native share sheet where possible and quietly copies the page address everywhere else:

shareButton.addEventListener('click', async () => {
  if (navigator.share) {
    await navigator.share({ title: document.title, url: location.href });
  } else {
    await navigator.clipboard.writeText(location.href);
    shareButton.textContent = 'Link copied';
  }
});

In component-based frameworks, a conditional (ternary) expression does the same job for whole chunks of interface. If the data a component needs never arrives, you can render a helpful notice instead, or render nothing at all if the component isn’t essential. Which is right depends on how much the visitor would miss it.

A real-world example

Imagine a small physiotherapy clinic whose site uses a third-party booking widget. One morning the provider has an outage. Without a fallback, every visitor sees a blank box and assumes the clinic isn’t taking appointments. With one, they see a short note explaining that online booking is temporarily unavailable, along with the phone number and opening hours. Same outage, very different outcome for the business.

None of this takes much time to build. The hard part is remembering to ask the question at the planning stage. So, for the most important page on your own site: what does a visitor see when the clever bits don’t load?

Go Ad Free

Create a free account, or log in.

Gain access to read this article, join developers who build better, faster, smarter solutions

Yes! I would like to receive new content and updates.

Scroll to Top