Possible Duplicate:
Are self-closing tags valid in HTML5?
For example:
<div id="myDiv" />
Something would then be done to populate this div using Javascript.
Is this valid HTML?
The fact is there is no need to close self closing tags by a slash /> at the end of the tag. Although many people use it but there is no meaning of slash at the end of the start tag even though you use it is ignored by the browsers.
If you don't add a closing tag the browser won't know where it ends. It will take the next tag and think it belongs to the previous tag without the closing tag.
Should Optional HTML Tags be Closed? Code with closing tags is much more readable and easy to follow. It is much easier to visually inspect a page with well laid out markup. Working with this markup is easier for developers.
No, not all the tags are ending tags. Tags may be either paired or unpaired (or single). Paired tags need to be closed, i.e. they contains both ending and non-ending tags, whereas unpaired tags need not be closed, i.e. they only contain opening tags.
No. HTML 4.x doesn't have any concept of self closing tags.
It is valid in XHTML.
Div's are not valid self closing tags. To have an empty div it would be better to do this:
<div id="myDiv"></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With