What is "/>"?

M

michaaal

I have been programming in HTML for 3 years and I usually program in this
format...

<input type="text">

...I have seen people use this type of format...

<input type="text />

What is the extra slash for? Am I missing something?
 
E

Edward Alfert

I have been programming in HTML for 3 years and I usually program in this
format...

<input type="text">

..I have seen people use this type of format...

<input type="text />

What is the extra slash for? Am I missing something?

Some HTML tags are not pairs or you have a choice of writing them as a pair
or not.

<tag></tag> or <tag />

for example.

<img src="/images/image.php" alt="image of me" />

<hr />
 
R

Rob Collyer

I have been programming in HTML for 3 years and I usually program in this
format...

<input type="text">

..I have seen people use this type of format...

<input type="text />

What is the extra slash for? Am I missing something?

The extra slash is required by XHTML for elements that do not have a
closing element....

For instance
<img src="blah" />
<br />
<input type="text" />


valid XHTML requires all elements to be closed.... the extra slash tells
the browser to close the element there and then.... it is both the
opening, and closing element in one.

Hope this helps.
 
N

Neil Monk

Rob said:
The extra slash is required by XHTML for elements that do not have a
closing element....

For instance
<img src="blah" />
<br />
<input type="text" />


valid XHTML requires all elements to be closed.... the extra slash
tells the browser to close the element there and then.... it is both
the opening, and closing element in one.

Hope this helps.
It certianly did, good clear explanation Rob.

Thanks.
 
A

Andy Dingley

Neil Monk said:
Rob Collyer wrote:
It certianly did, good clear explanation Rob.

Don't worry, at least twenty people will post soon to correct (sic)
and nit-pick.
:cool:


If you care about this stuff, read the XML spec and Appendix C of the
XHTML 1.0 spec.

If you don't care about this stuff, then just use the " />" form to
make sure that every element is closed somehow. BUT always write
empty elements as "<br />" (with a space in them), or some readers
see them as a tag name "br/" (which is wrong). Also make sure that
you don't use the XML short form for HTML elements that aren't empty
elements. Stick with <script ... ></script>, or IE6 will make your
whole page disappear!
 
K

Kurt Weber

michaaal said:
I have been programming in HTML for 3 years

No, you haven't.
and I usually program in this
format...

I doubt it.
..I have seen people use this type of format...

<input type="text />

What is the extra slash for? Am I missing something?

It's required by XHTML--all elements are required to be closed, so the
slash at the end tells the client to close the element right then and there.
 
S

Sam Hughes

Some HTML tags are not pairs or you have a choice of writing them as a
pair
or not.

<tag></tag> or <tag />

for example.

<img src="/images/image.php" alt="image of me" />

<hr />

Not exactly. The above is only true for XHTML. If you're writing to an
HTML spec, that form of code should not be used.
 
T

Toby Inkster

Kurt said:
It's required by XHTML--all elements are required to be closed, so the
slash at the end tells the client to close the element right then and there.

Not really *required*. You can happily write XHTML without a single "/>".
 
S

Spacen Jasset

michaaal said:
I have been programming in HTML for 3 years and I usually program in this
format...

<input type="text">

..I have seen people use this type of format...

<input type="text />

What is the extra slash for? Am I missing something?

/> Is the empty-element and forms a self closing tag

/ > ( Slash space angle-bracket ) is used for compatibility so non XHTML
browswers can render xhtml documents

from the xhtml spec:


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

Els

Spacen said:
/> Is the empty-element and forms a self closing tag

/ > ( Slash space angle-bracket )

You mean /> (space slash angle-bracket), as you state
yourself below :)
 
E

Edward Alfert

Sam Hughes said:
Not exactly. The above is only true for XHTML. If you're writing to
an HTML spec, that form of code should not be used.


Thanks...time for me to brush up on my coding.
 
S

Spacen Jasset

Els said:
Spacen Jasset wrote:
....

You mean /> (space slash angle-bracket), as you state
yourself below :)

....

Some days I don't know what I mean. Yes, that's right space slash angle
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top