View Full Version : Just a question about tags

Mar 3rd, 2012, 02:45 PM
Hi, for years I have always written single tags with a slash at the end, so like

<br />
<img src="" alt="" title="" />
<link href="" rel="stylesheet" type="text/css" />

However I have just used the w3schools validator and it shows all the slashes as errors. I know the code works without them, but I thought it was standard to have them. So my question is has standards changed and you dont have them anymore, or was a taught wrong and never did actaully need them.


Mar 3rd, 2012, 03:11 PM
In a nutshell: Using those closing slashes is XHTML, not using them is HTML.
XHTML is a stricter HTML using XML syntax.

You're right to be using XHTML and closing all your tags.

At the top of your page you should have something like this!?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

That's for strict.
This is for transitional.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

Mar 3rd, 2012, 03:33 PM
Ow thanks, I always forget about putting that at the top. That explains a lot.

Mar 3rd, 2012, 05:31 PM
1bellb it's a whole lot better to use the offical site to validate code instead of the w3school, which is NOT the real W3C.

Find it here http://validator.w3.org/

Mar 3rd, 2012, 10:31 PM
The space before the slash there is only required if you use an XHTML doctype but serve the page as HTML to Netscape 4. Change any of those three and you can get rid of the space.

If you use an XHTML doctype and serve the page as HTML then the / are actually there to keep the validator happy but the browser will see them as an error and ignore them. In Netscape 4 the error would result in the preceding attribute being ignored as well if it wasn't separated by a space.

If you use an XHTML doctype and serve the page as XHTML then IE8 and earlier will offer the page for download as those browsers do not understand XHTML. If you leave out the / in this situation then it will generate an error and most browsers would refuse to display the page.

Whether a page is HTML or XHTML is determined by the MIME type - the doctype is only used by the validator.