Inputs question. <input> VS <input />

Discussion in 'HTML & Website Design' started by x0x, Jan 28, 2010.

  1. #1
    What's the difference between:

    <input type="radio" class="radiobutton" name="name" value="2" />

    and

    <input type="radio" class="radiobutton" name="name" value="2" >


    Is the / really needed?
     
    x0x, Jan 28, 2010 IP
  2. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Depends on your doctype.

    HTML does not need the closing slash. In fact, a closing slash is (incorrectly) considered an error, though one most browsers try to ignore.

    XHTML attempted to make HTML as strict as XML, where every open tag requires either a closing tag, or for "empty" elements like <img> and <input>, a shortcut closing tag (<img/> and <input/>).

    Since browsers are HTML parsers, if you have a document with a text/html MIME type and an XHTML1.0 doctype, you basically will have

    <input />
    to satisfy the validator while browsers in reality will see the /> and figure it's an error, and then ignore it and go on with life.

    If you're actually sending a page with an XHTML doctype as real XHTML with an application/xml+xhtml, then leaving the / out is certainly an error, and the page should scream to a halt when it sees that and turn yellow and tell you that you suck balls and have an error.

    Since IE doesn't deal with real XHTML, very few people actually use real XHTML.

    A LOT of people sure seem to like to use an XHTML doctype and write their HTML with the closing slash (to be valid) even though all browsers just see it as "bad html" and go into error mode. They seem to think it's somehow "stricter" : )

    If you don't even have a doctype, GET ONE. And go ahead and use the Good One:
    HTML4.01 Strict.
     
    Stomme poes, Jan 28, 2010 IP
  3. nivedita011

    nivedita011 Peon

    Messages:
    97
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Correct Info, Keep it up
     
    nivedita011, Jan 29, 2010 IP
  4. K.Meier

    K.Meier Well-Known Member

    Messages:
    281
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #4
    I always use XHTML with closing slashes! Use a W3C validator to see if its correct or not.
     
    K.Meier, Jan 29, 2010 IP