Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Self-closing tags (void elements) in HTML5

Tags:

html

element

tags

Step 6 of 8.1.2.1 Start tags of the HTML5 spec says that void elements may have a single / character. I think this is so it's easier to migrate sites that are XHTML over to HTML5.

What's the best practice?

E.g., if I'm making a website with HTML5 (<!DOCTYPE html>), which should I do?

  1. without the slash

    <meta http-equiv="content-type" content="text/html; charset=utf-8"> 
  2. with the slash

    <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 

If both render correctly on all browsers, then I'm assuming (1) without the slash is the way to go since it's more HTML5.

like image 256
ma11hew28 Avatar asked Jan 14 '11 17:01

ma11hew28


People also ask

What are void elements in HTML self close tag?

These elements are called empty or void and only have a start tag since they can't have any content. They must not have an end tag in HTML. The void elements in HTML 4.01/XHTML 1.0 Strict are area , base , br , col , hr , img , input , link , meta , and param .

Which HTML5 tag is self closing?

↑ The full list of valid self-closing tags in HTML5 is: area, base, br, col, embed, hr, img, input, keygen, link, meta, param, source, track, and wbr.

What are void elements in HTML5?

A void element is an element whose content model never allows it to have contents under any circumstances. Void elements can have attributes. The following is a complete list of the void elements in HTML : area , base , br , col , command , embed , hr , img , input , keygen , link , meta , param , source , track , wbr.

Do Vold elements have an end tag?

Void elements only have a start tag; end tags must not be specified for void elements.


1 Answers

There is no consensus on best practice, and according to the author of the spec, Ian Hickson, it does not matter.

like image 149
Gaurav Avatar answered Oct 19 '22 07:10

Gaurav