Do URL Changes in a Single-Page App Make Sense to Screen Reader Users?

Learn how SPA URL changes affect screen reader users, when to move focus, and how to test page titles, navigation, and announcements.

Published
Reading time
7 min read
Do URL Changes in a Single-Page App Make Sense to Screen Reader Users?
On this page

Changing the URL in a single-page application (SPA) does not, by itself, tell a screen reader user that a new view is available. The browser history can change while keyboard focus and the accessibility experience remain on the previous view.

This guide shows how to coordinate the URL, document title, and focus for client-side navigation, then test the result with a keyboard and screen reader.

Key Takeaways

  • history.pushState() changes a history entry; it does not automatically announce the new content.
  • Update document.title for each view and give each view a descriptive main heading.
  • For a route that represents a new page, consider moving focus to its heading after rendering. A screen reader may then announce that heading.
  • Handle Back and Forward navigation as well as link activation.
  • Test actual behavior with a keyboard and screen reader. Avoid adding a live announcement on top of focus movement without checking for duplicate speech.

Browser History Is Not an Announcement

In a traditional navigation, the browser loads a document. In an SPA, JavaScript can instead update the current document and call history.pushState() to create a history entry. The address bar changes, but that operation does not inherently focus the new content or announce a route change.

Treat these as separate responsibilities:

ResponsibilityExample action
URL and historyCreate a history entry for the new view.
Document titleSet a meaningful document.title for the view.
FocusMove focus to an appropriate element when the change represents a new page.
AnnouncementVerify what the chosen focus strategy communicates; use a live region only if needed and tested.

Updating the title helps identify the current view, including in browser UI. Do not assume that changing the title alone will be spoken immediately by every screen reader.

Advertisement

A Client-Side Navigation Example

The following small example uses query parameters as routes. It updates the title and main content, then moves focus to the new heading after navigation. It does not use a live region: the intended announcement comes from focusing the heading, and must be verified with the screen reader being used.

Save this as index.html. From the same directory, serve it with Python:

python3 -m http.server 8000

Open the local server address shown by Python. This example requires JavaScript; its static HTML is not a complete no-JavaScript fallback. The code has not been executed in this environment.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Home | Example App</title>
</head>
<body>
  <nav aria-label="Main navigation">
    <a href="?page=home">Home</a>
    <a href="?page=reports">Reports</a>
  </nav>

  <main id="main-content">
    <h1>Home</h1>
    <p>Welcome to the example app.</p>
  </main>

  <script>
    const main = document.getElementById('main-content');
    const nav = document.querySelector('nav');

    const pages = {
      home: {
        title: 'Home',
        text: 'Welcome to the example app.'
      },
      reports: {
        title: 'Reports',
        text: 'Choose a report to review.'
      }
    };

    function renderPage({ moveFocus }) {
      const params = new URLSearchParams(window.location.search);
      const requestedPage = params.get('page') || 'home';
      const page = Object.hasOwn(pages, requestedPage)
        ? pages[requestedPage]
        : { title: 'Page not found', text: 'Choose a link in the navigation.' };

      document.title = `${page.title} | Example App`;

      const heading = document.createElement('h1');
      heading.tabIndex = -1;
      heading.textContent = page.title;

      const paragraph = document.createElement('p');
      paragraph.textContent = page.text;
      main.replaceChildren(heading, paragraph);

      if (moveFocus) {
        heading.focus();
      }
    }

    nav.addEventListener('click', (event) => {
      const link = event.target.closest('a');
      if (!link || !nav.contains(link)) return;
      if (event.defaultPrevented || event.button !== 0) return;
      if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
      if (link.target || link.hasAttribute('download')) return;

      const nextUrl = new URL(link.href);
      if (nextUrl.origin !== window.location.origin) return;

      event.preventDefault();
      if (nextUrl.href === window.location.href) return;

      try {
        history.pushState(null, '', nextUrl.href);
      } catch (error) {
        // Fall back to a normal navigation if history cannot be updated.
        window.location.assign(nextUrl.href);
        return;
      }
      renderPage({ moveFocus: true });
    });

    window.addEventListener('popstate', () => {
      renderPage({ moveFocus: true });
    });

    // Do not steal focus when the document first loads.
    renderPage({ moveFocus: false });
  </script>
</body>
</html>

What Should Happen

When you activate Reports, the URL should contain ?page=reports, the document title should become Reports | Example App, and focus should move to the Reports heading. A screen reader should have an opportunity to announce the focused heading; the exact speech depends on the browser and screen reader. No separate live-region message is generated.

Back and Forward should render the corresponding view and move focus to its heading. The initial page load deliberately leaves focus alone. Modified clicks, such as opening a link in a new tab, are left to the browser.

The heading has tabindex="-1" so JavaScript can focus it without adding it to the normal Tab sequence. Creating elements and assigning textContent also avoids treating the route value as HTML. Unknown page values render a not-found view.

This is a routing demonstration, not a complete application router. For deployment, ensure direct loads, refreshes, and new-tab navigation return the appropriate content, including any server-side routing or fallback your application needs. Consider what users should receive if JavaScript fails or is unavailable.

Choose Focus and Announcements Deliberately

Moving focus to a page heading works well when navigation replaces the main view and the user needs a clear starting point. Focus should move only after the new heading exists; asynchronous applications may need to wait until the relevant view has rendered.

A live region can be useful when a meaningful update occurs without a page-like navigation and focus should remain where it is. Keep the live region in the document before updating its text, make the message concise, and test it with your supported browser and screen reader combinations. Avoid announcing the same route name both through a live region and focused heading unless testing shows that the combination is helpful rather than repetitive.

Not every URL change is a new page. For example, changing a query parameter while filtering a list may be better communicated as an update to the results, with focus remaining on the filter control. Decide based on the interaction, not merely on whether the address changed.

Advertisement

Test with a Keyboard and Screen Reader

Test the actual application, not just the example:

  1. Using only the keyboard, Tab to a navigation link and activate it. Check that the new heading receives focus and that subsequent keyboard navigation remains logical.
  2. Use browser Back and Forward. Check the URL, title, rendered view, focus position, and any unexpected scrolling.
  3. Repeat with at least one screen reader and its supported browser. Listen for whether the new view is understandable, whether the heading is spoken, and whether anything is announced twice.
  4. Test an initial load, a direct link to a non-default view, a refresh, and an unknown route. Check modified clicks and opening a link in a new tab.
  5. Test slow or delayed content if your application fetches data. Ensure focus is not moved to an element that does not yet exist or repeatedly moved as content updates.

Record the browser, screen reader, operating system, and versions used. Automated checks can supplement this process, but they cannot establish whether the spoken navigation experience makes sense.

Common Mistakes

  • Changing only the URL: The address bar is not an accessible route announcement.
  • Updating only the title: It is useful context, but it is not a reliable immediate announcement mechanism.
  • Ignoring Back and Forward: A click handler alone does not render views reached through browser history.
  • Always moving focus: A filter or small in-place update may not warrant the same behavior as a new page.
  • Combining multiple announcement mechanisms without testing: A live region and focused heading can repeat the same information.
  • Replacing links with non-semantic click targets: Real links preserve familiar keyboard and browser navigation behavior.

Best Practices

Define a consistent route-change policy for your application: decide which transitions are page-like, what their titles and headings should be, and where focus should go. Keep visible headings descriptive and aligned with the view users have reached. Test exceptions, such as dialogs, validation failures, and in-place filtering, independently rather than applying one focus rule everywhere.

The W3C WAI-ARIA Authoring Practices Guide, WCAG guidance, and current MDN History API documentation were not available to consult in this environment. Review those sources and the documentation for your routing framework before adopting this pattern, especially for framework-specific rendering and focus behavior.

Conclusion

A meaningful SPA route change is more than a new URL. Coordinate history, title, rendered content, and focus, then verify the experience with keyboard and screen reader testing.

What would your domain sell for?

A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.