HTML 5: Is it
,
, or
?

后端 未结 29 3784
滥情空心
滥情空心 2020-11-22 00:26

I\'ve tried checking other answers, but I\'m still confused — especially after seeing W3schools HTML 5 reference.

I thought HTML 4.01 was supposed to \"allow\" singl

29条回答
  •  没有蜡笔的小新
    2020-11-22 00:37

    XML doesn't allow leaving tags open, so it makes
    a bit worse than the other two. The other two are roughly equivalent with the second (
    ) preferred for compatibility with older browsers. Actually, space before / is preferred for compatibility sake, but I think it only makes sense for tags that have attributes. So I'd say either
    or
    , whichever pleases your aesthetics.

    To sum it up: all three are valid with the first one (
    ) being a bit less "portable".

    Edit: Now that we're all crazy about specs, I think it worth pointing out that according to dev.w3.org:

    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.

提交回复
热议问题