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
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:
- A "<" character.
- The element’s tag name.
- Optionally, one or more attributes, each of which must be preceded by one or more space characters.
- Optionally, one or more space characters.
- Optionally, a "/" character, which may be present only if the element is a void element.
- A ">" character.