What is the correct implementation of element in HTML5?

I’ve been watching a video to learn HTML. I know about HTML but I just wanted to refresh my knowledge. The author declared that he is using HTML5 because the doctype was:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><!doctype html>
</code>
<code><!doctype html> </code>
<!doctype html>

but I noticed that the author used the meta element in a different style that I get used to, he used it without the the forward slash to close the element as follows:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><meta charset="utf-8">
</code>
<code><meta charset="utf-8"> </code>
<meta charset="utf-8"> 

and what I know about this is that it should be like the follwing:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><meta charset="utf-8" />
</code>
<code><meta charset="utf-8" /> </code>
<meta charset="utf-8" />

Which one of the above elements is considered HTML5? I tried to search online but it seems that every web designer has a different opinion which confused me. I like standards.

My SGML is rusty, so I’m going to hope someone comes along to correct some of this but…

This line is SGML which is a super set of HTML and XML.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><!doctype html>
</code>
<code><!doctype html> </code>
<!doctype html>

The <! indicates that the document should drop back to follow SGML directives, not the parent document. This is the same reason that <!-- is the way to start a comment in XML and HTML. <! drops to SGML, and -- is the usual delimiter for comments in SGML. In the above line of code, <! doctype html> is valid SGML for declaring the doctype.

Whereas this line is a part of the standard document and needs to follow the documents rules (which are declared by the doctype, or schema dependent on the document):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><meta charset="utf-8">
</code>
<code><meta charset="utf-8"> </code>
<meta charset="utf-8"> 

In this the SGML rules no longer apply as we are looking at something that needs to conform to HTML. Now, depending on if it is HTML4, HTML5 or XHTML how the tag is closed changes.

In HTML4 many tags didn’t need to be closed, and in fact in some cases were forbidden from being closed. This includes <meta>, <img> and <p> tags, where only the latter was allowed to be closed (like </p>) the other 2 should be left as is with attributes and no closing tags – because in their declaration they needed no closing tag.

However, in XHTML attempts were made to make HTML conformant to XML. A noble goal, however this meant that standalone tags line <meta> or <img> needed to be self-closing as they had no content and became <meta /> and <img /> in XHTML. However, people being overzealous started to do this in HTML4 documents as well. Technically invlaid, but most HTML parsers are very kind and eat much worse HTML, so they never really paid attention.

When HTML5 came along, everyone recognised that people were writing self-closing tags in HTML and the W3C said, “hey you know what, if everyone is doing it, let them do it legally”. So, now in HTML5 you can have either <meta> or <meta />.

As for which type you should choose when writing your code. If you are outputting XHTML, you need to self-close the tag, no questions asked. Otherwise, you have options:

Arguments against self-closing:

  • Over thousands of page views the additional space and slash add up. Google does some heinous things to make readable HTML that saves bytes – for a while they omitted </body> and </head> closing tags.

Arguments for self-closing:

  • Closing tags and making your HTML close to XML, makes it easier for XML based parsers to read your content, which may make searching or scraping content easier if you are using XML based technologies like XPath.

The choice is really up to you, but regardless of which approach you take, consistency is the key.

The notion of self-closing tags like this:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><meta charset="utf-8" />
</code>
<code><meta charset="utf-8" /> </code>
<meta charset="utf-8" />

Is an idea that was brought forward from XHTML. XHTML was an effort by some at the W3C to create a XML-compatible dialect of HTML. It was based on HTML 4.0, but was modified only for XML compatibility. XHTML proved to have a number of problems, and many user agents (browsers) were unable to cope with XHTML documents delivered according to the standard’s specifications and required several “hacks” just to keep browsers from dropping to “quirks mode.”

HTML5 has no relation to XML. It too is based on HTML 4.0, but it disposed of the XML boondoggle that came out of the XHTML effort.

Self-closing tags in HTML5 are valid, but unnecessary.

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật