Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you need to close meta and link tags in HTML?

Tags:

html

xhtml

People also ask

Do HTML meta tags need to be closed?

The <meta> element is used to add machine-readable information to an HTML document. Information added with the <meta> tag is not displayed to website visitors but is provided for use by browsers and web crawlers. This element must not contain any content, and does not need a closing tag.

Does link need a closing tag?

LINK. The LINK element indicates a relationship between the document and some other object. A document may have any number of LINK elements. The LINK element is empty (does not have a closing tag), but takes the same attributes as the anchor element.


A tag must always be closed by the tag close symbol > (if we ignore certain SGML rules that nominally apply in non-XHTML HTML but were never implemented in browsers).

What you mean to ask is whether the elements need to be closed by end tags. The answer is that non-XHTML HTML (including HTML5 in HTML serialization), no end tag is required or allowed for meta and link elements. In practice, however, browsers just ignore explicit end tags for them, as well as the cargo-cult / before >, if you use them. And HTML5 makes this permissiveness a rule by even formally allowing the / in HTML serialization, too.

In XHTML, XML rules apply, so every element, without exception, must have both a start tag and an end tag, but the same tag may be used for both roles if the element content is empty, e.g. <meta name="foo" content="bar"/> as short for <meta name="foo" content="bar"></meta>. If you violate this when serving a document with an XML (XHTML) content type to a conforming browser, then your document is not displayed at all; an error message is shown instead.

When using an XHTML server with the HTML content type (Content-Type: text/html), as XHTML documents almost always are on the web, then browsers will actually apply the non-XHTML HTML rules.

To summarize:

  • normally, use just <meta ...> with no /
  • if you are really using XHTML in a context where XHTML parsing is actually applied, play by XML rules (and make sure you know them)
  • if your boss tells you to write <meta ... />, do so; it’s not useful, but it causes no harm (except if you try to validate e.g. against the HTML 4.01 doctype).

It depends on the doctype. HTML5 doesn't need the closing. XHTML does.

In HTML5, so-called void elements (elements that can't have content) don't need the closing, as they are self-closing. But it is still valid if you close them..

Read more about it here: void-elements