简体   繁体   中英

Skipping html closing tags

Google chrome (and probably all the recent browsers) automatically adds the closing tag of html elements when they are missing. It will automatically add the closing tag at the end of the element parent .

Example 1:

<tag1>content1<tag2>content2<tag3>content3

Will output:

<tag1> 
    content1 
    <tag2> 
        content2
        <tag3> 
            content3 
        </tag3>
    </tag2> 
</tag1>

Example 2:

<tag1>content1<tag2>content2</tag2><tag3>content3

Will output:

<tag1> 
    content1 
    <tag2> 
        content2
    </tag2>
    <tag3> 
        content3 
    </tag3>
</tag1>

I know that the previous html examples are invalid and difficult to read . But removing closing html tags following this rule with an html minifier could reduce the templates's size. Why aren't html minifier using this rule ? Is there some restrictions ?

Edit: Context: I am not talking about any name tag in particular, that's why i used tagX in my examples. Eg. with angularjs element directives

Good observation. This has been done by Firefox for a long time as well as it helps developers with semantics. But the issue we run into is what we just mentioned. Firefox, Chrome. But what does IE do? Or screenreaders? I know Safari is not doing this at the same level FF and Chrome are.

It comes down to browser support and having a general global consensus on valid html. Having a blueprint to work with instead of browser specific implementations means we can run web technology more safely across old and new devices who are not fail safe-ing their parsers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM