[wp-trac] [WordPress Trac] #63824: button is not a self-closing HTML element and needs a closing tag
WordPress Trac
noreply at wordpress.org
Wed Aug 13 10:06:01 UTC 2025
#63824: button is not a self-closing HTML element and needs a closing tag
-----------------------------+-------------------------
Reporter: kkmuffme | Owner: (none)
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Media | Version: 4.8
Severity: trivial | Resolution: maybelater
Keywords: has-patch close | Focuses:
-----------------------------+-------------------------
Comment (by kkmuffme):
Replying to [comment:2 joedolson]:
> This is a jQuery created element, and the value passed into jQuery to
instantiate the element is created with closing tags. See this codepen for
a very simplified example:
>
> https://codepen.io/joedolson/pen/GgpOqar
>
> The actual `button` element in this case doesn't have any text, because
it's hidden and just used as a placeholder. But the created element is
complete. jQuery is creating a DOM object, not raw HTML. This would only
be self-closing if it was being inserted as HTML directly.
>
> So there is no actual issue here.
This has nothing to do with jQuery, but this is how the browser's DOM
parser works - it fixes invalid HTML. And jQuery just (ab)uses it.
Run this and you'll see you get a valid HTML too, just like with jQuery:
{{{
document.getElementById("demo").innerHTML = '<button type="button" />';
}}}
You'll also see that the browser will always remove the XHTML closing
slash too.
So yeah, you can pass incomplete HTML, but it's always better to directly
pass valid HTML to reduce the parser work.
Furthermore, with some tags (not this one), this is actually unsafe and
allows for XSS attacks. Therefore it only makes sense to consistently
enforce valid, complete HTML to be used.
----
XHTML is deprecated:
https://html.spec.whatwg.org/#the-xhtml-syntax
>Using the XML syntax is not recommended, for reasons which include the
fact that there is no specification which defines the rules for how an XML
parser must map a string of bytes or characters into a Document object, as
well as the fact that the XML syntax is essentially unmaintained
And it's removed by the browser anyway in all regular HTML cases. But even
in XML button isn't a self-closing tag is it?
>I'd like to see movement on #59883 to remove support for XHTML before
considering this
Yeah me too, but this has nothing to do with it. The XHTML slash is
removed by the browser automatically anyway
----
Bottom-line: keeping invalid, but working HTML is a bad practice.
I can't believe that this, minimal change that ensures compliance to the
HTML standard even requires a discussion... If php-src contributors worked
like that, we'd still be at PHP 5.6
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63824#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list