Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Just a question about tags

    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.

    Thanks
    Ben

  • #2
    Regular Coder dan-dan's Avatar
    Join Date
    Aug 2009
    Location
    England
    Posts
    483
    Thanks
    22
    Thanked 79 Times in 78 Posts
    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!?

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    That's for strict.
    This is for transitional.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    Last edited by dan-dan; 03-03-2012 at 02:14 PM.

  • #3
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ow thanks, I always forget about putting that at the top. That explains a lot.
    Thanks
    Ben

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,193
    Thanks
    23
    Thanked 605 Times in 604 Posts
    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/

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,640
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •