codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Follow publication

Bootstrap 5 — Radio Buttons and Checkboxes

John Au-Yeung
codeburst
Published in
4 min readJul 15, 2020

Photo by amirali mirhashemian on Unsplash

Bootstrap 5 is in alpha when this was written and so the details of this article are subject to change.

Bootstrap is a popular UI library for any JavaScript apps. In this article, we’ll look at how to style radio buttons and checkboxes with Bootstrap 5.

Radio Buttons

Bootstrap 5 also provides styles for radio buttons.

To add them, we can write:

<div class="form-check">
<input class="form-check-input" type="radio" name="fruit" id="apple">
<label class="form-check-label" for="apple">
apple
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="fruit" id="orange" checked>
<label class="form-check-label" for="orange">
orange
</label>
</div>

We set the type attribute to radio . And we set the name of both radio buttons to be the same so that we can select between them. Also, we use the form-check class to style the radio button. Inside the divs we use the form-check-input and form-check-label classes as we did with checkboxes.

Disabled Radio Buttons

We can disable radio buttons with the disabled attribute. Then we won’t be able to interact with them. They’ll also be lighter than usual.

For example, we can write:

<div class="form-check">
<input class="form-check-input" type="radio" name="flexRadioDefault" id="apple" disabled>
<label class="form-check-label" for="apple">
apple
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="flexRadioDefault" id="orange" checked disabled>
<label class="form-check-label" for="orange">
orange
</label>
</div>

Switches

We can add switches with the form-check and form-switch classes. The type of the inputs are set to checkbox .

For example, we can write:

<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="apple">
<label class="form-check-label" for="apple">apple</label>
</div>
<div class="form-check form-switch">
<input…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

No responses yet

Write a response