{"id":14972553,"url":"https://github.com/palcarazm/bootstrap5-toggle","last_synced_at":"2025-10-01T21:30:58.473Z","repository":{"id":41349234,"uuid":"509172495","full_name":"palcarazm/bootstrap5-toggle","owner":"palcarazm","description":"Bootstrap 5 Toggle is a bootstrap plugin/widget that converts checkboxes into toggles.","archived":false,"fork":true,"pushed_at":"2024-12-23T06:53:15.000Z","size":3080,"stargazers_count":42,"open_issues_count":2,"forks_count":5,"subscribers_count":3,"default_branch":"v5","last_synced_at":"2025-01-09T16:18:36.445Z","etag":null,"topics":["bootstrap","bootstrap-checkbox","bootstrap-switch","bootstrap-toggle","bootstrap5","switch","toggle","toggle-buttons","toggle-switch","toggle-switches"],"latest_commit_sha":null,"homepage":"https://palcarazm.github.io/bootstrap5-toggle/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"gitbrent/bootstrap4-toggle","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/palcarazm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null},"funding":{"github":["palcarazm"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2022-06-30T17:25:43.000Z","updated_at":"2024-12-31T14:40:05.000Z","dependencies_parsed_at":"2023-02-08T17:45:53.566Z","dependency_job_id":null,"html_url":"https://github.com/palcarazm/bootstrap5-toggle","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palcarazm%2Fbootstrap5-toggle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palcarazm%2Fbootstrap5-toggle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palcarazm%2Fbootstrap5-toggle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palcarazm%2Fbootstrap5-toggle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/palcarazm","download_url":"https://codeload.github.com/palcarazm/bootstrap5-toggle/tar.gz/refs/heads/v5","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234902725,"owners_count":18904521,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bootstrap","bootstrap-checkbox","bootstrap-switch","bootstrap-toggle","bootstrap5","switch","toggle","toggle-buttons","toggle-switch","toggle-switches"],"created_at":"2024-09-24T13:47:06.914Z","updated_at":"2025-10-01T21:30:58.468Z","avatar_url":"https://github.com/palcarazm.png","language":"JavaScript","readme":"[![GitHub license](https://img.shields.io/github/license/palcarazm/bootstrap5-toggle.svg?color=informational)](https://github.com/palcarazm/bootstrap5-toggle/blob/master/LICENSE)\n[![Latest release](https://img.shields.io/github/package-json/v/palcarazm/bootstrap5-toggle/v5?logo=github)](https://github.com/palcarazm/bootstrap5-toggle/releases)\n[![Bootstrap 5](https://img.shields.io/static/v1?label=bootstrap\u0026message=%5E5.0.0\u0026color=informational\u0026logo=bootstrap\u0026logoColor=white)](https://getbootstrap.com/docs/5.0)\n[![JSDelivr Badge](https://img.shields.io/jsdelivr/npm/hm/bootstrap5-toggle?label=hits\u0026logo=jsdelivr\u0026logoColor=white)](https://www.jsdelivr.com/package/npm/bootstrap5-toggle)\n[![NPM Badge](https://img.shields.io/npm/dm/bootstrap5-toggle?logo=npm)](https://www.npmjs.com/package/bootstrap5-toggle)\n[![Build](https://img.shields.io/github/actions/workflow/status/palcarazm/bootstrap5-toggle/build.yml?branch=v5\u0026logo=npm)](https://github.com/palcarazm/bootstrap5-toggle/actions?query=workflow%3A%22Build+Check%22)\n[![Test](https://img.shields.io/github/actions/workflow/status/palcarazm/bootstrap5-toggle/cypress.yml?branch=v5\u0026label=tests\u0026logo=cypress)](https://github.com/palcarazm/bootstrap5-toggle/actions?query=workflow%3A%22Cypress+Tests%22)\n[![Security](https://img.shields.io/snyk/vulnerabilities/npm/bootstrap5-toggle@5.1.2?logo=snyk)](https://snyk.io/advisor/npm-package/bootstrap5-toggle)\n[![EOL](https://img.shields.io/endpoint?url=https%3A%2F%2Fpalcarazm.github.io%2Fbootstrap5-toggle%2Fapi%2Feol%2Fv5)](https://github.com/palcarazm/bootstrap5-toggle/security/policy)\n[![Funding](https://img.shields.io/badge/sponsor-30363D?style=flat\u0026logo=GitHub-Sponsors\u0026logoColor=#white)](https://github.com/sponsors/palcarazm)\n[![Rate this package](https://badges.openbase.com/js/rating/bootstrap5-toggle.svg?token=rNvznTVToo+EmX5g+KTvfYqI9+YTWJeUWTxPj7tLA6o=)](https://openbase.com/js/bootstrap5-toggle?utm_source=embedded\u0026utm_medium=badge\u0026utm_campaign=rating-badge\u0026utm_term=js/bootstrap5-toggle)\n\n# Bootstrap 5 Toggle\n\n**Bootstrap 5 Toggle** is a bootstrap plugin/widget that converts checkboxes into toggles.\n\n---\n\n#### Library Distributions\n\n|                           Version                            |                                                                             Bootstrap Support                                                                             |                                                                             Last Release                                                                              |                                                                                     End of Life                                                                                      |\n| :----------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |\n| [v5](https://github.com/palcarazm/bootstrap5-toggle/tree/v5) | [![Bootstrap 5](https://img.shields.io/static/v1?label=bootstrap\u0026message=%5E5.0.0\u0026color=informational\u0026logo=bootstrap\u0026logoColor=white)](https://getbootstrap.com/docs/5.0) | [![Latest release](https://img.shields.io/github/package-json/v/palcarazm/bootstrap5-toggle/v5?logo=github)](https://github.com/palcarazm/bootstrap5-toggle/releases) | [![EOL](https://img.shields.io/endpoint?url=https%3A%2F%2Fpalcarazm.github.io%2Fbootstrap5-toggle%2Fapi%2Feol%2Fv5)](https://github.com/palcarazm/bootstrap5-toggle/security/policy) |\n| [v4](https://github.com/palcarazm/bootstrap5-toggle/tree/v4) | [![Bootstrap 5](https://img.shields.io/static/v1?label=bootstrap\u0026message=%5E5.0.0\u0026color=informational\u0026logo=bootstrap\u0026logoColor=white)](https://getbootstrap.com/docs/5.0) | [![Latest release](https://img.shields.io/github/package-json/v/palcarazm/bootstrap5-toggle/v4?logo=github)](https://github.com/palcarazm/bootstrap5-toggle/releases) | [![EOL](https://img.shields.io/endpoint?url=https%3A%2F%2Fpalcarazm.github.io%2Fbootstrap5-toggle%2Fapi%2Feol%2Fv4)](https://github.com/palcarazm/bootstrap5-toggle/security/policy) |\n| [v3](https://github.com/palcarazm/bootstrap5-toggle/tree/v3) | [![Bootstrap 4](https://img.shields.io/static/v1?label=bootstrap\u0026message=%5E4.0.0\u0026color=informational\u0026logo=bootstrap\u0026logoColor=white)](https://getbootstrap.com/docs/4.0) | [![Latest release](https://img.shields.io/github/package-json/v/palcarazm/bootstrap5-toggle/v3?logo=github)](https://github.com/palcarazm/bootstrap5-toggle/releases) | [![EOL](https://img.shields.io/endpoint?url=https%3A%2F%2Fpalcarazm.github.io%2Fbootstrap5-toggle%2Fapi%2Feol%2Fv3)](https://github.com/palcarazm/bootstrap5-toggle/security/policy) |\n\nSee EOL for each version in [Security Policy Page](https://github.com/palcarazm/bootstrap5-toggle/security/policy).\n\n# Demos\n\n**Demos and API Docs:** https://palcarazm.github.io/bootstrap5-toggle/\n\n# Related Bootstrap Plugins\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/palcarazm/bs-darkmode\" title=\"Boostrap Darkmode\"\n    \u003e\u003cimg\n      src=\"https://github-readme-stats.vercel.app/api/pin/?username=palcarazm\u0026repo=bs-darkmode\u0026border_radius=10\u0026show_owner=true\"\n  /\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n---\n\n\u003c!-- To update TOC run .\\node_modules\\.bin\\doctoc README.md --github --\u003e\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n\n- [Installation](#installation)\n  - [CDN](#cdn)\n    - [ECMAS Interface](#ecmas-interface)\n    - [jQuery Interface](#jquery-interface)\n  - [Download](#download)\n  - [NPM](#npm)\n  - [Yarn](#yarn)\n- [Usage](#usage)\n  - [Initialize With HTML](#initialize-with-html)\n  - [Initialize With Code](#initialize-with-code)\n- [API](#api)\n  - [Options](#options)\n  - [Methods](#methods)\n- [Events](#events)\n  - [Event Propagation](#event-propagation)\n  - [Stopping Event Propagation](#stopping-event-propagation)\n  - [API vs Input](#api-vs-input)\n- [Collaborators welcom!](#collaborators-welcom)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n---\n\n# Installation\n\n## CDN\n\n[![JSDelivr Badge](https://img.shields.io/jsdelivr/npm/hm/bootstrap5-toggle?label=hits\u0026logo=jsdelivr\u0026logoColor=white)](https://www.jsdelivr.com/package/npm/bootstrap5-toggle)\n\n### ECMAS Interface\n\n```html\n\u003clink\n  href=\"https://cdn.jsdelivr.net/npm/bootstrap5-toggle@5.1.2/css/bootstrap5-toggle.min.css\"\n  rel=\"stylesheet\" /\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/bootstrap5-toggle@5.1.2/js/bootstrap5-toggle.ecmas.min.js\"\u003e\u003c/script\u003e\n```\n\n### jQuery Interface\n\n```html\n\u003clink\n  href=\"https://cdn.jsdelivr.net/npm/bootstrap5-toggle@5.1.2/css/bootstrap5-toggle.min.css\"\n  rel=\"stylesheet\" /\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/bootstrap5-toggle@5.1.2/js/bootstrap5-toggle.jquery.min.js\"\u003e\u003c/script\u003e\n```\n\n## Download\n\n[![Latest release](https://img.shields.io/github/package-json/v/palcarazm/bootstrap5-toggle/v5?logo=github)](https://github.com/palcarazm/bootstrap5-toggle/releases)\n\n## NPM\n\n[![NPM Badge](https://img.shields.io/npm/dm/bootstrap5-toggle?logo=npm)](https://www.npmjs.com/package/bootstrap5-toggle)\n\n```ksh\nnpm install bootstrap5-toggle@5.1.2\n```\n\n## Yarn\n\n```ksh\nyarn add bootstrap5-toggle@5.1.2\n```\n\n# Usage\n\n## Initialize With HTML\n\nAdd `data-toggle=\"toggle\"` to automatically convert a plain checkbox into a bootstrap 5 toggle.\n\n```html\n\u003cinput id=\"chkToggle\" type=\"checkbox\" data-toggle=\"toggle\" /\u003e\n```\n\n## Initialize With Code\n\nToggles can also be initialized via JavaScript code.\n\nEX: Initialize id `chkToggle` with a single line of JavaScript.\n\n```html\n\u003cinput id=\"chkToggle\" type=\"checkbox\" checked /\u003e\n\u003cscript\u003e\n  document.querySelector(\"#chkToggle\").bootstrapToggle();\n\u003c/script\u003e\n```\n\n# API\n\n## Options\n\n- Options can be passed via data attributes or JavaScript\n- For data attributes, append the option name to `data-` (ex: `data-on=\"Enabled\"`)\n\n```html\n\u003cinput\n  type=\"checkbox\"\n  data-toggle=\"toggle\"\n  data-onlabel=\"Enabled\"\n  data-offlabel=\"Disabled\" /\u003e\n\u003cinput type=\"checkbox\" id=\"toggle-two\" /\u003e\n\u003cscript\u003e\n  document.querySelector(\"#toggle-two\").bootstrapToggle({\n    on: \"Enabled\",\n    off: \"Disabled\",\n  });\n\u003c/script\u003e\n```\n\n| Name       | Type        | Default     | Description                                                                                                                                              |\n| ---------- | ----------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `onlabel`  | string/html | \"On\"        | Text of the on toggle                                                                                                                                    |\n| `offlabel` | string/html | \"Off\"       | Text of the off toggle                                                                                                                                   |\n| `size`     | string      | \"normal\"    | Size of the toggle. Possible values are: `large`, `normal`, `small`, `mini`.                                                                             |\n| `onstyle`  | string      | \"primary\"   | Style of the on toggle. Possible values are: `primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark` and with `outline-` prefix  |\n| `offstyle` | string      | \"secondary\" | Style of the off toggle. Possible values are: `primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark` and with `outline-` prefix |\n| `onvalue`  | string      | _null_      | Sets on state value                                                                                                                                      |\n| `offvalue` | string      | _null_      | Sets off state value                                                                                                                                     |\n| `ontitle`  | string      | _null_      | Title of the on toggle                                                                                                                                   |\n| `offtitle` | string      | _null_      | Title of the off toggle                                                                                                                                  |\n| `style`    | string      |             | Appends the value to the class attribute of the toggle. This can be used to apply custom styles. Refer to Custom Styles for reference.                   |\n| `width`    | integer     | _null_      | Sets the width of the toggle. if set to _null_, width will be auto-calculated.                                                                           |\n| `height`   | integer     | _null_      | Sets the height of the toggle. if set to _null_, height will be auto-calculated.                                                                         |\n| `tabindex` | integer     | 0           | Sets the tabindex of the toggle.                                                                                                                         |\n| `tristate` | boolean     | false       | Sets tristate support                                                                                                                                    |\n\n## Methods\n\nMethods can be used to control toggles directly.\n\n```html\n\u003cinput id=\"toggle-demo\" type=\"checkbox\" data-toggle=\"toggle\" /\u003e\n\u003cscript\u003e\n  const toggleDemo = document.querySelector(\"#toggle-demo\");\n\u003c/script\u003e\n```\n\n| Method        | Example                                       | Description                                                                           |\n| ------------- | --------------------------------------------- | ------------------------------------------------------------------------------------- |\n| initialize    | `toggleDemo.bootstrapToggle()`                | Initializes the toggle plugin with options                                            |\n| destroy       | `toggleDemo.bootstrapToggle('destroy')`       | Destroys the toggle                                                                   |\n| rerender      | `toggleDemo.bootstrapToggle('rerender')`      | Rerender toggle with the appropriated size. Useful when parent is collapsed at first. |\n| on            | `toggleDemo.bootstrapToggle('on')`            | Sets the toggle to 'On' state                                                         |\n| off           | `toggleDemo.bootstrapToggle('off')`           | Sets the toggle to 'Off' state                                                        |\n| toggle        | `toggleDemo.bootstrapToggle('toggle')`        | Toggles the state of the toggle on/off                                                |\n| enable        | `toggleDemo.bootstrapToggle('enable')`        | Enables the toggle                                                                    |\n| disable       | `toggleDemo.bootstrapToggle('disable')`       | Disables the toggle                                                                   |\n| readonly      | `toggleDemo.bootstrapToggle('readonly')`      | Disables the toggle but preserve checkbox enabled                                     |\n| indeterminate | `toggleDemo.bootstrapToggle('indeterminate')` | Sets the toggle to 'indeterminate' state                                              |\n| determinate   | `toggleDemo.bootstrapToggle('determinate')`   | Sets the toggle to 'determinate' state                                                |\n\n# Events\n\n## Event Propagation\n\nNote All events are propagated to and from input element to the toggle.\n\nYou should listen to events from the `\u003cinput type=\"checkbox\"\u003e` directly rather than look for custom events.\n\n```html\n\u003cinput id=\"toggle-event\" type=\"checkbox\" data-toggle=\"toggle\" /\u003e\n\u003cdiv id=\"console-event\"\u003e\u003c/div\u003e\n\u003cscript\u003e\n  document.querySelector(\"#toggle-event\").change(function (e) {\n    document\n      .querySelector(\"#console-event\")\n      .html(\"Toggle: \" + e.target.prop(\"checked\"));\n  });\n\u003c/script\u003e\n```\n\n## Stopping Event Propagation\n\nPassing `true` to the on, off, toggle, determinate and indeterminate methods will enable the silent option to prevent the control from propagating the change event in cases where you want to update the controls on/off state, but do not want to fire the onChange event.\n\n```html\n\u003cinput id=\"toggle-silent\" type=\"checkbox\" data-toggle=\"toggle\" /\u003e\n\u003cbutton class=\"btn btn-success\" onclick=\"toggleApiOnSilent()\"\u003e\n  On by API (silent)\n\u003c/button\u003e\n\u003cbutton class=\"btn btn-success\" onclick=\"toggleApiOffSilent()\"\u003e\n  Off by API (silent)\n\u003c/button\u003e\n\u003cbutton class=\"btn btn-warning\" onclick=\"toggleApiOnNotSilent()\"\u003e\n  On by API (not silent)\n\u003c/button\u003e\n\u003cbutton class=\"btn btn-warning\" onclick=\"toggleApiOffNotSilent()\"\u003e\n  On by API (not silent)\n\u003c/button\u003e\n\u003cscript\u003e\n  function toggleApiOnSilent() {\n    document.querySelector(\"#toggle-silent\").bootstrapToggle(\"on\", true);\n  }\n  function toggleApiOffSilent() {\n    document.querySelector(\"#toggle-silent\").bootstrapToggle(\"off\", true);\n  }\n  function toggleApiOnNotSilent() {\n    document.querySelector(\"#toggle-silent\").bootstrapToggle(\"on\");\n  }\n  function toggleApiOffNotSilent() {\n    document.querySelector(\"#toggle-silent\").bootstrapToggle(\"off\");\n  }\n\u003c/script\u003e\n```\n\n## API vs Input\n\nThis also means that using the API or Input to trigger events will work both ways.\n\n```html\n\u003cinput id=\"toggle-trigger\" type=\"checkbox\" data-toggle=\"toggle\" /\u003e\n\u003cbutton class=\"btn btn-success\" onclick=\"toggleApiOn()\"\u003eOn by API\u003c/button\u003e\n\u003cbutton class=\"btn btn-danger\" onclick=\"toggleApiOff()\"\u003eOff by API\u003c/button\u003e\n\u003cbutton class=\"btn btn-success\" onclick=\"toggleInpOn()\"\u003eOn by Input\u003c/button\u003e\n\u003cbutton class=\"btn btn-danger\" onclick=\"toggleInpOff()\"\u003eOff by Input\u003c/button\u003e\n\u003cscript\u003e\n  function toggleApiOn() {\n    document.querySelector(\"#toggle-trigger\").bootstrapToggle(\"on\");\n  }\n  function toggleApiOff() {\n    document.querySelector(\"#toggle-trigger\").bootstrapToggle(\"off\");\n  }\n  function toggleInpOn() {\n    document.querySelector(\"#toggle-trigger\").prop(\"checked\", true).change();\n  }\n  function toggleInpOff() {\n    document.querySelector(\"#toggle-trigger\").prop(\"checked\", false).change();\n  }\n\u003c/script\u003e\n```\n\n# Collaborators welcom!\n\n- :sos: ¿Do you need some help? Open a issue in [GitHub help wanted](https://github.com/palcarazm/bootstrap5-toggle/issues/new?assignees=\u0026labels=help+wanted\u0026template=help-wanted.md\u0026title=%5BHELP%5D)\n- :bug: ¿Do you find a bug? Open a issue in [GitHub bug report](https://github.com/palcarazm/bootstrap5-toggle/issues/new?assignees=\u0026labels=bug\u0026template=bug_report.md\u0026title=%5BBUG%5D)\n- :bulb: ¿Do you have a great idea? Open a issue in [GitHub feature request](https://github.com/palcarazm/bootstrap5-toggle/issues/new?assignees=\u0026labels=enhancement\u0026template=feature_request.md\u0026title=%5BFEATURE%5D)\n- :computer: ¿Do you know how to fix a bug? Open a pull request in [GitHub pull repuest](https://github.com/palcarazm/bootstrap5-toggle/compare).\n\n[![GitHub Contributors](https://contrib.rocks/image?repo=palcarazm/bootstrap5-toggle)](https://github.com/palcarazm/bootstrap5-toggle/graphs/contributors)\n\n¿Do you like the project? Give us a :star: in [GitHub](https://github.com/palcarazm/bootstrap5-toggle).\n","funding_links":["https://github.com/sponsors/palcarazm"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalcarazm%2Fbootstrap5-toggle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpalcarazm%2Fbootstrap5-toggle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalcarazm%2Fbootstrap5-toggle/lists"}