Published: May 19, 2026, Last updated: September 8, 2026
The web has long since moved on from the static, document-driven medium that it started as. Modern, rich web apps are used by everyone for many reasons, from communicating, purchasing, consuming rich content, to managing our complex lives.
HTML, despite all its advances, is still delivered in-order in a top-to-bottom fashion with little regard for when content is ready or when the user consumes it. CSS lets you change the ordering of content, but often with significant accessibility side effects. JavaScript lets you manipulate the DOM through various APIs to break free of this somewhat, but those often require verbose syntax, or construction of DOM trees to plug into HTML.
Performance is incredibly important for the web, given the client-server nature of the medium. However, suboptimal choices are often made to circumvent this in-order nature of HTML, which slows down performance. This includes waiting until the whole page is ready or using a heavy framework to deliver components in an asynchronous manner. The popularity of JavaScript frameworks shows that web developers prefer a component-based model rather than the rigid document mental model of the web's origins.
The Chrome team has been considering this problem and has been developing new additions to the web platform under the name of Declarative Partial Updates.
The first two new sets of APIs make it easier to deliver HTML in a less linear fashion, whether out-of-order in the HTML document itself, or through easier ways to dynamically insert HTML into existing documents using new JavaScript APIs. Polyfills are also available to let you use these new APIs right away, even in browsers that don't yet support them.
Out-of-order streaming
The first set of changes are new out-of-order streaming APIs using processing instruction placeholders and the <template> HTML element with for attribute. For example:
<div>
<?marker name="placeholder">
</div>
...
<template for="placeholder">
Here is some <em>HTML content</em>!
</template>
Processing instructions have existed in XML for a long time, but have been treated as comments in HTML and ignored. This new API changes that and brings processing instructions to HTML. For example, when the browser sees the <?marker name="placeholder"> processing instruction, it doesn't do anything straight away—much like before—but it can be referenced later.
The <template> element with the for attribute looks up the corresponding processing instructions with a name attribute and replaces the content. In this case, after being parsed, the DOM ends up as the following (ignoring some whitespace differences):
<div>
Here is some <em>HTML content</em>!
</div>
As well as the <?marker> attribute for replacements, there are also <?start> and <?end> range markers which allow for temporary placeholder content to be shown before the template is processed:
<div>
<?start name="another-placeholder">
Loading…
<?end>
</div>
...
<template for="another-placeholder">
Here is some <em>HTML content</em>!
</template>
In this case, a Loading… string displays until the <template> is seen, and then is replaced with the new content.
It's also possible to include processing instructions in templates to allow multiple updates:
<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>
...
This ends up with the following HTML after being parsed and processed:
<ul id="results">
<li>Result One</li>
<li>Result Two</li>
<?marker name="results">
</ul>
With the final processing instruction at the end, in case any more <template for="results"> placeholders are added to the document later.
Why processing instructions instead of standard HTML elements?
This is a common question for those first using this API initially, with suggestions to use <slot> or even <template> elements themselves. An initial version of this proposal worked with standard HTML elements, but processing instructions were switched to as the design was iterated on. Processing instructions allow patching to happen without affecting the DOM. This allows this to be used in the <head>—for <title> updates, for example—or even inside other elements like <table> (to add optional additional rows, for example).
Despite the syntax being unfamiliar to many web developers, processing instructions offer far greater flexibility with less chance of backwards compatibility issues. They are already used in XML, and are now part of the HTML standard thanks to this proposal.
Demo
In this video, a basic photo album application is implemented with streaming HTML:
Both the status and photos are streamed into the HTML after the initial layout.
Use cases
There are many use cases for this out-of-order patching HTML when coupled with streaming HTML:
- Island architecture. A common pattern popularized by frameworks like Astro the island architecture where components are hydrated independently on top of static HTML. The
<template for>API lets static content be handled in a similar fashion directly in HTML. JavaScript frameworks can also use this for more interactive islands or to handle components. - Delivery content when it is ready. Thanks to this island architecture, content can be streamed when it is ready, rather than held back for content that requires extra processing—for example, a database lookup. While many platforms allow streaming HTML, the in-order nature of HTML means that content is often held back, or by resorting to complex JavaScript DOM manipulations. Now you can deliver the static content while waiting, and then plug in more expensive and dynamic content at the end of the HTML stream.
- HTML can be delivered in the optimal order for page load performance. Taking this one step further, you can change the order even when it is ready. For example, mega menus are a common navigation feature that contain a lot of HTML that the user won't see until the page becomes interactive. This large chunk of HTML can be delivered later in the HTML document to prioritize more important HTML needed for the initial page load. Order is no longer a barrier with HTML.
These are just some use cases, and we are excited to see what developers use this new API for.
Restrictions and subtleties
The API includes a few restrictions and subtleties to be aware of:
<template for>can only update processing instructions within the same parent element for security reasons. Adding<template for>directly to the<body>element gives it access to the whole document (including the<head>).- The
<?end>processing instruction is optional and if missing, the content between the<?start>element and the end of the containing element will be replaced. - Moving processing instructions after a
<template for>has started streaming can also have unexpected consequences with the new content continuing to stream into the old location. - Note that when inserting
<template for>dynamically with a method such assetHTMLor theinnerHTMLproperty, the "parent" of the template when it is parsed is an intermediate document fragment. That means that inserting HTML with these methods cannot modify existing DOM, and the patching happens "in place" inside the fragment. However, when streaming using methods likestreamHTMLUnsafe(covered shortly), there's no intermediate fragment, so the templates can replace existing content.
Standardization status
The <template for> attribute is part of the HTML standard but is not yet supported in all browsers.
Future potential additions
Some potential future additions that are under consideration include:
- Client side includes. For example,
<template for="footer" src="/partials/footer.html">, or even without patching<template src="/partials/footer.html">. For more details see the explainer. This is available behind thechrome://flags/#enable-experimental-web-platform-featuresflag. - Preventing overwriting content that will not change. This could be achieved with a content revision number or versioning. This would let state be maintained between route changes or other updates rather than resetting the content.
- Sanitizing while patching. For example,
<template for=icon safe><svg id="from-untrusted-source">...</svg></template>
Polyfill
The Chrome team has released a template-for-polyfill which is available on npm to let sites use this new functionality right away even before this lands in other browsers.
There are some limitations as it cannot directly update browser's HTML parsers, but the most common use cases are covered. Sites should still test in other browsers.
Renewed HTML insertion and streaming methods
Not all content can be delivered as HTML. A second part of the work Chrome has done in this area aims to make it easier to update content with JavaScript.
There already are multiple ways to dynamically inject HTML into an existing document using JavaScript:
setHTMLsetHTMLUnsafeinnerHTMLandouterHTMLcreateContextualFragmentinsertAdjacentHTML
However, they all work in slightly different ways with subtleties and differences that developers may not always consider:
- Does the new content overwrite or append?
- Do they sanitize potentially dangerous HTML—for example. by escaping
<script>tags? - If not, should
<script>'s run? - How do they work with Trusted Types?
Few developers could honestly look at those APIs and confidently answer those questions for each of them.
A big limitation is that they can only be used for a complete set of HTML known in advance, when there have been calls to allow HTML to be streamed. Practically, this means you need to download the entire content before inserting it, when one of the strong points of HTML is the ability to stream in content right away. This can be worked around in a limited fashion by splitting up payloads or using hacky, deprecated methods like document.write, but they introduce their own problems.
A new set of Static and Streaming APIs
Browser Support
Chrome has worked on a suite of new APIs and extensions to the existing setHTML and setHTMLUnsafe that cleans this up, as well as introducing streaming functionality.
These are ready for developer testing from Chrome 148 using the chrome://flags/#enable-experimental-web-platform-features flag and are planned for launch in Chrome 155.
There are methods to set or replace along with methods to insert content before or after existing HTML. Each method has stream equivalents:
| Action | Static | Streaming |
|---|---|---|
| Set the HTML contents of the element | setHTML(html, options); |
streamHTML(options); |
| Replace the entire element with this HTML | replaceWithHTML(html, options); |
streamReplaceWithHTML(options); |
| Add the HTML before the element | beforeHTML(html, options); |
streamBeforeHTML(options); |
| Add the HTML as the first child of the element | prependHTML(html, options); |
streamPrependHTML(options); |
| Add the HTML as the last child of the element | appendHTML(html, options); |
streamAppendHTML(options); |
| Add the HTML after the element | afterHTML(html, options); |
streamAfterHTML(options); |
There are also Unsafe versions that will be covered shortly. While there might appear to be a lot of them—especially when you add in the Unsafe equivalents)—the consistent naming convention makes it more obvious what each does compared to the unrelated methods mentioned previously.
The static versions take new HTML as a DOM String argument, along with optional options:
const newHTML = "<p>This is a new paragraph</p>";
const contentElement = document.querySelector('#content-to-update');
contentElement.setHTML(newHTML);
The streaming versions work with the Streams API such as with a getWriter():
const contentElement = document.querySelector('#content-to-update');
const writer = contentElement.streamHTMLUnsafe().getWriter();
// Example stream of updating content
while (true) {
await writer.write(`<p>${++i}</p>`);
await new Promise((resolve) => setTimeout(resolve, 1000));
}
writer.close();
Or, alternatively from a fetch response using pipe chains:
const contentElement = document.querySelector('#content-to-update');
const response = await fetch('/api/content.html');
response.body
.pipeThrough(new TextDecoderStream())
.pipeTo(contentElement.streamHTMLUnsafe());
textStream() convenience method
Browser Support
A textStream convenience method was also added, where you can stream directly without needing the intermediate TextDecoderStream() step:
const contentElement = document.querySelector('#content-to-update');
const response = await fetch('/api/content.html');
response.textStream().pipeTo(contentElement.streamHTMLUnsafe());
options
The options argument lets you specify a custom sanitizer which defaults to default meaning the default sanitizer config. It is used like so:
const newHTML = '<p>This is a new paragraph</p>';
const contentElement = document.querySelector('#content-to-update');
// Only allows basic formatting
const basicFormattingSanitzer = new Sanitizer({ elements: ['em', 'i', 'b', 'strong'] });
contentElement.setHTML(newHTML, {sanitizer: basicFormattingSanitzer});
"Unsafe" methods
There are also "unsafe" versions of each of the APIs:
| Action | Static | Streaming |
|---|---|---|
| Set the HTML contents of the element | setHTMLUnsafe(html,options); |
streamHTMLUnsafe(options); |
| Replace the entire element with this HTML | replaceWithHTMLUnsafe(html, options); |
streamReplaceWithHTMLUnsafe(options); |
| Add the HTML before the element | beforeHTMLUnsafe(html, options); |
streamBeforeHTMLUnsafe(options); |
| Add the HTML as the first child of the element | prependHTMLUnsafe(html, options); |
streamPrependHTMLUnsafe(options); |
| Add the HTML as the last child of the element | appendHTMLUnsafe(html, options); |
streamAppendHTMLUnsafe(options); |
| Add the HTML after the element | afterHTMLUnsafe(html, options); |
streamAfterHTMLUnsafe(options); |
These "unsafe" methods switch off the sanitizer by default, and you can specify a custom sanitizer if you want. These methods also allow scripts to be run with an optional runScripts option—which defaults to false.
Like setHTML, setHTMLUnsafe is an existing method, but the runScripts options parameter has been added to it to allow it to be used with script execution:
const newHTML = `<p>This is a new paragraph</p>
<script src=script.js></script>`;
const contentElement = document.querySelector('#content-to-update');
contentElement.setHTMLUnsafe(newHTML, {runScripts: true});
The "unsafe" wording in the method is to remind developers of the potential risk and how they may want to sanitize or restrict scripts, not to say that these methods shouldn't be used.
How "unsafe" this is depends on how trusted the inputs are. The Unsafe static methods all work with both DOM String or TrustedHTML as the html arguments and also allow sanitizers to be used. Though with runScript the whole intent is to allow scripts, hence why by default no sanitizer is used.
Use cases
These new APIs make it easier for developers to add HTML to existing pages, adding new APIs with consistent names and options. The streaming APIs bring the performance benefits of not having to wait until all the new content is available to the platform.
Use cases include:
- Dynamic streaming of large content updates in Single Page Apps. As mentioned previously, a big drawback of current SPA architect is that it doesn't benefit from the streaming nature of initial HTML loads—until now!
- Inserting common content like HTML footers. Using the JavaScript APIs lets you pull in partials and insert them into the page, benefiting from caching, rather than repeating them in every page sent. However, given the dependency on JavaScript to run, this should only be used for content that is not going to be visible in the initial load.
Again, those are just a couple of examples and we're eager to see what you all come up with!
Restrictions and subtleties
These new APIs also include a few restrictions and subtleties to be aware of:
- Integration of streaming with the Trusted Types API requires using a new
createParserOptionsmethod which allows injecting a sanitizer to any HTML setting operation. See the explainer for more details on trusted types integration - Similar to
<template for>, moving elements that are being streamed into, can create unexpected consequences or stream errors. streamHTMLUnsafeworks more like the main parser in many ways, including processing<template for>instructions as they are added to the main document and deferringdeferscripts until the end of the stream.
Standardization status
The newer insertion and streaming methods are in the process of being added to of the HTML standard, but are not yet supported in all browsers.
Polyfill
The Chrome team has released a html-setters-polyfill which is available on npm to let sites use this new functionality right away even before this lands in other browsers.
Note that this polyfill does not stream, and instead buffers and applies when complete. It's more a polyfill for the API shape than for functionality.
Additionally, setting of safe content depends on setHTML and the Sanitizer API which is not supported in Safari.
Use these both together
While these are two separate APIs, real power comes from combining them. By streaming new <template for> elements into the HTML, you can dynamically update different parts of content without having to directly target each with separate JavaScript references to the DOM.
A basic SPA-style page load could be implemented by loading an outline page with processing instructions and then streaming each new page's templates into the bottom of the HTML to slot into those processing instructions.
Undoubtedly there is more potential and use-cases for both these APIs so don't let our (limited!) imaginations hold you back. By making partial updates easier to manage you can reduce some of the boilerplate code, make updates easier, and unlock new potential for the web!
There are a few more APIs Chrome is working on under the Declarative Partial Updates project, but we're excited to get these first two into your hands. We'll keep you updated and let you know when more is available in this space.