← Blog
1 Dec 2026VueRadio ButtonsForm LabelsAccessibilityReusable Components

Radio Button With Label in Vue: Stable IDs and v-model

Build a radio button with label in Vue using v-model, stable IDs, keyed options, and reusable groups. Includes code and practical label-click checks.

Radio Button With Label in Vue: Stable IDs and v-model

TL;DR

To create a radio button with label in Vue, match the label’s for to the input’s unique id. Give options in one question a shared name, bind them to one v-model, and use stable option values as Vue keys. Reusable groups also need instance-specific IDs and separate names for independent questions.

A label that works in a static mockup can fail after a component is duplicated or its options change. The useful Vue pattern preserves three things independently: the label association, the selected value, and each rendered option’s identity.

I’ll build that pattern from an array, then extract it into a reusable component. For the broader native-label and ARIA background, see our guide to labels for radio buttons.

Table of contents

Before you start

Use an existing Vue 3.5+ application with single-file component compilation and <script setup> support. The reusable example uses useId(), introduced in Vue 3.5, and defineModel(), available since Vue 3.4.

You also need a browser for interaction checks and an option array containing unique, stable string values. I use email, phone, and post; reserve the empty string for an unanswered question. Keep these identifiers separate from translated display labels.

The examples manage selection only. They do not implement submission, persistence, required-field validation, or asynchronous option loading. Keep the native inputs visible while checking behavior, then integrate your application’s presentation and error handling.

1. Render a labeled radio group from an array

Create ContactPreference.vue with the following complete starting example. Render this version once; its fixed ID prefix is not suitable for repeated instances.

<script setup>
import { ref } from 'vue'

const selectedContact = ref('')
const options = ref([
  { value: 'email', label: 'Email' },
  { value: 'phone', label: 'Phone' },
  { value: 'post', label: 'Post' }
])
</script>

<template>
  <fieldset>
    <legend>Preferred contact method</legend>

    <div v-for="option in options" :key="option.value">
      <input
        :id="`profile-contact-${option.value}`"
        v-model="selectedContact"
        type="radio"
        name="profile-contact"
        :value="option.value"
      />
      <label :for="`profile-contact-${option.value}`">
        {{ option.label }}
      </label>
    </div>
  </fieldset>

  <p>Selected: {{ selectedContact || 'No selection yet' }}</p>
</template>

For Email, both expressions produce profile-contact-email. The match must be exact: for targets the input’s id, not its name or Vue variable. W3C’s labeling guidance explains this association and the larger clickable target it provides.

Matching for="contact-email" on a label with id="contact-email" on an input makes Email a clickable radio label.

The fieldset and legend supply the shared question, following W3C’s grouping guidance. They do not replace each option’s label.

Check it: click the word Phone. Its radio should become checked, and the paragraph should show phone. If clicking the circle works but clicking the text does not, inspect the rendered for and id first. Adding another click handler would conceal the association problem rather than fix it.

2. Keep label association separate from selection state

Several identifiers appear together, but they solve different problems:

Part Purpose Example
Input id Identifies one input for its label profile-contact-email
Label for References that input profile-contact-email
Radio name Connects options in one native group profile-contact
Input value Represents one answer email
Vue key Tracks an option during list updates option.value
v-model Holds the selected answer selectedContact

Vue’s Form Input Bindings documentation establishes that radio v-model uses the checked property and change event. It does not generate a label relationship. Conversely, a correct label does not create your reactive state.

To start with Email selected, initialize selectedContact with ref('email'). Do not add a competing checked attribute: Vue treats the bound JavaScript state as the source of truth. The ref documentation explains why script code uses .value while these top-level refs are unwrapped in templates.

When wrapping the input is practical

For a compact choice row, the label can contain its input:

<label>
  <input type="radio" name="contact-method" value="email" />
  Email
</label>

This standalone HTML alternative uses implicit association. W3C documents both approaches and notes stronger assistive-technology support for explicit labels. I keep explicit matching in the Vue examples because it makes the generated relationship easy to inspect.

For a visual introduction to the underlying HTML pattern, this supplementary lesson focuses on labels for radio buttons. Use the Vue examples here for reactive state and reusable components.

3. Preserve option identity when the list changes

Use a stable data identifier for both the key and the option-specific part of the input ID. In this example, option.value serves both roles because each value is unique and does not change when its label changes.

Vue’s list-rendering guide recommends keys for tracking identity, particularly when rendered output depends on form or component state. A list position is not a durable identity when options can move.

Avoid building identifiers from:

  • Array indexes: inserting or sorting options changes which answer occupies an index.
  • Display labels: localization or editorial changes should not change an answer’s identity.
  • Values generated during rendering: the same option should not receive a fresh identifier on each update.

A stable key does not repair mismatched for and id values. It also cannot prevent a parent from resetting the selected model. These are separate checks, not interchangeable fixes.

Verify an update: select Phone, then reorder the options through Vue Devtools. Confirm that Phone remains selected and its label still activates it. Change the visible wording while retaining value: 'phone'; the selected answer should remain phone.

If an update removes the selected option, decide what should happen to the answer. I recommend explicitly clearing an unavailable value and explaining why the user must choose again, rather than silently substituting another option. Keyed rendering is not an application-level policy for invalid answers.

4. Extract a reusable group with instance-specific IDs

The fixed prefix in step 1 becomes a collision risk when copied. Replace it with an instance-specific prefix in RadioGroup.vue:

<script setup>
import { useId } from 'vue'

const props = defineProps({
  name: { type: String, required: true },
  legend: { type: String, required: true },
  options: { type: Array, required: true }
})

const selected = defineModel({ type: String, required: true })
const groupId = `radio-${useId()}`
</script>

<template>
  <fieldset>
    <legend>{{ props.legend }}</legend>

    <div v-for="option in props.options" :key="option.value">
      <input
        :id="`${groupId}-${option.value}`"
        v-model="selected"
        type="radio"
        :name="props.name"
        :value="option.value"
      />
      <label :for="`${groupId}-${option.value}`">
        {{ option.label }}
      </label>
    </div>
  </fieldset>
</template>

Vue’s useId() reference documents unique-per-application IDs, including across component instances, and stability between server and client renders. Call it during setup as shown. Persist the option value, not the generated DOM ID.

The parent still owns name, because it describes the form question rather than a particular input. If a document mounts multiple Vue applications, give each application a different app.config.idPrefix; the uniqueness guarantee is per application.

Component v-model allows the ref returned by defineModel() to bind directly to native inputs. The parent and child then share the selected answer without manually forwarding change events.

defineProps() and defineModel() are compiler macros, so they are not imported. Here, required: true requires the caller to provide the component model; it does not make the HTML question required.

Inspect the result: each label should target an input inside its own component instance. Duplicate option values still produce duplicate suffixes within an instance, so validate your option data before rendering it.

5. Render independent questions and exercise state changes

Place this parent component beside RadioGroup.vue. It deliberately repeats the same options while giving each question its own model and native name.

<script setup>
import { ref } from 'vue'
import RadioGroup from './RadioGroup.vue'

const primary = ref('')
const backup = ref('')
const options = ref([
  { value: 'email', label: 'Email' },
  { value: 'phone', label: 'Phone' },
  { value: 'post', label: 'Post' }
])

function reverseOptions() {
  options.value = [...options.value].reverse()
}

function clearChoices() {
  primary.value = ''
  backup.value = ''
}
</script>

<template>
  <form>
    <RadioGroup
      v-model="primary"
      name="primary-contact"
      legend="Primary contact"
      :options="options"
    />
    <RadioGroup
      v-model="backup"
      name="backup-contact"
      legend="Backup contact"
      :options="options"
    />
    <button type="button" @click="reverseOptions">
      Reverse options
    </button>
    <button type="button" @click="clearChoices">
      Clear choices
    </button>
  </form>

  <p>Primary: {{ primary || 'None' }}</p>
  <p>Backup: {{ backup || 'None' }}</p>
</template>

Separate models alone are insufficient if independent questions accidentally share a native name within the same form. The browser’s radio grouping rules still apply. Unique IDs protect label targets; separate names protect independent selection. The simplified illustration uses readable prefixes to show that distinction.

Primary and backup contact groups use separate names and ID prefixes, so Phone and Email can be selected independently.

Choose Phone for Primary and Email for Backup. Reverse the list, then click each label again. Both answers should stay independent. Finally, activate Clear choices and confirm both groups become unanswered.

Vue documents reactive array replacement in its list-rendering guide. The reset above also changes the Vue models deliberately; it does not rely on a native form reset to synchronize application state. These buttons are a local verification harness, not a submission workflow.

6. Check the rendered behavior before integrating

Run these checks against the actual component, not just its source:

Action Expected result First thing to inspect if it fails
Click every option’s text Its own radio becomes checked Matching for and id
Select a different answer The displayed model changes Shared model and distinct values
Reverse the list The same answer stays selected Stable keys and unchanged values
Use both groups Each retains its own answer Different names and separate models
Clear choices Neither group remains checked Both parent refs are cleared
Inspect all rendered IDs No repeated input identifiers Instance prefixes and duplicate data

Also test without a mouse. For an ordinary group outside a toolbar, the W3C Radio Group Pattern describes Tab entry and exit, arrow-key selection, and Space activation. Native browsers can differ when entering an entirely unanswered group with Shift+Tab. Preserve native behavior rather than adding keyboard handlers just to match one browser.

Check that focus remains visible, then use your supported screen-reader and browser combination to verify the question, option name, and selected state. Repeat after reordering. If a focused option is removed, test recovery explicitly; stable keys do not guarantee a useful focus destination for a deleted element.

Put the group into your real form

You now have a data-driven radio group with inspectable labels, parent-owned selection, and identifiers that support repeated instances. Your next step is to add the real option data and connect submission and validation, keeping these regression checks alongside the component.

To compare this native pattern with a component implementation, open DOM Studio’s Radio Group playground and apply the same label-click, repeated-instance, and keyboard checks to its rendered output.

Sources

Recommended Reads