简体   繁体   中英

Should I remove trailing slashes in meta tags?

W3c markup validation is asking me to remove trailing slashes on my page. Is this correct? And will my page still be compliant in all browsers?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<meta http-equiv="content-style-type" content="text/css" **/**>

That is correct. For HTML 4.01 you shouldn't have trailing slashes (self-closing tags) for meta elements and I believe <link> elements if memory serves me correctly.

xhtml requires trailing slashes, though.

XHTML is HTML with an XML syntax. In XML all tags must be closed. Some HTML tags do not have closing tags so in XHTML they need to be self closed. This is achieved through placing an / in front of the > .

So any tags that you have with /> must be changed to remove the forward slash to be HTML conformant.

These aren't the only differences between the two specifications.

The answer to the question is Yes, you should remove the superfluous solidus. (aka trailing slash, if you wish).

This is also true of HTML5. HTML does not require the slash before the closing > character (aka. "self-closing" tags, also a misnomer) , such as <link /> , and <meta /> , <br /> , <hr /> , etc, and such use is is discouraged for multiple reasons as discussed at the target of the hyperlink provided. Note: it is always best to reference the HTML Specification at either an official W3C or WHATWG resource. (eg https://html.spec.whatwg.org/multipage/#toc-semantics )

More info about the history, here: https://www..net.com/culture/growing-pains-afflict-html5-standardization/

The Trailing slash was to promote XML "compatibility" in XHTML, and was typically only considered by the User Agent ONLY if the XHTML Strict Doctype was used. (eg Transitional just parsed it as HTML anyway)

The syntax is still widely used incorrectly (eg WordPress is allegedly the most popular content management system in use on the web in 2023. View the source of most any WP site, and you'll see it uses incorrect syntax in the HTML. however, it's worth noting that the code-formatting app, Prettier is at least partly to blame)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM