xhtml - 是否应该闭合html5文档中的空标签
ringa_lee
ringa_lee 2017-04-17 11:07:00
0
3
1030

处女贴,问个很浅薄也很困扰的问题吧
发现官方草案及答疑中说明即自关闭的斜线(/)对空标签无效,普通HTML标签不要自闭合才是标准的写法,那么我们是否还应该闭合html5中的空标签?
看了下SF的源码,也并不是所有的单标签都闭合了:)

Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/). This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.

Void elements in HTML (e.g. the br, img and input elements) do not require a trailing slash. e.g. Instead of writing, you only need to write. This is the same as in HTML4. However, due to the widespread attempts to use XHTML1, there are a significant number of pages using the trailing slash. Because of this, the trailing slash syntax has been permitted on void elements in HTML in order to ease migration from XHTML1 back to HTML.

ringa_lee
ringa_lee

ringa_lee

reply all(3)
刘奇

The designer of

XHTML believes that the HTML page should strictly conform to XML, making HTML truly a subset of XML, thus advocating self-closing tags consistent with XML.

It must be said that XHTML has played a huge historical role in promoting programmers to standardize semantics. But in terms of results, few of the XHTML pages actually written were actually sent to the XML parser without reporting an error. So in the current HTML5 era, the obsession with XML has finally been abandoned, and the original design goals of XHTML have been dug into a hole by the designers of the Web standards themselves.

The current principle is: as long as there is no ambiguity in the label, adjust it as you like. Regarding the void elements mentioned in the standard, you should be closed or not, and don’t be obsessed with how to make them more “standard” – this is an unnecessary burden under the current thinking.

巴扎黑

Some of this website is closed and some is not. It may not be written by one person, otherwise there would not be two styles.

Regarding the closure of empty tags, I prefer the non-closure recommended in the Google Style Guide. I am a bit lazy in this regard and feel that Google's standards will be the future standards of the industry.

A bit perfectionist. I used to strive to be closed, but now I strive not to be closed.

大家讲道理

One of the new features of html5 is: powerful fault tolerance mechanism. So, don’t worry about the details

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template