views:

111

answers:

3
<input type="radio" value="1" id="baby">

I'd like to keep this code like that. However, can I apply a CSS to it so that the "1" is not displayed to the user?

Edit: For some reason, it is being displayed, I don't know why. I do have a CSS attached to it though.

+6  A: 

The value of "1" is not displayed to the user at all, it's hidden and only has meaning when the form posts. You need to add a <label> tag or just raw text near the radio button to display the value you want the user to see.

Randolpho
Preferably a label since that is (a) semantic (b) makes this easier for screen reader users (c) gives a large click target for mouse users
David Dorward
True on every count. `<label>` is preferred.
Randolpho
+2  A: 

For radio buttons, the value attributed is never rendered by the user agent (unless it does something rather weird). Typically, if you need a radio button with a label, you explicitly specify one, ideally using the <label> tag.

Jan Krüger
+1  A: 

The "1" should not display for the user.. it's just a value..

Normally, you'd declare a radio input like so:

<label><input type="radio" value="1" id="baby"> Baby </label>

This will make "Baby" the label for the radio button, this will also make clicking on the Baby text activate the radio button, which is what accessibility rules would require..

Ben
edit: forgot to wrap in code
Ben
I believe the correct usage is: `<input type="radio" value="1" id="baby"><label for="baby">Baby</label>` (the `id` and `for` elements must match)
intgr
Yes, yes! To @intgr you listen! Do not put `<input>` tags inside `<label>` tags! Doing so violates many doctypes.
Randolpho
Does it? Which ones? Consider:http://www.w3.org/TR/html401/interact/forms.html#idx-label-1
alex
@Randolpho Yes, which ones, never had any problems with it
Ben
@alex thanks for the official doc link
Ben
@alex: I stand corrected.
intgr
@alex: my first thought was "that's just HTML 4 transitional, XHTML will be stricter on it". But I went and checked, and holy crap, I was totally wrong. I've been doing XHTML strict for years now and always thought label could not accept an input tag. I humbly offer apologies to you and Ben.
Randolpho