---
title: "Javascript Forms Radio buttons Example | Mobiscroll"
component: "Forms"
framework: "JavaScript"
library_version: "6.1.5"
url: "https://demo.mobiscroll.com/javascript/forms/radio-button"
---

# Radio buttons - JavaScript Forms demo

Javascript radio button demo for single select option lists. Use it with or without description, supports disabled styling. Plain JS api for usage everywhere.

- [Live demo](https://demo.mobiscroll.com/javascript/forms/radio-button)
- [View code on GitHub](https://github.com/acidb/mobiscroll-demos-javascript/tree/main/src/demos/form-components/forms/radio-button)
- This demo in other frameworks: [jQuery](https://demo.mobiscroll.com/jquery/forms/radio-button.md), [Angular](https://demo.mobiscroll.com/angular/forms/radio-button.md), [React](https://demo.mobiscroll.com/react/forms/radio-button.md), [Vue](https://demo.mobiscroll.com/vue/forms/radio-button.md)

## Description

Set up radio-button lists for mutually exclusive value selection. Different color presets are available.

## What this demo shows

- This demo shows different examples for radio buttons.
- **Single selection** Radio button groups for selecting one option from a set of mutually exclusive choices.
- **Option content** Radio buttons with labels and optional descriptive text.
- **States** Selected, unselected, and disabled radio button states.
- **Color presets** Primary, secondary, success, danger, warning, and info radio button colors.
- **Selection indicator** A checkmark identifies the currently selected option.

## Best for

- **Settings and preferences** Choosing one value from a small set of configuration options.
- **Forms and questionnaires** Presenting mutually exclusive answers that remain visible for quick comparison.
- **Plans and service levels** Selecting one option when labels and supporting descriptions help explain the differences.
- **Availability constraints** Showing choices that are currently unavailable with a disabled state.
- **Status-based choices** Using color presets to distinguish options with different meanings or levels of importance.

## Tutorial

```html
<div mbsc-radio-group>
    <label>
        <input mbsc-radio data-label="Radio Option 1" data-description="This is description for radio 1" name="group" type="radio" checked/>
    </label>
    <label>
        <input mbsc-radio data-label="Radio Option 2" data-description="This is description for radio 2" name="group" type="radio" />
    </label>
    <label>
        <input mbsc-radio data-label="Radio Option 3" name="group" type="radio" />
    </label>
    <label>
        <input mbsc-radio data-label="Disabled" type="radio" name="group" disabled />
    </label>
</div>
```

```html
<div mbsc-radio-group>
    <label>
        <input mbsc-radio data-label="Primary" data-color="primary" type="radio" name="colors" />
    </label>
    <label>
        <input mbsc-radio data-label="Secondary" data-color="secondary" type="radio" name="colors" />
    </label>
    <label>
        <input mbsc-radio data-label="Success" data-color="success" type="radio" name="colors" checked />
    </label>
    <label>
        <input mbsc-radio data-label="Danger" data-color="danger" type="radio" name="colors" />
    </label>
    <label>
        <input mbsc-radio data-label="Warning" data-color="warning" type="radio" name="colors" />
    </label>
    <label>
        <input mbsc-radio data-label="Info" data-color="info" type="radio" name="colors" />
    </label>
</div>
```

## Code

### JS

```js
mobiscroll.setOptions({
  theme: 'ios',
  themeVariant: 'light'
});
```

### HTML

```html
<div class="mbsc-form-group">
    <div class="mbsc-form-group-title">Radio buttons</div>
    <div mbsc-radio-group>
        <label>
            <input mbsc-radio data-label="Radio Option 1" data-description="This is description for radio 1" name="group" type="radio" checked/>
        </label>
        <label>
            <input mbsc-radio data-label="Radio Option 2" data-description="This is description for radio 2" name="group" type="radio" />
        </label>
        <label>
            <input mbsc-radio data-label="Radio Option 3" name="group" type="radio" />
        </label>
        <label>
            <input mbsc-radio data-label="Disabled" type="radio" name="group" disabled />
        </label>
    </div>
</div>
<div class="mbsc-form-group">
    <div class="mbsc-form-group-title">Radio button colors</div>
    <div mbsc-radio-group>
        <label>
            <input mbsc-radio data-label="Primary" data-color="primary" type="radio" name="colors" />
        </label>
        <label>
            <input mbsc-radio data-label="Secondary" data-color="secondary" type="radio" name="colors" />
        </label>
        <label>
            <input mbsc-radio data-label="Success" data-color="success" type="radio" name="colors" checked />
        </label>
        <label>
            <input mbsc-radio data-label="Danger" data-color="danger" type="radio" name="colors" />
        </label>
        <label>
            <input mbsc-radio data-label="Warning" data-color="warning" type="radio" name="colors" />
        </label>
        <label>
            <input mbsc-radio data-label="Info" data-color="info" type="radio" name="colors" />
        </label>
    </div>
</div>
```

## Implementation notes

- Radios are grouped with `RadioGroup`/`mbsc-radio-group` (JS/jQuery: a `div` carrying the `mbsc-radio-group` attribute); an individual option is `Radio`/`mbsc-radio`/`input[mbsc-radio][type="radio"]`.
- Mutual exclusivity within a group comes from a shared `name`: set on the group in React/Vue (`RadioGroup name="group"`), or on each input in JS/jQuery and Angular.
- `label` sets an option's primary text; `description` (`data-description` in JS/jQuery) adds secondary explanatory text beneath the label.
- Selection state is bound differently per framework: Angular and Vue bind the selected value on the group itself (`[(ngModel)]="group"` in Angular, `v-model="radio"` in Vue) with each option supplying its own `value`; React marks the initially selected option with `defaultChecked={true}`; JS/jQuery marks it with the plain `checked` attribute on that option's input.
- `disabled` makes a single option non-selectable: React `disabled={true}`, Vue `:disabled="true"`, Angular `[disabled]="true"`, JS/jQuery the bare `disabled` attribute.
- `color` (`data-color` in JS/jQuery) sets a preset color per option: `primary`, `secondary`, `success`, `danger`, `warning`, `info`.

## Run it in your project

1. If not signed up yet, or don't own a license, you can [start a free trial](https://mobiscroll.com/starttrial).

2. Clone the repository:

   ```
   git clone https://github.com/acidb/mobiscroll-demos-javascript.git
   ```

3. If not installed yet, install the Mobiscroll CLI from NPM:

   ```
   npm install -g @mobiscroll/cli
   ```

4. Config Mobiscroll - open a terminal window in the root directory and run:

   ```
   mobiscroll config javascript
   ```

5. Install dependencies - open a terminal window in the root directory and run:

   ```
   npm install
   ```

6. Run the project:

   ```
   npm run dev
   ```

On a trial, add `--trial` to the config command: `mobiscroll config javascript --trial`.

Running a demo locally requires a Mobiscroll trial or a license; setup is per framework at https://mobiscroll.com/docs/javascript/getting-started/installation

## Related demos

- Previous: [Switch](https://demo.mobiscroll.com/javascript/forms/switch.md) - Javascript switch/toggle demo with or without description. Alternative to the checkbox. Supports disabled styling.
