Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 5 text BEFORE switch-checkbox (without extra addons/plugins)

I use Bootstrap 5 and I wand to use a switch-toggle.

I don't want to use any other addons, but only with bootstrap.

How to put a Text BEFORE the toggle switch.

This does not work:

<div class="form-check form-switch">
  off
  <input type="checkbox" class="form-check-input" id="site_state">
  <label for="site_state" class="form-check-label">on</label>
</div>

Anyone have an idea ?

like image 221
Akkie Avatar asked Aug 26 '26 16:08

Akkie


1 Answers

What if you put your Off label before the checkbox and make everything display: inline-block?

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"/>


<div class="container">
    <div class="row">
        <div class="col">
            <div class="d-inline-block me-1">Off</div>
            <div class="form-check form-switch d-inline-block">
                <input type="checkbox" class="form-check-input" id="site_state" style="cursor: pointer;">
                <label for="site_state" class="form-check-label">On</label>
                </div>
        </div>
    </div>
</div>
like image 173
Rich DeBourke Avatar answered Aug 30 '26 08:08

Rich DeBourke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!