Image tag closing

前端 未结 5 827
野趣味
野趣味 2020-12-12 08:10

How to close image tag in HTML?


or


or

5条回答
  •  失恋的感觉
    2020-12-12 08:31

    As per this HTML5 standard: http://www.w3.org/TR/html-markup/syntax.html#void-element

    Start tags consist of the following parts, in exactly the following order:

    1. A "<" character.
    2. The element’s tag name.
    3. Optionally, one or more attributes, each of which must be preceded by one or more space characters.
    4. Optionally, one or more space characters.
    5. Optionally, a "/" character, which may be present only if the element is a void element.
    6. A ">" character.

    The img is a void element and hence the part #5 would apply with a caveat that "a '/' character, which may be present..."

    
    

    And so, you may omit the part #5 i.e. the closing "/", and hence this is also valid:

    
    

    Further down the spec says:

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

    So, no end tag is required.

提交回复
热议问题