hurt
hurt

Reputation: 77

xHTML syntax question

Is it proper if I place the tag after the input tag or before or does it matter?

<label for="l">Last Name:</label>
<input type="text" name="lname" id="l" />

<input type="text" name="fname" id="f" />
<label for="f">First Name:</label>

Upvotes: 2

Views: 76

Answers (3)

John Teague
John Teague

Reputation: 667

no. It doesn't matter. The input can be anywhere on the page for that matter.

Upvotes: 1

Chris Fulstow
Chris Fulstow

Reputation: 41872

Both are valid XHTML, however for good accessibility it's probably best to have <label> first so it'll be described by a screen reader before reaching the input itself.

Upvotes: 4

pzr
pzr

Reputation: 1256

I put the input tag inside the label tag:

<label>Name: <input ... /></label>

That way, the for attribute isn't needed.

Upvotes: 2

Related Questions