Hello everyone,
In this situation, is there any reason to actually do the latter apart from modern-day standards
compared toHTML Code:<br>
same for img, hr, etc.HTML Code:<br />
Hello everyone,
In this situation, is there any reason to actually do the latter apart from modern-day standards
compared toHTML Code:<br>
same for img, hr, etc.HTML Code:<br />
No reason other than conforming to w3c standards for XHTML, it's just closing tags, for neatness.
"Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
Anime Views Forums
Bernie
In XHTML, yes. In [other] HTML, no.
In HTML, tags that go around content require a preceding 'open' tag and a following 'close' tag, while tags that are the content (for example, an image) have a single tag, which doesn't need a separate close tag.
In XHTML, the idea was simply to merge the open+closer tags so that it is <img /> rather than <img> without an </img> anywhere.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
The situation is a little more complex. Unless your XHTML page is actually being served as application/xml, it will be error corrected to HTML by the browser.
It likely isn't being served as application/xml, because if it were, it wouldn't load in IE 8 and less.
You really shouldn't use XHTML unless you are serving application/xml. If you do, you need a valid XML prologue. And as I say the page won't load in IE 8 and less.
Use HTML 4.01 or HTML 5. In 4.01, self closing tags are not allowed, in 5 they are, but are not required.
About the worst thing you can do in either HTML or XHTML is to self close a tag that requires a closing tag. The iframe tag is a good example. But any tag requiring a closing tag can act oddly if you try to get away with self closing it rather than using its required closing tag. At the same time you need to be aware that, for scripting purposes, some browser will erroneously self close some tags. This can throw off your element count (say if you're using getElementsByTagName('*') or childNodes()) in those browsers even when your code is valid.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
In XHTML, self closing a tag that requires a closing tag yields an error anyway, so it's within the XHTML standards to do that. I personally maintain XHTML standards on regular HTML pages, for the sake of keeping up readability and coding habits.
"Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
Anime Views Forums
Bernie
Self closing tags on HTML pages are invalid unless it's HTML 5. But just as browsers error correct most "XHTML" to HTML, they will usually do the same with HTML written as XHTML. But there could be exceptions.
It's generally best to follow the standards of the DOCTYPE you're using.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Bookmarks