HTML Tag Question

M

Matt

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!!
 
M

Mark Parnell

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.
 
N

Neal

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.
 
G

Geoff Ball

(e-mail address removed) (Matt) wrote in @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
 
R

rf

Matt said:
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
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.
 
D

David Dorward

Matt said:
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.
 
N

Neal

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.
 
D

David Håsäther

Neal said:
"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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top