HTML Tag Question

Discussion in 'HTML' started by Matt, May 27, 2004.

  1. Matt

    Matt Guest

    Whats the differences between the following:

    1) <input type="text" name="username">
    2) <input type="text" name="username" />
    3) <input type="text" name="username"></input>

    I always use #1, but I have seen people using #2 and #3, but
    seems like they all yield the same output.

    Please advise. Thanks!!
     
    Matt, May 27, 2004
    #1
    1. Advertising

  2. Matt

    Mark Parnell Guest

    On 26 May 2004 22:34:08 -0700, (Matt) declared in
    alt.html:

    > Whats the differences between the following:
    >
    > 1) <input type="text" name="username">
    > 2) <input type="text" name="username" />


    This one has a space and a / before the >

    > 3) <input type="text" name="username"></input>


    This one has a </input> added at the end.

    BTW: 1 is HTML, 2 and 3 are XHTML.

    --
    Mark Parnell
    http://www.clarkecomputers.com.au
     
    Mark Parnell, May 27, 2004
    #2
    1. Advertising

  3. Matt

    Neal Guest

    On 26 May 2004 22:34:08 -0700, Matt <> wrote:

    > Whats the differences between the following:
    >
    > 1) <input type="text" name="username">
    > 2) <input type="text" name="username" />
    > 3) <input type="text" name="username"></input>
    >
    > I always use #1, but I have seen people using #2 and #3, but
    > seems like they all yield the same output.
    >
    > Please advise. Thanks!!



    1) is correct HTML. 2) is correct XHTML. 3) is valid but incorrect XHTML.
     
    Neal, May 27, 2004
    #3
  4. Matt

    Geoff Ball Guest

    (Matt) wrote in news:ba8a039e.0405262134.3dfb8456
    @posting.google.com:

    > Whats the differences between the following:
    >
    > 1) <input type="text" name="username">


    HTML.

    > 2) <input type="text" name="username" />
    > 3) <input type="text" name="username"></input>


    XHTML. For compatibility with older browsers, use #2 over #3 (because you
    can't have content within the input element anyway).

    > I always use #1, but I have seen people using #2 and #3, but
    > seems like they all yield the same output.


    If you're using HTML, use #1. If you're using XHTML, use #2.

    Regards,
    Geoff
     
    Geoff Ball, May 27, 2004
    #4
  5. Matt

    rf Guest

    "Matt" <> wrote in message
    news:...
    > Whats the differences between the following:
    >


    HTML element.
    > 1) <input type="text" name="username">


    XHTML elements: (an entirely different animal)
    > 2) <input type="text" name="username" />
    > 3) <input type="text" name="username"></input>


    If you are writing HTML then 1) is the only valid one. In fact, 2) in
    particular can cause havoc, particularly if used in the <head> element for,
    say, a link element.

    > I always use #1, but I have seen people using #2 and #3, but
    > seems like they all yield the same output.


    Yep, mainly because many browsers (well the MS one at least) simply do not
    understand XHTML and it gets error corrected back to HTML.

    Cheers
    Richard.
     
    rf, May 27, 2004
    #5
  6. Toby A Inkster, May 27, 2004
    #6
  7. Matt wrote:

    > Whats the differences between the following:
    >
    > 1) <input type="text" name="username">


    In HTML: An input element
    In XHTML: An opening tag for an input element

    > 2) <input type="text" name="username" />


    In HTML: An input element followed by a ">" sign
    In XHTML: An input element

    > 3) <input type="text" name="username"></input>


    In HTML: An input element followed by an invalid tag
    In XHTML: An input element

    > I always use #1, but I have seen people using #2 and #3, but
    > seems like they all yield the same output.


    Browsers tend to perform error correction to cope with author's screwups. It
    is best to avoid conditions which trigger error correction as not all
    browsers will guess the author's intentions in the same way.


    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, May 27, 2004
    #7
  8. Matt

    Neal Guest

    On Thu, 27 May 2004 07:20:43 +0100, Toby A Inkster <>
    wrote:

    > Neal wrote:
    >
    >> 3) is valid but incorrect XHTML.

    >
    > There's nothing incorrect about it.
    >


    "C.2. Empty Elements

    Include a space before the trailing / and > of empty elements, e.g. <br
    />, <hr /> and <img src="karen.jpg" alt="Karen" />. Also, use the
    minimized tag syntax for empty elements, e.g. <br />, as the alternative
    syntax <br></br> allowed by XML gives uncertain results in many existing
    user agents."

    Ok, maybe "incorrect" is too strong. But it's definitely "uncertain" and
    therefore unadvisable.
     
    Neal, May 27, 2004
    #8
  9. Neal <> wrote:

    > On Thu, 27 May 2004 07:20:43 +0100, Toby A Inkster
    > <> wrote:
    >
    >> Neal wrote:
    >>
    >>> 3) is valid but incorrect XHTML.

    >>
    >> There's nothing incorrect about it.
    >>

    >
    > "C.2. Empty Elements
    >
    > Include a space before the trailing / and > of empty elements,
    > e.g. <br />, <hr /> and <img src="karen.jpg" alt="Karen" />. Also,
    > use the minimized tag syntax for empty elements, e.g. <br />, as
    > the alternative syntax <br></br> allowed by XML gives uncertain
    > results in many existing user agents."


    Appendix C is informative.

    > Ok, maybe "incorrect" is too strong. But it's definitely
    > "uncertain" and therefore unadvisable.


    Yes, when sending it with the wrong Content-Type.

    --
    David Håsäther
     
    David Håsäther, May 27, 2004
    #9
  10. Matt

    Neal Guest

    On Thu, 27 May 2004 14:52:52 GMT, David Håsäther <> wrote:

    > Neal <> wrote:
    >> Ok, maybe "incorrect" is too strong. But it's definitely
    >> "uncertain" and therefore unadvisable.

    >
    > Yes, when sending it with the wrong Content-Type.
    >


    .... which you must do for most users, who use a particular browser-like
    piece of software. :)
     
    Neal, May 27, 2004
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RC
    Replies:
    2
    Views:
    445
    Malte
    May 10, 2005
  2. shruds
    Replies:
    1
    Views:
    870
    John C. Bollinger
    Jan 27, 2006
  3. RC
    Replies:
    2
    Views:
    664
  4. Replies:
    1
    Views:
    398
    Andrew Thompson
    Nov 29, 2006
  5. Replies:
    7
    Views:
    506
    Max Erickson
    Mar 26, 2007
Loading...

Share This Page