← Chrome 148 reference

v148 · html · origin trial

Parse processing instructions in HTML

Chrome 148 teaches the HTML parser to recognise processing instructions — the <?target data?> syntax already used in XML and SVG — and expose them as ProcessingInstruction nodes in the DOM. Parsers and streaming frameworks can use them as lightweight range markers or directives without touching element structure.

Origin trial Parse processing instructions in HTML is in origin trial in Chrome 148. An origin trial token is required to use it in production. The feature ships as enabled by default in Chrome 150. Register at developer.chrome.com/origintrials to test before then.

at a glance

Origin trialChrome 148+
StatusOrigin trial (Experiment)
Standards positionSafari: Support  ·  Firefox: No signal
Specwhatwg/html PR #12118 (Working draft)
Blink componentBlink>HTML>Parser
ChromeStatus6534495085920256 — Parse processing instructions in HTML

why it exists

Processing instructions (PIs) are an established DOM primitive in XML: they appear as ProcessingInstruction nodes and carry an arbitrary target and data string that tooling can act on while leaving element structure untouched. Until this feature, the HTML parser silently discarded PIs. The motivation is to enable two new use-cases without adding new element types that would affect CSS layout:

Source: chromestatus summary + whatwg/html PR #12118.

syntax

A processing instruction in HTML markup follows the XML grammar:

<?target data?>

where target is a name token and data is an arbitrary string that does not contain ?>. The parser creates a ProcessingInstruction node with .target and .data properties.

DOM interface (existing)

ProcessingInstruction.targetThe PI target string (e.g. "start")
ProcessingInstruction.dataThe data portion after the target (e.g. "section-1")
Node.nodeType7 (Node.PROCESSING_INSTRUCTION_NODE)
Node.parentNodeThe containing element or document node
Source: DOM Standard §ProcessingInstruction.

example

Inserting a PI in HTML and reading it from JS

<!-- HTML source -->
<div>
  <?highlight start="1" end="3"?>
  <p>Line one</p>
  <p>Line two</p>
  <p>Line three</p>
  <?highlight end?>
</div>

<script>
// Walk childNodes and collect PIs
const pis = [];
document.body.querySelectorAll('*').forEach(el => {
  for (const child of el.childNodes) {
    if (child.nodeType === Node.PROCESSING_INSTRUCTION_NODE) {
      pis.push({ target: child.target, data: child.data });
    }
  }
});
console.log(pis);
// [{ target: "highlight", data: "start=\"1\" end=\"3\"" },
//  { target: "highlight", data: "end" }]
</script>

Using createProcessingInstruction from JS

const pi = document.createProcessingInstruction('stream', 'flush-before');
document.body.prepend(pi);
// <?stream flush-before?>

browser support

Chrome148 (desktop)
Edge148 (Chromium)
FirefoxNo signal
SafariSupport (date TBD)
Source: chromestatus browser views at time of generation.

see also