Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Brenda Krafft
Brenda Krafft
18,036 Points

How can you put a radio button in front of its label?

By default the label shows up in front of a radio button.

Can you reverse this with just HTML and CSS?

Does anyone have an example?

1 Answer

Erik McClintock
Erik McClintock
45,783 Points

Brenda,

Can you post the code that you have to make those radio buttons so we can see an example of what you're doing? If you create a radio button as follows, the label should appear after the radio button:

<form>
    <input type="radio">Yes
    <input type="radio">No
</form>

It should just be a matter of where you've got the label placed in relation to the element itself in your HTML.

Erik

Brenda Krafft
Brenda Krafft
18,036 Points

A-HA! I didn't realize my order in HTML would matter. Originally I had:

<label for="yes">Yes <input type="radio" id="yes" value="yes"> </label>

But putting the input then the label, works just fine.

Brenda Krafft
Brenda Krafft
18,036 Points

For some reason I was thinking I had to embed the button within the label so the label would be clickable.

Not so.