webdevpuneet.com

Bootstrap Feature Flag Toggle Panel — Free HTML CSS JS Snippet

Bootstrap Feature Flag Toggle Panel · Dashboards · Plain HTML, CSS & JS · Live preview

CategoryDashboards

Copy & paste

Source Code

<div class="container py-5 d-flex justify-content-center">
  <div class="card bsflag-card">
    <div class="card-body p-3">
      <h6 class="fw-bold mb-2">Feature flags</h6>
      <ul class="list-unstyled mb-0" id="bsflagList"></ul>
    </div>
  </div>
</div>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month, 7 days free), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

Each flag pairs an on/off state with a rollout percentage, kept consistent with each other automatically
The rollout slider only exists in the DOM while its flag is actually enabled
Disabling a flag resets its rollout instead of leaving a stale, misleading percentage behind
Re-enabling a flag defaults to a full 100% rollout rather than an ambiguous leftover value
Two narrowly-scoped delegated listeners (change and input) handle every row without per-row re-binding

About this UI Snippet

Bootstrap Feature Flag Toggle Panel — HTML, CSS & JavaScript

Screenshot of the Bootstrap Feature Flag Toggle Panel snippet rendered live

Each flag is a small object carrying both an on boolean and a rollout percentage, and the two are kept honest with respect to each other rather than tracked independently — switching a flag off sets rollout = 0, since a disabled flag showing a stale "25%" the next time someone glances at it would misrepresent what's actually happening in production. Switching a flag back on from a zeroed rollout jumps it to 100%, on the assumption that re-enabling a flag most often means "turn it back on for everyone," not "quietly resume some old partial rollout."

The rollout slider only renders at all while its flag is on — d-none toggles alongside the switch's own checked state — so there's no way to see (or accidentally drag) a rollout percentage for a flag that's currently off, which would be a meaningless value to display or edit in the first place.

The switch and the slider are handled by two separate, narrowly-scoped listeners on the same list — one listening for change events matching .bsflag-toggle, the other for input events matching .bsflag-slider — using event delegation on the parent <ul> rather than attaching a listener to every individual row, so newly rendered rows are automatically covered without re-binding anything after every render() call.

Step by step

How to Use

  1. 1
    Load the snippetFour flags show, two enabled with visible rollout sliders and two disabled with no slider showing.
  2. 2
    Drag the "AI summaries" rollout sliderThe percentage label updates live as you drag, without needing to release first.
  3. 3
    Turn off "New navigation"Its rollout slider disappears entirely, and its rollout resets to 0% internally.
  4. 4
    Turn "New navigation" back onIt jumps straight to 100% rollout rather than an ambiguous or stale prior value.
  5. 5
    Turn on "Dark mode"Its rollout slider appears fresh, ready to be adjusted from 100%.

Real-world uses

Common Use Cases

🚩
Engineering release controls
Give product and engineering one place to switch features on or off, with each flag carrying both an enabled state and a rollout percentage.
📈
Gradual rollout dashboards
Ramp a feature to a growing share of users, with the rollout slider existing in the DOM only while its flag is actually enabled.
🧪
A/B and experiment panels
Reuse the same toggle for experiments, where disabling a flag resets its rollout to zero instead of leaving a stale, misleading percentage.
🚢
Deployment status pairing
Pair with the Bootstrap deployment status panel so a flag change and the release it belongs to appear together.

Got questions?

Frequently Asked Questions

A disabled flag with a leftover "25%" showing (even if hidden from view) would misrepresent the flag's actual state the next time someone re-enables it and expects a fresh decision, not a silently resumed old value.

This demo treats re-enabling as a deliberate "turn it back on" decision defaulting to full rollout; a real system might instead ask explicitly, or genuinely remember the last rollout value if that behavior is preferred — both are reasonable, differing product decisions.

Live — it listens for the "input" event, which fires continuously while dragging, rather than "change", which only fires once the drag ends.

Yes. Keep the flags array in component state, update the relevant flag's on/rollout fields immutably on toggle or slider change, and conditionally render the rollout slider based on that flag's on value.