html5 - Is it okay not to close HTML tags like <img> with />? -
i learned close html tags img
, meta
etc. this:
<img src="..." /> <meta charset="..." /> <hr /> <br /> <input type="..." />
but i've seen numerous sites don't put />
@ end. put >
@ end. results in:
<img src="..."> <meta charset="..."> <hr> <br> <input type="...">
but me doesn't seem right... how can browser know if tag still needs closed somewhere when that? that's how learned years ago.
but twitter bootstrap closing input
tags without />
@ end.
is valid html? , preferred way of doing it?
<foo />
xml syntax. meaningful in xml (including xhtml).
however, let deal html.
how can browser know if tag still needs closed somewhere when that?
some elements have required end tags. these must have explicit </foo>
some elements cannot have child nodes , must not have explicit </foo>
. example <img>
.
some elements have optional end tags (such <p>
). browsers close these elements when either encounter explicit end tag (</p>
) they encounter start tag element not allowed child node inside element (such <div>
inside <p>
or <li>
inside <li>
).
browsers know elements have required, optional or forbidden end tags because programmed recognise html.
html 5 allows />
syntax on elements either forbidden end tags, syntactic sugar people addicted xml.
Comments
Post a Comment