0

same as title, I'm pretty sure it has no difference, but just to be on the safe side with standard compliance.

6 Answers 6

6

If your document is served as XHTML (application/xhtml+xml), then there is no difference. If it's served as HTML (text/html), only the first form is going to be parsed "correctly" by an HTML parser.

See this post for a related question.

1
  • Although its not "parsed correctly" ... the closing tags for HTML are optional while The self closing tag is ignored. still valid HTML, just not W3C compliant these days. Jan 29, 2010 at 15:07
1

This is not just a theoretical different in what is parsed "correctly". There's actually a practical difference.

When served as text/html to browsers other than IE, the "/" in the first case and </img> in the second case will be ignored, and the DOM created in both cases will be the same.

In IE however, in the second case the </img> is not ignored and results in an additional element in the DOM called "/IMG". It's possible for this to effect the workings of scripts that might be on the page.

0

No difference. Self closing tags are just the short way of getting the same job done.

just like c++ is that same as c+=1 and c=c+1 ... just cuts down on typing.

0

No there is no difference for any XML element in any XML document.

<img .../> is just a shortcut for <img...></img>

0

Both methods are xhtml w3C compliant

0

<img /> is the recommended way: http://www.freewebmasterhelp.com/tutorials/xhtml/2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.