Understanding Progressive Enhancement

Progressive enhancement is a development approach that begins with useful HTML content and core functionality, then adds CSS, JavaScript, and newer browser features as enhancements.

The goal is to make the essential content and tasks of a webpage available from the strongest possible foundation instead of making the entire experience depend on optional technologies working perfectly.

How Progressive Enhancement Works

Progressive enhancement treats a webpage as a set of layers. Each layer adds capability without replacing the usefulness of the layer beneath it.

  1. HTML provides content, structure, links, forms, and other core functionality.
  2. CSS improves layout, appearance, and responsive presentation.
  3. JavaScript adds optional behavior and interaction.
  4. Newer browser features can provide additional enhancements when supported.

If an enhancement is unavailable, the underlying HTML should still provide a useful experience whenever practical.

Start with HTML

The HTML layer should contain meaningful content and use the appropriate elements for links, forms, buttons, headings, navigation, and document structure.

<a href="/contact.html">Contact Us</a>

This link works without CSS or JavaScript. Styling can make it look different, and JavaScript can enhance its behavior, but the basic navigation remains available through HTML.

Starting with functional HTML gives the webpage a dependable foundation before additional technologies are added.

Add CSS for Presentation

CSS can improve the visual presentation of the HTML without changing the underlying meaning or basic function of the content.

<a href="/contact.html" class="contact-link">Contact Us</a>
.contact-link {
  display: inline-block;
  padding: 10px 16px;
  text-decoration: none;
}

If the stylesheet fails to load or a particular CSS feature is unsupported, the HTML link can still function.

This separation allows presentation to enhance the experience without becoming the only way the content can be understood or used.

Add JavaScript for Behavior

JavaScript can add richer interactions while keeping the underlying HTML usable when scripting is unavailable or fails.

<a href="/details.html" id="details-link">View Details</a>

JavaScript could enhance this link by loading the details into a dialog or updating part of the current page.

const link = document.querySelector("#details-link");

link.addEventListener("click", function(event) {
  event.preventDefault();
  // Load the details without leaving the page.
});

If the script does not run, the visitor can still follow the normal link to /details.html.

The JavaScript provides a better experience when available without removing the basic HTML behavior.

Use Feature Detection

When an enhancement depends on a browser feature, test whether the required capability exists before trying to use it.

if ("geolocation" in navigator) {
  // Offer automatic location detection.
} else {
  // Keep the manual location option available.
}

Feature detection is more reliable than assuming a capability exists because of a browser name or version.

The fallback should remain useful when the enhancement is unavailable.

Progressive Enhancement with Forms

HTML forms are a good example of progressive enhancement because the form itself can provide the essential functionality while JavaScript adds convenience.

<form action="/contact.php" method="post">
  <label for="email">Email</label>
  <input type="email" id="email" name="email" required>

  <button type="submit">Send</button>
</form>

The form can submit normally to the server without JavaScript.

JavaScript could later add features such as inline feedback, character counters, conditional fields, or asynchronous submission, but those enhancements should not unnecessarily remove the form's basic ability to submit.

This also makes the server-side form handler the dependable foundation rather than making successful submission depend entirely on client-side scripting.

Navigation should begin with real HTML links so visitors can move between pages using the browser's normal navigation system.

<nav aria-label="Main navigation">
  <ul>
    <li><a href="/">Home</a></li>
    <li><a href="/services.html">Services</a></li>
    <li><a href="/contact.html">Contact</a></li>
  </ul>
</nav>

CSS can transform this list into a horizontal menu, mobile navigation, or another layout. JavaScript can add menu toggles and other interactions.

The important point is that the underlying links continue to identify real destinations rather than existing only as JavaScript controls.

Progressive Enhancement with Web APIs

Many browser APIs are excellent candidates for progressive enhancement because they provide useful capabilities that may depend on support, permissions, hardware, or user settings.

For example, a website could allow a visitor to type a location manually and then offer geolocation as an optional convenience.

<label for="location">Location</label>
<input type="text" id="location" name="location">

<button type="button" id="detect-location">Use My Location</button>

If geolocation is available and the visitor grants permission, JavaScript can fill the location automatically. If not, the text field remains available.

The enhancement saves effort without making the browser API the only way to complete the task.

Build for Resilience

Webpages operate in environments that developers cannot completely control. Resources can fail to load, scripts can encounter errors, browser capabilities differ, extensions can interfere with pages, and network connections can be slow or unreliable.

Progressive enhancement accepts this reality by avoiding unnecessary single points of failure.

A useful question to ask while building a feature is: What happens if this enhancement does not work?

If the answer is that the visitor loses access to essential content or cannot complete an important task, consider whether a stronger HTML foundation or alternative path can be provided.

Progressive Enhancement and Graceful Degradation

Progressive enhancement and graceful degradation are related approaches, but they begin from different directions.

Approach General Idea
Progressive enhancement Begin with a dependable core experience and add enhancements when capabilities are available.
Graceful degradation Begin with a more advanced experience and provide acceptable behavior when parts of it are unavailable.

Both approaches try to keep a website usable under different conditions, but progressive enhancement places particular emphasis on establishing the basic content and functionality first.

Common Progressive Enhancement Mistakes

Mistake Better Approach
Using JavaScript for navigation when a normal link would work Start with an a element and enhance it only when needed.
Making a form depend entirely on JavaScript submission Provide a functional server-side form action when practical.
Hiding essential content until a script runs Include important content in the HTML whenever possible.
Assuming every browser supports a newer API Use feature detection and provide an alternative.
Making an optional enhancement the only way to complete a task Keep a dependable core method available.
Trying to reproduce every enhancement in unsupported environments Preserve essential content and functionality without requiring identical experiences.

Best Practices

  • Start with meaningful, functional HTML.
  • Use real links for navigation whenever navigation is the intended action.
  • Build forms that can perform their core task without unnecessary dependence on JavaScript.
  • Use CSS to enhance presentation without changing the underlying meaning of the content.
  • Add JavaScript when it provides useful behavior rather than replacing working HTML without a reason.
  • Use feature detection before depending on optional browser capabilities.
  • Provide alternatives when unsupported features would prevent an important task.
  • Keep essential content available even when enhancements fail.
  • Do not require every browser to provide an identical experience.
  • Test what happens when scripts, resources, permissions, or newer features are unavailable.
  • Build the dependable foundation first, then add the extras.

Summary

Progressive enhancement begins with useful HTML and adds presentation, interaction, and newer browser capabilities as additional layers. This helps preserve essential content and functionality when scripts fail, features are unsupported, permissions are denied, or network conditions interfere with enhancements.

A strong HTML foundation makes webpages more resilient and easier to maintain across changing browsers and technologies. Next, we will finish the Best Practices section with an HTML Best Practices Checklist that brings the major recommendations together in one place.