{"id":5653,"date":"2026-02-12T20:45:02","date_gmt":"2026-02-13T01:45:02","guid":{"rendered":"https:\/\/chubes.net\/?documentation=html-api"},"modified":"2026-03-13T03:28:32","modified_gmt":"2026-03-13T07:28:32","slug":"html-api","status":"publish","type":"documentation","link":"https:\/\/chubes.net\/docs\/wordpress-core\/html-api\/html-api\/","title":{"rendered":"HTML API"},"content":{"rendered":"<p>WordPress HTML parsing and modification framework providing spec-compliant HTML5 processing.<\/p><p><strong>Since:<\/strong> 6.2.0<br \/>\n<strong>Source:<\/strong> <code>wp-includes\/html-api\/<\/code><\/p><h2 class=\"wp-block-heading\">Components<\/h2><figure class=\"wp-block-table\"><table><thead><tr><th>Component<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><a href=\"https:\/\/chubes.net\/docs\/wordpress-core\/html-api\/wp_html_tag_processor\/\">class-wp-html-tag-processor.md<\/a><\/td><td>Tag-level HTML scanner and modifier<\/td><\/tr><tr><td><a href=\"https:\/\/chubes.net\/docs\/wordpress-core\/html-api\/wp_html_processor\/\">class-wp-html-processor.md<\/a><\/td><td>Full HTML5 parser with tree construction<\/td><\/tr><tr><td><a href=\"https:\/\/chubes.net\/docs\/wordpress-core\/html-api\/wp_html_decoder\/\">class-wp-html-decoder.md<\/a><\/td><td>HTML character reference decoding<\/td><\/tr><tr><td><a href=\"https:\/\/chubes.net\/docs\/wordpress-core\/html-api\/wp_html_doctype_info\/\">class-wp-html-doctype-info.md<\/a><\/td><td>DOCTYPE token parsing<\/td><\/tr><tr><td><a href=\"https:\/\/chubes.net\/docs\/wordpress-core\/html-api\/wp_html_open_elements\/\">class-wp-html-open-elements.md<\/a><\/td><td>Stack of open elements<\/td><\/tr><tr><td><a href=\"https:\/\/chubes.net\/docs\/wordpress-core\/html-api\/wp_html_active_formatting_elements\/\">class-wp-html-active-formatting-elements.md<\/a><\/td><td>Active formatting elements list<\/td><\/tr><tr><td><a href=\"https:\/\/chubes.net\/docs\/wordpress-core\/html-api\/wp_html_processor_state\/\">class-wp-html-processor-state.md<\/a><\/td><td>Parser state management<\/td><\/tr><tr><td><a href=\"https:\/\/chubes.net\/docs\/wordpress-core\/html-api\/wp_html_token\/\">class-wp-html-token.md<\/a><\/td><td>Token representation<\/td><\/tr><tr><td><a href=\"https:\/\/chubes.net\/docs\/wordpress-core\/html-api\/wp_html_attribute_token\/\">class-wp-html-attribute-token.md<\/a><\/td><td>Attribute token data<\/td><\/tr><tr><td><a href=\"https:\/\/chubes.net\/docs\/wordpress-core\/html-api\/wp_html_span\/\">class-wp-html-span.md<\/a><\/td><td>Text span data structure<\/td><\/tr><tr><td><a href=\"https:\/\/chubes.net\/docs\/wordpress-core\/html-api\/wp_html_text_replacement\/\">class-wp-html-text-replacement.md<\/a><\/td><td>Text replacement data<\/td><\/tr><tr><td><a href=\"https:\/\/chubes.net\/docs\/wordpress-core\/html-api\/wp_html_stack_event\/\">class-wp-html-stack-event.md<\/a><\/td><td>Stack operation record<\/td><\/tr><tr><td><a href=\"https:\/\/chubes.net\/docs\/wordpress-core\/html-api\/wp_html_unsupported_exception\/\">class-wp-html-unsupported-exception.md<\/a><\/td><td>Unsupported markup exception<\/td><\/tr><tr><td><a href=\"https:\/\/chubes.net\/docs\/wordpress-core\/html-api\/hooks\/\">hooks.md<\/a><\/td><td>Actions and filters<\/td><\/tr><\/tbody><\/table><\/figure><h2 class=\"wp-block-heading\">Architecture<\/h2><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\"><\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code\"><code>WP_HTML_Tag_Processor (6.2.0)\n    \u2514\u2500\u2500 Linear token scanner\n    \u2514\u2500\u2500 Attribute modification\n    \u2514\u2500\u2500 Bookmark navigation\n\nWP_HTML_Processor (6.4.0) extends WP_HTML_Tag_Processor\n    \u2514\u2500\u2500 HTML5 tree construction\n    \u2514\u2500\u2500 Stack of open elements\n    \u2514\u2500\u2500 Active formatting elements\n    \u2514\u2500\u2500 Breadcrumb navigation<\/code><\/pre><\/div><h2 class=\"wp-block-heading\">Usage Patterns<\/h2><h3 class=\"wp-block-heading\">Tag Processor (Simple Modifications)<\/h3><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Modify attributes on specific tags\n$processor = new WP_HTML_Tag_Processor( $html );\nwhile ( $processor-&gt;next_tag( &#039;img&#039; ) ) {\n    $processor-&gt;set_attribute( &#039;loading&#039;, &#039;lazy&#039; );\n}\n$html = $processor-&gt;get_updated_html();<\/code><\/pre><\/div><h3 class=\"wp-block-heading\">HTML Processor (Structure-Aware)<\/h3><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\">php<\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code language-php\"><code class=\"language-php\">\/\/ Modify based on document structure\n$processor = WP_HTML_Processor::create_fragment( $html );\nwhile ( $processor-&gt;next_tag( array( &#039;breadcrumbs&#039; =&gt; array( &#039;FIGURE&#039;, &#039;IMG&#039; ) ) ) ) {\n    $processor-&gt;add_class( &#039;figure-image&#039; );\n}\n$html = $processor-&gt;get_updated_html();<\/code><\/pre><\/div><h2 class=\"wp-block-heading\">Processing Flow<\/h2><h3 class=\"wp-block-heading\">Tag Processor<\/h3><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\"><\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code\"><code>next_tag() \/ next_token()\n    \u251c\u2500\u2500 parse_next_tag()\n    \u251c\u2500\u2500 parse_next_attribute() (loop)\n    \u2514\u2500\u2500 matches() query check\n\nModification methods:\n    \u251c\u2500\u2500 set_attribute() \u2192 lexical_updates[]\n    \u251c\u2500\u2500 remove_attribute() \u2192 lexical_updates[]\n    \u251c\u2500\u2500 add_class() \u2192 classname_updates[]\n    \u251c\u2500\u2500 remove_class() \u2192 classname_updates[]\n    \u2514\u2500\u2500 set_modifiable_text() \u2192 lexical_updates[]\n\nget_updated_html()\n    \u2514\u2500\u2500 apply_attributes_updates()<\/code><\/pre><\/div><h3 class=\"wp-block-heading\">HTML Processor<\/h3><div class=\"code-block-wrapper\"><div class=\"code-block-header\"><span class=\"code-block-language\"><\/span><button class=\"code-copy-btn\" aria-label=\"Copy code\"><svg><use href=\"https:\/\/chubes.net\/wp-content\/themes\/chubes\/assets\/icons\/chubes.svg#icon-copy\"><\/use><\/svg><\/button><\/div><pre data-chubes-enhanced class=\"wp-block-code\"><code>create_fragment() \/ create_full_parser()\n    \u2514\u2500\u2500 Initialize state, stacks\n\nnext_tag() \/ next_token()\n    \u2514\u2500\u2500 step() insertion mode dispatch\n        \u251c\u2500\u2500 step_in_body()\n        \u251c\u2500\u2500 step_in_table()\n        \u251c\u2500\u2500 step_in_head()\n        \u2514\u2500\u2500 ... other modes\n\nTree operations:\n    \u251c\u2500\u2500 insert_html_element()\n    \u251c\u2500\u2500 generate_implied_end_tags()\n    \u251c\u2500\u2500 reconstruct_active_formatting_elements()\n    \u2514\u2500\u2500 run_adoption_agency_algorithm()<\/code><\/pre><\/div><h2 class=\"wp-block-heading\">Token Types<\/h2><figure class=\"wp-block-table\"><table><thead><tr><th>Token<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>#tag<\/code><\/td><td>HTML element (opening or closing)<\/td><\/tr><tr><td><code>#text<\/code><\/td><td>Text node content<\/td><\/tr><tr><td><code>#comment<\/code><\/td><td>HTML comment<\/td><\/tr><tr><td><code>#doctype<\/code><\/td><td>DOCTYPE declaration<\/td><\/tr><tr><td><code>#cdata-section<\/code><\/td><td>CDATA section (only in foreign content \u2014 SVG\/MathML)<\/td><\/tr><tr><td><code>#funky-comment<\/code><\/td><td>Invalid tag closer as comment<\/td><\/tr><tr><td><code>#presumptuous-tag<\/code><\/td><td>Empty end tag <code>&lt;\/&gt;<\/code><\/td><\/tr><\/tbody><\/table><\/figure><h2 class=\"wp-block-heading\">Compatibility Modes<\/h2><figure class=\"wp-block-table\"><table><thead><tr><th>Mode<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>no-quirks<\/code><\/td><td>Standards mode<\/td><\/tr><tr><td><code>limited-quirks<\/code><\/td><td>Almost standards mode<\/td><\/tr><tr><td><code>quirks<\/code><\/td><td>Quirks mode (legacy)<\/td><\/tr><\/tbody><\/table><\/figure><h2 class=\"wp-block-heading\">Special Elements<\/h2><p>Certain elements have special parsing rules:<\/p><ul class=\"wp-block-list\"><li><strong>SCRIPT<\/strong>: Raw text with legacy comment handling<\/li><li><strong>STYLE<\/strong>: Raw text<\/li><li><strong>TITLE\/TEXTAREA<\/strong>: Decoded plaintext<\/li><li><strong>IFRAME\/NOSCRIPT\/NOEMBED<\/strong>: Raw text, no decoding<\/li><\/ul><h2 class=\"wp-block-heading\">Namespaces<\/h2><figure class=\"wp-block-table\"><table><thead><tr><th>Namespace<\/th><th>Context<\/th><\/tr><\/thead><tbody><tr><td><code>html<\/code><\/td><td>Standard HTML<\/td><\/tr><tr><td><code>svg<\/code><\/td><td>SVG foreign content<\/td><\/tr><tr><td><code>math<\/code><\/td><td>MathML foreign content<\/td><\/tr><\/tbody><\/table><\/figure><h2 class=\"wp-block-heading\">Design Principles<\/h2><ol class=\"wp-block-list\"><li><strong>Spec Compliance<\/strong>: Implements HTML5 parsing specification<\/li><li><strong>Safety First<\/strong>: Aborts on unsupported markup rather than breaking documents<\/li><li><strong>Garbage-in, Garbage-out<\/strong>: The Tag Processor passes invalid inputs through unchanged; the HTML Processor will abort (bail) on unsupported or unrecognized markup rather than producing incorrect output<\/li><li><strong>Minimal Diff<\/strong>: Preserves original formatting where possible<\/li><li><strong>No Tree Construction<\/strong>: Tag Processor operates linearly<\/li><li><strong>Memory Efficient<\/strong>: Negligible memory overhead<\/li><\/ol>","protected":false},"excerpt":{"rendered":"<p>WordPress HTML parsing and modification framework providing spec-compliant HTML5 processing. Since: 6.2.0 Source: wp-includes\/html-api\/ Components Component Description class-wp-html-tag-processor.md Tag-level HTML scanner and modifier class-wp-html-processor.md Full HTML5 parser with tree construction&#8230;<\/p>\n","protected":false},"featured_media":0,"template":"","meta":{"footnotes":""},"tags":[],"project":[629],"project_type":[749],"class_list":["post-5653","documentation","type-documentation","status-publish","hentry","project-html-api","project_type-wordpress-reference"],"project_info":{"id":589,"name":"WordPress Core","slug":"wordpress-core"},"project_type_info":{"id":749,"name":"WordPress Reference","slug":"wordpress-reference"},"_links":{"self":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5653","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation"}],"about":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/types\/documentation"}],"version-history":[{"count":4,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5653\/revisions"}],"predecessor-version":[{"id":8875,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/documentation\/5653\/revisions\/8875"}],"wp:attachment":[{"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/media?parent=5653"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/tags?post=5653"},{"taxonomy":"project","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/project?post=5653"},{"taxonomy":"project_type","embeddable":true,"href":"https:\/\/chubes.net\/wp-json\/wp\/v2\/project_type?post=5653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}