# Radio Buttons and Name Attributes

**URL:** <https://forum.freecodecamp.org/t/radio-buttons-and-name-attributes/136448>\
**Category:** General\
**Created:** [July 16, 2017, 5:58am UTC](https://forum.freecodecamp.org/t/radio-buttons-and-name-attributes/136448 "2017-07-16T05:58:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zabeer7](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/zabeer7/32/31672_2.png) [@Zabeer7](https://forum.freecodecamp.org/u/Zabeer7)\
**Post date:** [July 16, 2017, 5:58am UTC](https://forum.freecodecamp.org/t/radio-buttons-and-name-attributes/136448/1 "2017-07-16T05:58:48Z")

</div>

Why all related radio buttons should have the same name attribute???

---

<div class="post-metadata">

**Author:** ![DaveC](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/davec/32/161518_2.png) [@DaveC](https://forum.freecodecamp.org/u/DaveC)\
**Post date:** [July 16, 2017, 6:22am UTC](https://forum.freecodecamp.org/t/radio-buttons-and-name-attributes/136448/2 "2017-07-16T06:22:20Z")

</div>

Radio buttons are grouped in a way that you should only be able to select one button from a group. You don’t want people to select ‘boy’, ‘girl’, AND ‘complicated’ from a `gender` field (… which is a terrible thing to ask anyway in today’s world. Only hospitals and the like actually NEED to know gender).

The `name` attribute is how the browser knows that these radio buttons are related. Different groups of radio buttons can have different names so they don’t interfere with each other. Without `name`, your “preferred in-flight meal” group could interfere with your “gender” group.

Also, radio buttons don’t toggle; you can’t turn the off after you turn them on (for that, you should be using a checkbox instead). In order to turn one radio button in a group off, you need to turn another on.

---

<div class="post-metadata">

**Author:** ![Zabeer7](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/zabeer7/32/31672_2.png) [@Zabeer7](https://forum.freecodecamp.org/u/Zabeer7)\
**Post date:** [July 16, 2017, 6:50am UTC](https://forum.freecodecamp.org/t/radio-buttons-and-name-attributes/136448/3 "2017-07-16T06:50:31Z")

</div>

That makes more sense.

THANKS.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:48pm UTC](https://forum.freecodecamp.org/t/radio-buttons-and-name-attributes/136448/4 "2021-01-17T20:48:02Z")

</div>

Closed on January 17, 2021, 8:48pm UTC


