out-of-order HTML streaming

Out-of-Order HTML Streaming: How to Use template for in Chrome (2026)

Out-of-order HTML streaming lets the browser fill in parts of a page as they arrive, in any order, without a JavaScript framework doing the work. You send the fast parts of the page first. Then the slow parts, such as comments or recommendations, follow later in the same response and drop into place.

Chrome and Edge 150 shipped the declarative part of this feature, and the matching JavaScript methods keep landing in newer releases. Google also added a guide for it to its Modern Web Guidance docs. So this is a good time to learn how out-of-order HTML streaming works, where it is supported and how to use it safely today.

In this guide, you will learn the new markers, the <template for> element, the new streaming DOM methods, browser support and a practical rollout plan.

What Is Out-of-Order HTML Streaming?

Normally, a browser reads HTML from top to bottom. If one part of the page is slow to build on the server, everything below it waits. As a result, a slow database query for a sidebar can delay the whole page.

Out-of-order HTML streaming fixes this. The spec work is also called Declarative Partial Updates, and it lives in the WICG declarative-partial-updates repository. You mark a spot in the page early. Later in the same stream, you send a template that says, in effect, “put this content in that spot.”

The idea is not new. Facebook’s BigPipe used it back in 2009, and React Suspense streaming does something similar today. However, those tools needed JavaScript on the client to move the HTML around. Now the browser’s own HTML parser can do it.

The Two Parts of the Feature

  • Declarative patching (HTML): new processing instructions (<?marker>, <?start> and <?end>) plus <template for>.
  • Imperative setting and streaming (JavaScript): a family of methods such as setHTML(), streamHTML() and setHTMLUnsafe() that write or stream HTML straight into an element.

How the Declarative Markers Work

First, you add an insertion point to your page. There are two kinds. A single marker is just a spot where content will go. A start and end pair wraps fallback content, such as a loading message, that the browser removes later.

<!-- A simple insertion point -->
<aside id="sidebar">
  <?marker name="related-posts">
</aside>

<!-- A range with a loading state -->
<main>
  <?start name="main-content">
    <p class="skeleton" role="status">Loading article…</p>
  <?end>
</main>

Next, later in the same HTML response, the server sends a template with a matching for value. When the parser reaches it, it swaps the template’s contents into the right place.

<!-- Sent later in the same stream -->
<template for="main-content">
  <article>
    <h1>The real article</h1>
    <p>This replaces the loading message.</p>
  </article>
</template>

<template for="related-posts">
  <ul class="related">...</ul>
</template>

Sending Several Updates to One Slot

Once a template fills an insertion point, that point is gone. However, a template can include a new marker. This lets you append items one by one, for example search results that arrive in batches.

<ul id="results">
  <?start name="results">Loading…<?end>
</ul>

<template for="results">
  <li>Result one</li>
  <?marker name="results">
</template>

<template for="results">
  <li>Result two</li>
  <?marker name="results">
</template>

Scope Rules You Need to Know

For security, a <template for> can only patch markers inside its own parent element. This stops injected markup from taking over a form or a link elsewhere on the page. There is one exception: a template placed directly under <body> can reach markers anywhere in the document, including the head.

The New JavaScript Streaming Methods

Out-of-order HTML streaming also comes with a matching set of DOM methods. There are six actions, and each has four versions, which gives 24 methods in total.

  • Actions: set, replace, before, prepend, append and after.
  • Static or streaming: setHTML() takes a string, while streamHTML() returns a WritableStream you can pipe into.
  • Safe or unsafe: safe methods run a built-in sanitizer that strips things like scripts. Unsafe methods, such as streamHTMLUnsafe(), skip it by default.

Scripts never run by accident. Even with an unsafe method, you must pass { runScripts: true } to let scripts execute. In addition, Chrome 151 added response.textStream(), which removes the need for a separate TextDecoderStream.

// Stream a server-rendered fragment into the page
const feed = document.querySelector('#feed');
const response = await fetch('/partials/feed');

await response
  .textStream()
  .pipeTo(feed.streamHTML());

// Older pattern, if textStream() is not available
// await response.body
//   .pipeThrough(new TextDecoderStream())
//   .pipeTo(feed.streamHTML());

Use the safe methods by default. In fact, only reach for the unsafe versions when the content is fully trusted and the safe version cannot do the job.

Out-of-Order HTML Streaming Browser Support

Support is still limited, so plan for it. According to the web features explorer, here is where things stand:

  • Chrome 150 and Edge 150: <template for> and the HTML processing instructions shipped in mid-2026.
  • Chrome 151: response.textStream() arrived.
  • Chrome and Edge 157: the HTML setter methods are listed as supported.
  • Safari and Firefox: not supported yet. WebKit has a positive standards position, and Mozilla has signalled interest.

The declarative markup is now part of the WHATWG HTML Living Standard. Meanwhile, the JavaScript streaming methods are going through a separate standards process, so their details could still change.

Polyfills and Fallbacks

Browsers without support read <?marker>, <?start> and <?end> as comments. That means the page does not break. Instead, the templates just stay unused at the bottom.

To get the same behaviour everywhere, Google recommends two polyfills: template-for-polyfill and html-setters-polyfill. That way, you can use the same out-of-order HTML streaming markup in every browser. Keep the same marker syntax everywhere, because the polyfill looks for those comments. Do not rewrite them as elements.

// Simple feature checks
const hasTemplateFor = 'htmlFor' in HTMLTemplateElement.prototype;
const hasStreamHTML = 'streamHTML' in Element.prototype;

if (!hasTemplateFor) {
  // Load template-for-polyfill here
}

How to Use Out-of-Order HTML Streaming on Your Server

The browser side is easy. The harder part is making your server actually stream. Here is a simple plan.

  1. Send the shell first. Output the head, header, navigation and main layout with markers in place.
  2. Flush early. Push that first chunk to the browser before you run slow queries.
  3. Send templates as data is ready. Each slow part becomes one <template for> written at the end of the body.
  4. Check every proxy. CDNs, reverse proxies and compression can buffer the response and undo the benefit.

A WordPress and PHP Example

WordPress renders PHP top to bottom, so it suits this pattern well. For example, you can print a marker in your template and fill it from the footer.

<?php // In the template, where the slow block belongs ?>
<section class="related">
  <?php echo '<?start name="related">'; ?>
    <p role="status">Loading related posts…</p>
  <?php echo '<?end>'; ?>
</section>

<?php
// Later, for example in a wp_footer hook
add_action( 'wp_footer', function () {
    echo '<template for="related">';
    echo render_related_posts(); // your slow query
    echo '</template>';
}, 99 );

Note the echo calls. PHP treats <? as its own open tag, so printing the markers as strings avoids parse errors. Also, output buffering in PHP or in your host can hold the page until the end. Check whether your setup flushes early before you measure anything.

If you also use AI coding agents, our guide on Modern Web Guidance explains how to opt in to volatile features like this one. By default, that skill will not suggest single-engine features to your agent.

Best Practices for Out-of-Order HTML Streaming

The rules below help out-of-order HTML streaming stay fast, stable and easy to maintain.

  • Stream the important parts first. Send the header, hero and main content early. Defer comments, ads and related content.
  • Reserve space. Give placeholders fixed sizes or an aspect-ratio so the page does not jump. This protects your CLS score.
  • Do not over-split the page. Too many tiny patches add work for the browser and can delay content.
  • Do not rely on script order. A script inside a template runs as soon as it is patched in, not in a fixed sequence.
  • Respect Trusted Types. When a policy is enforced, pass a sanitized object to any unsafe method.

Accessibility Tips

Content that out-of-order HTML streaming swaps in while someone reads can confuse screen reader users. Therefore, follow a few simple rules from Google’s guide:

  • Put a live region only on the short progress text, such as “Loading comments”. Never wrap the whole streamed area in one.
  • Avoid role="alert" for progress messages, because some screen readers announce the word “alert” first.
  • Set aria-busy="true" on a panel while it loads, then switch it to false when it is done.
  • Keep focus where the user left it. Make sure focus is not lost when a placeholder is replaced.

Small performance wins add up. For instance, pairing this with a smaller transfer size, as covered in our Compression Dictionary Transport guide, makes the first chunk arrive even faster.

FAQ

Is out-of-order HTML streaming safe to use in production?

Yes, if you treat it as progressive enhancement. Browsers without support see comments, so add a polyfill or make sure the page still works without the patched parts.

Do I still need React Suspense or a framework?

Not for out-of-order HTML streaming itself. However, frameworks still help with data loading and routing. Over time, they may switch to the native feature under the hood.

Does this help Core Web Vitals?

It can. The browser gets useful HTML sooner, which can improve LCP. Still, you must reserve space for placeholders, or layout shifts may hurt CLS.

When will Safari and Firefox support it?

No release dates are public yet. WebKit has a positive position and Mozilla has shown interest, so watch their release notes.

Conclusion

Out-of-order HTML streaming moves a well-known framework trick into the browser itself. With a few markers and <template for>, your server can send the fast parts now and the slow parts later, in one response.

For now, out-of-order HTML streaming ships in Chrome and Edge only. So start small: pick one slow block, add a polyfill, measure the result and expand from there.

Sources

Need Help With Your Website or Web App?

Swrice builds and customises WordPress sites, plugins and web apps. Whether you need an upgrade, a custom feature or a fix, our team can handle it for you.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *