Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.