Here at visualdev.fm we want to make sure that we have content for everyone. You will certainly find tutorials, blog posts, resources, and videos that require no coding knowledge. However, you will also find plenty of articles and resources for the advanced user as well. We break all of our content into different levels. You can read about our levels and see the difficulty of this post below.
You don't need to know anything about code. We'll provide you resources and you can use web apps and tools we recommend and just follow along.
You don't need to know how to code, but there might be a few lines of it in the tutorial. You will copy and paste and replace some values.
You need to know a little but about how code works. You have an understanding of the concepts and are ready to customize settings using code.
OMG. THIS IS COMPLICATED!! We're going to dive deep and build complicated items and workflows with nocode tools & you need a good grasp on code.
Tl;dr:
While building a side project recently, I found myself needing to incorporate a "switch" of sorts within my web app — ideally it would be a toggle switch. With Webflow, this isn't a native option but you can get pretty damn close with a few different methods:
I stumbled across Bootstrap Toggle while working on my side project. As I said above, it's a Javascript library that was intended to convert checkbox elements to (functioning!) toggle switches. It was originally intended to work within projects using the official Bootstrap styles, but I wanted to extend this a little further and allow Webflow users to create their own version of Bootstrap Styles visually and achieve the same functionality with minimal programming knowledge required.
So... we built it! You can see and clone the project into your Webflow Dashboard here, but let's get into what you need if you're building your project from scratch.
On the page containing the checkboxes that you want to turn into toggles, paste in the following code into the {% code-line %}Before < / body > tag{% code-line-end %} area:
{% code-block language="html" %}
<link href="https://rileyrichter.github.io/visualdev.fm/bootstrap-toggle/disabled.css" rel="stylesheet">
<!--- The above stylesheet is an OPTIONAL file in your final project. It contains styles relating to the :disabled state, which is shown to the enduser IF a toggle is disabled. We unfortunately can't style the :disabled statein Webflow natively (yet!), which is why we have to hand-write these styles.If you don't care for the :disabled state, then we would recommend deleting thisreference! Learn more about the disabled state here: https://www.w3schools.com/cssref/sel_disabled.asp--->
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
{% code-block-end %}
{% code-block language="hmtl" %}
<script>
var Webflow = Webflow || [];
Webflow.push(function () {
$("#btnOn").click(function(){
$('#toggle-demo').bootstrapToggle('on');
});
$("#btnOff").click(function(){
$('#toggle-demo').bootstrapToggle('off');
});
$("#btnToggle").click(function(){
$('#toggle-demo').bootstrapToggle('toggle');
});
$("#btnEnable").click(function(){
$('#toggle-demo').bootstrapToggle('enable');
});
$("#btnDisable").click(function(){
$('#toggle-demo').bootstrapToggle('disable');
});
});
</script>
{% code-block-end %}
There's a few different pieces here, so let's address each piece-by-piece:
Bootstrap Toggle works by using Bootstrap's style sheet to style the toggle elements themselves. You've got two options when it comes to how you want to style the toggles:
(1) USE VISUAL STYLES (within Webflow)
If you don't want to have to adhere to Bootstrap Styles and want to control the specifics of how your toggles look, we recommend simply copy-and-pasting the style guide from our cloneable project into yours. Cross-project copy-and-paste only works if you have cloneable the project yourself (doesn't work on read-only links), so be sure you clone it first.
IMPORTANT: If you do this, make sure that you are not using any of the following classes in your project, as they're required for Bootstrap Toggle:
{% code-line %}btn{% code-line-end %}, {% code-line %}.btn-primary{% code-line-end %}, {% code-line %}.btn-secondary{% code-line-end %}, {% code-line %}btn-success{% code-line-end %}, {% code-line %}.btn-info{% code-line-end %}, {% code-line %}.btn-warning{% code-line-end %}, {% code-line %}.btn-danger{% code-line-end %}, {% code-line %}.btn-light{% code-line-end %}, and {% code-line %}.btn-dark{% code-line-end %} .
The style guide itself is closely matched to Bootstrap's Default Colors to begin with, with each color being created as what's known as a Global Swatch in Webflow. Global Swatches allow you to change the color in one place (the style panel) and have the change reflected site-wide on EVERY element using that color swatch. It's incredible when it comes to saving time.
Furthermore, most colors you see here have a similar (but noticeably different) color pair — this is used for the {% code-line %}:hover{% code-line-end %} state on the toggles! You can alter this via the style panel as well. (How do I access and style the hover state?)
(2) USE BOOTSTRAP STYLES (Bootstrap Default)
If you like Bootstrap's Default Styles, have no intention of changing them, and want to include just get started without having to do cross-site copy-and-paste, replace the FIRST {% code-line %}< link >{% code-line-end %} element listed above (the rileyrichter.github.io element) with the following:
{% code-block language="html" %}
<link href="https://rileyrichter.github.io/visualdev.fm/bootstrap-toggle/Full-CSS-Bootstrap-Styles.css" rel="stylesheet">
{% code-block-end %}
This style sheet excludes pretty much every default Bootstrap Style that you DON'T need for Bootstrap Toggle. This step and file is required if you do not copy-and-paste the style guide from our project. If you see a line (or lines) of CSS that can be removed even more, let us know or create a pull request on Github.
This is pretty much the final step! Drag an {% code-line %}Embed{% code-line-end %} element onto the page and inside of it, add the following code at a minimum:
{% code-block language="html" %}
<input type="checkbox" data-toggle="toggle">
{% code-block-end %}
The {% code-line %}data-toggle="toggle"{% code-line-end %} attribute is incredibly important here, as that's how Bootstrap Toggle knows what checkboxes to convert to toggles and which ones to leave alone. You MUST have this attribute on any checkbox element you want converted to a toggle.
There are also other attributes you can add to the {% code-line %}< input >{% code-line-end %} element to extend the functionality / design:
Example attribute:
{% code-block language="html" %}
data-on="Hello<br>World" data-off="Goodbye<br>World"
{% code-block-end %}
{% code-block language="html" %}
<style>
.slow .toggle-group { transition: left 0.7s; -webkit-transition: left 0.7s; }
</style>
<input type="checkbox" checked data-toggle="toggle" data-style="slow" data-on="Slow" data-off="Speed">
{% code-block-end %}
The full documentation talks about more potential attributes you can add, so feel free to scan through that and add any attributes you'd like.
I hope this helps! All credit to the original maker of Bootstrap Toggle, Min Hur for The New York Times, for making this awesome library.