Should I remove trailing slashes in meta tags?
Asked Answered
C

4

16

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" />
<!--                                                     ^ -->
Canoodle answered 22/7, 2010 at 16:10 Comment(0)
B
10

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.

Brost answered 22/7, 2010 at 16:12 Comment(1)
As a related thread (but not directly) an interesting read: #70413Brost
D
6

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.

Duplicator answered 22/7, 2010 at 16:25 Comment(1)
To confirm, that means that the presence of a /> renders the code invalid HTML? (github.com/VishwaGauravIn/visit-count-pro/issues/…).Playreader
N
3

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. (e.g. https://html.spec.whatwg.org/multipage/#toc-semantics )

More info about the history, here: https://www.cnet.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. (e.g. Transitional just parsed it as HTML anyway)

The syntax is still widely used incorrectly (e.g. 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)

Nadabb answered 17/1, 2023 at 8:16 Comment(0)
D
0

One usecase here. The <meta> tag must not have the trailing slash.

I have 5 different websites and want to remove them from search engine results.

I set the meta tag

<meta name="robots" content="noindex">

As a result, 4 of them completely disappeared from Bing and Google search results. But, only one page still appears.

I eventually found out the reason. The only still-appearing page had the trailing slash in the meta tag, the 4 others didn't have.

Dynamo answered 15/5, 2024 at 6:48 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.