2017-07-17 18:41:58 +00:00
|
|
|
---
|
2017-07-29 12:02:00 +00:00
|
|
|
title: Radio button
|
2024-03-21 16:11:54 +00:00
|
|
|
layout: docs
|
|
|
|
theme: library
|
2017-07-17 18:41:58 +00:00
|
|
|
doc-tab: form
|
|
|
|
doc-subtab: radio
|
2018-04-09 15:15:58 +00:00
|
|
|
breadcrumb:
|
2024-03-21 16:11:54 +00:00
|
|
|
- home
|
|
|
|
- documentation
|
|
|
|
- form
|
|
|
|
- form-radio
|
2018-04-09 15:15:58 +00:00
|
|
|
meta:
|
|
|
|
colors: false
|
|
|
|
sizes: false
|
|
|
|
variables: false
|
2017-07-17 18:41:58 +00:00
|
|
|
---
|
2024-07-07 16:59:24 +00:00
|
|
|
|
2017-07-17 18:41:58 +00:00
|
|
|
{% capture radio_example %}
|
|
|
|
<div class="control">
|
|
|
|
<label class="radio">
|
2024-03-21 16:11:54 +00:00
|
|
|
<input type="radio" name="answer" />
|
2017-07-17 18:41:58 +00:00
|
|
|
Yes
|
|
|
|
</label>
|
|
|
|
<label class="radio">
|
2024-03-21 16:11:54 +00:00
|
|
|
<input type="radio" name="answer" />
|
2017-07-17 18:41:58 +00:00
|
|
|
No
|
|
|
|
</label>
|
|
|
|
</div>
|
2024-07-07 16:59:24 +00:00
|
|
|
{% endcapture %} {% capture radio_default_example %}
|
2017-07-17 18:41:58 +00:00
|
|
|
<div class="control">
|
|
|
|
<label class="radio">
|
2024-03-21 16:11:54 +00:00
|
|
|
<input type="radio" name="foobar" />
|
2017-07-17 18:41:58 +00:00
|
|
|
Foo
|
|
|
|
</label>
|
|
|
|
<label class="radio">
|
2024-03-21 16:11:54 +00:00
|
|
|
<input type="radio" name="foobar" checked />
|
2017-07-17 18:41:58 +00:00
|
|
|
Bar
|
|
|
|
</label>
|
|
|
|
</div>
|
2024-07-07 16:59:24 +00:00
|
|
|
{% endcapture %} {% capture radio_disabled_example %}
|
2017-07-17 18:41:58 +00:00
|
|
|
<div class="control">
|
|
|
|
<label class="radio">
|
2024-03-21 16:11:54 +00:00
|
|
|
<input type="radio" name="rsvp" />
|
2017-07-17 18:41:58 +00:00
|
|
|
Going
|
|
|
|
</label>
|
|
|
|
<label class="radio">
|
2024-03-21 16:11:54 +00:00
|
|
|
<input type="radio" name="rsvp" />
|
2017-07-17 18:41:58 +00:00
|
|
|
Not going
|
|
|
|
</label>
|
|
|
|
<label class="radio" disabled>
|
2024-03-21 16:11:54 +00:00
|
|
|
<input type="radio" name="rsvp" disabled />
|
2017-07-17 18:41:58 +00:00
|
|
|
Maybe
|
|
|
|
</label>
|
|
|
|
</div>
|
2024-07-07 16:59:24 +00:00
|
|
|
{% endcapture %} {% capture list_of_radios %}
|
|
|
|
<div class="radios">
|
|
|
|
<label class="radio">
|
|
|
|
<input type="radio" name="rsvp" />
|
|
|
|
Going
|
|
|
|
</label>
|
|
|
|
<label class="radio">
|
|
|
|
<input type="radio" name="rsvp" />
|
|
|
|
Not going
|
|
|
|
</label>
|
|
|
|
<label class="radio" disabled>
|
|
|
|
<input type="radio" name="rsvp" disabled />
|
|
|
|
Maybe
|
|
|
|
</label>
|
|
|
|
</div>
|
2017-07-17 18:41:58 +00:00
|
|
|
{% endcapture %}
|
|
|
|
|
2018-04-09 15:15:58 +00:00
|
|
|
<div class="content">
|
|
|
|
<p>
|
2024-07-07 16:59:24 +00:00
|
|
|
The <code>radio</code> class is a simple wrapper around the
|
|
|
|
<code><input type="radio"></code> HTML elements. It is intentionally
|
|
|
|
not styled, to preserve cross-browser compatibility and the user experience.
|
2018-04-09 15:15:58 +00:00
|
|
|
</p>
|
|
|
|
<p>
|
2024-07-07 16:59:24 +00:00
|
|
|
Make sure the linked radio buttons have the <strong>same value</strong> for
|
|
|
|
their <code>name</code> HTML attribute.
|
2018-04-09 15:15:58 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
2017-07-17 18:41:58 +00:00
|
|
|
|
2018-04-09 15:15:58 +00:00
|
|
|
<div class="columns">
|
2024-03-21 16:11:54 +00:00
|
|
|
<div class="column is-half">{{ radio_example }}</div>
|
2021-01-27 23:30:42 +00:00
|
|
|
<div class="column is-half bd-highlight-full">
|
2024-07-07 16:59:24 +00:00
|
|
|
{% highlight html -%} {{- radio_example -}} {%- endhighlight %}
|
2018-04-09 15:15:58 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-07-17 18:41:58 +00:00
|
|
|
|
2018-04-09 15:15:58 +00:00
|
|
|
<div class="content">
|
|
|
|
<p>
|
2024-07-07 16:59:24 +00:00
|
|
|
You can check a radio button by <strong>default</strong> by adding the
|
|
|
|
<code>checked</code> HTML attribute to the
|
2024-03-21 16:11:54 +00:00
|
|
|
<code><input></code> element.
|
2018-04-09 15:15:58 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
2017-07-17 18:41:58 +00:00
|
|
|
|
2018-04-09 15:15:58 +00:00
|
|
|
<div class="columns">
|
2024-03-21 16:11:54 +00:00
|
|
|
<div class="column is-half">{{ radio_default_example }}</div>
|
2021-01-27 23:30:42 +00:00
|
|
|
<div class="column is-half bd-highlight-full">
|
2024-07-07 16:59:24 +00:00
|
|
|
{% highlight html -%} {{- radio_default_example -}} {%- endhighlight %}
|
2018-04-09 15:15:58 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-07-17 18:41:58 +00:00
|
|
|
|
2018-04-09 15:15:58 +00:00
|
|
|
<div class="content">
|
|
|
|
<p>
|
2024-07-07 16:59:24 +00:00
|
|
|
You can <strong>disable</strong> a radio button by adding the
|
|
|
|
<code>disabled</code> HTML attribute to both the
|
2024-03-21 16:11:54 +00:00
|
|
|
<code><label></code> and the <code><input></code>.
|
2018-04-09 15:15:58 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
2017-07-17 18:41:58 +00:00
|
|
|
|
2018-04-09 15:15:58 +00:00
|
|
|
<div class="columns">
|
2024-03-21 16:11:54 +00:00
|
|
|
<div class="column is-half">{{ radio_disabled_example }}</div>
|
2021-01-27 23:30:42 +00:00
|
|
|
<div class="column is-half bd-highlight-full">
|
2024-07-07 16:59:24 +00:00
|
|
|
{% highlight html -%} {{- radio_disabled_example -}} {%- endhighlight %}
|
2017-07-17 18:41:58 +00:00
|
|
|
</div>
|
2018-04-09 15:15:58 +00:00
|
|
|
</div>
|
2024-07-07 16:59:24 +00:00
|
|
|
|
|
|
|
{% include docs/elements/anchor.html name="List of Radio Buttons" %}
|
|
|
|
|
|
|
|
<div class="content">
|
|
|
|
<p>
|
|
|
|
If you want to list several radio buttons, wrap them in a
|
|
|
|
<code><div class="radios"></code> element:
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="block">{{- list_of_radios -}}</div>
|
|
|
|
|
|
|
|
{% highlight html -%} {{- list_of_radios -}} {%- endhighlight %}
|