How to Make Toggle Switch In CSS?
![How to Make Toggle Switch In CSS?](https://sp-ao.shortpixel.ai/client/to_webp,q_glossy,ret_img,w_808,h_345/https://imageoptimize.help/wp-content/uploads/2022/02/how-to-make-toggle-button.png.webp)
What is Toggle Switch Button?
A toggle switch is a graphical control element that allows the user to make a choice between two mutually exclusive states. Originally toggle switches were used primarily in touchscreen-based user interfaces, but they have later become commonplace in desktop and web applications. Wikipedia
Making a custom toggle button is super simple.
Open your code editor and create Two files for HTML and CSS and now connect your CSS file with HTML by using <link href="stylesheet" href="yourstyle.css" />
Copy the HTML code from below and paste it to your HTML Code (Inside the <body>
tag).
<label class="label"> <div class="toggle"> <input class="toggle-state" type="checkbox" name="check" value="check" /> <div class="indicator"></div> </div> <div class="label-text">no more emails plz</div> </label>
If insertion of HTML code is done then This is the time to Copy CSS Code From below and paste it to your stylesheet that is connected to your HTML File.
*{ box-sizing: border-box; } body { height: 100vh; display: flex; align-items: center; justify-content: center; overflow: hidden; font-family: 'IBM Plex Sans Condensed', sans-serif; font-weight: 300; background-color: #ecf0f3; } .label { display: inline-flex; align-items: center; cursor: pointer; color: #394a56; } .label-text { margin-left: 16px; } .toggle { isolation: isolate; position: relative; height: 30px; width: 60px; border-radius: 15px; overflow: hidden; box-shadow: -8px -4px 8px 0px #ffffff, 8px 4px 12px 0px #d1d9e6, 4px 4px 4px 0px #d1d9e6 inset, -4px -4px 4px 0px #ffffff inset; } .toggle-state { display: none; } .indicator { height: 100%; width: 200%; background: #ecf0f3; border-radius: 15px; transform: translate3d(-75%, 0, 0); transition: transform 0.4s cubic-bezier(0.85, 0.05, 0.18, 1.35); box-shadow: -8px -4px 8px 0px #ffffff, 8px 4px 12px 0px #d1d9e6; } .toggle-state:checked ~ .indicator { transform: translate3d(25%, 0, 0); }
Toggle Switch In Codepen
For UI Color Concept you can use our Color Palet tool.
Leave a Reply