Toggle Style | Description | Example |
---|---|---|
Basic Toggle | A simple, rounded toggle switch | |
iOS-style Toggle | A toggle switch inspired by iOS design | |
Material Design Toggle | A toggle switch following Material Design guidelines | |
Neon Toggle | A toggle switch with a neon glow effect | |
Flat Toggle | A minimalist, flat design toggle switch | |
Dark Mode Toggle | A toggle switch for dark mode with moon/sun icons, dark by default | |
Minimal Dark Toggle | A simple, minimal toggle switch for dark mode, dark by default |
1. Basic Toggle
CSS:
.toggle-switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.toggle-switch input {
opacity: 0;
width: 0;
height: 0;
}
.toggle-slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .4s;
border-radius: 34px;
}
.toggle-slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
transition: .4s;
border-radius: 50%;
}
input:checked + .toggle-slider {
background-color: #2196F3;
}
input:checked + .toggle-slider:before {
transform: translateX(26px);
}
2. iOS-style Toggle
CSS:
.toggle-ios {
position: relative;
display: inline-block;
width: 50px;
height: 30px;
}
.toggle-ios input {
opacity: 0;
width: 0;
height: 0;
}
.toggle-ios-slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #e9e9ea;
transition: .4s;
border-radius: 30px;
}
.toggle-ios-slider:before {
position: absolute;
content: "";
height: 28px;
width: 28px;
left: 1px;
bottom: 1px;
background-color: white;
transition: .4s;
border-radius: 50%;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}
input:checked + .toggle-ios-slider {
background-color: #4cd964;
}
input:checked + .toggle-ios-slider:before {
transform: translateX(20px);
}
3. Material Design Toggle
CSS:
.toggle-material {
position: relative;
display: inline-block;
width: 36px;
height: 14px;
}
.toggle-material input {
opacity: 0;
width: 0;
height: 0;
}
.toggle-material-slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0,0,0,0.38);
transition: .4s;
border-radius: 14px;
}
.toggle-material-slider:before {
position: absolute;
content: "";
height: 20px;
width: 20px;
left: -2px;
bottom: -3px;
background-color: #fafafa;
transition: .4s;
border-radius: 50%;
box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.12), 0 1px 5px 0 rgba(0,0,0,0.2);
}
input:checked + .toggle-material-slider {
background-color: rgba(33,150,243,0.5);
}
input:checked + .toggle-material-slider:before {
transform: translateX(20px);
background-color: #2196F3;
}
4. Neon Toggle
CSS:
.toggle-neon {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.toggle-neon input {
opacity: 0;
width: 0;
height: 0;
}
.toggle-neon-slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #333;
transition: .4s;
border-radius: 34px;
box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
}
.toggle-neon-slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: #fff;
transition: .4s;
border-radius: 50%;
}
input:checked + .toggle-neon-slider {
background-color: #000;
box-shadow: inset 0 0 10px rgba(0,255,255,0.5);
}
input:checked + .toggle-neon-slider:before {
transform: translateX(26px);
box-shadow: 0 0 15px #00ffff;
}
5. Flat Toggle
CSS:
.toggle-flat {
position: relative;
display: inline-block;
width: 60px;
height: 30px;
}
.toggle-flat input {
opacity: 0;
width: 0;
height: 0;
}
.toggle-flat-slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #bdc3c7;
transition: .4s;
}
.toggle-flat-slider:before {
position: absolute;
content: "";
height: 22px;
width: 22px;
left: 4px;
bottom: 4px;
background-color: white;
transition: .4s;
}
input:checked + .toggle-flat-slider {
background-color: #2ecc71;
}
input:checked + .toggle-flat-slider:before {
transform: translateX(30px);
}
6. Dark Mode Toggle
CSS:
.toggle-dark-mode {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.toggle-dark-mode input {
opacity: 0;
width: 0;
height: 0;
}
.toggle-dark-mode-slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #2c3e50;
transition: .4s;
border-radius: 34px;
}
.toggle-dark-mode-slider:before {
position: absolute;
content: "🌙";
display: flex;
align-items: center;
justify-content: center;
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: #34495e;
transition: .4s;
border-radius: 50%;
}
input:checked + .toggle-dark-mode-slider {
background-color: #f1c40f;
}
input:checked + .toggle-dark-mode-slider:before {
content: "☀️";
transform: translateX(26px);
background-color: #f39c12;
}
7. Minimal Dark Toggle
CSS:
.toggle-minimal-dark {
position: relative;
display: inline-block;
width: 50px;
height: 24px;
}
.toggle-minimal-dark input {
opacity: 0;
width: 0;
height: 0;
}
.toggle-minimal-dark-slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #333;
transition: .4s;
border-radius: 24px;
}
.toggle-minimal-dark-slider:before {
position: absolute;
content: "";
height: 16px;
width: 16px;
left: 4px;
bottom: 4px;
background-color: #ddd;
transition: .4s;
border-radius: 50%;
}
input:checked + .toggle-minimal-dark-slider {
background-color: #ddd;
}
input:checked + .toggle-minimal-dark-slider:before {
transform: translateX(26px);
background-color: #333;
}
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to CSS,
- How to create a circular Image using pure CSS Code
- Horizontally Center Align tag in HTML using CSS
- Add scroll to div element in HTML Css
- Change CSS Background Opacity with Examples
- How to make text bold using CSS
- How to place two div elements next to each other
- Vertically Center Text in a DIV Element
- align image at middle of div element
- Tailwind CSS Hello World Example
- How to make div or text in html unselectable using CSS
- Only Chessboard using HTML and CSS Code Example
- Simple CSS Grid Example
- How to set CSS background-Image Property
- CSS Background Opacity with Examples
- reCAPTCHA Implementation Tutorial
- List of 32 CSS cursors web developers must know about
- How to Vertically Center Align Text in a Div using CSS Code Example
- 10 Must Know CSS Border Styles with Examples
- Tutorial : Simple Lightweight Pure CSS based Vertical Navigation Menu
- CSS: Apply opacity only for div background and not text
- Set Falling Show on Website for Christmas using Pure CSS Code
- How to make jsfiddle bootstrap ready
- Elegant CSS Box Shadows Ideas
- Responsive Web Design with CSS Media Queries: A Beginner's Tutorial [Updated for 2023]
- How to Center Align Image in Bootstrap
More Posts:- Difference Between Predicate and Function in Java 8 - Java
- Install Microsoft OneDrive on Mac - MacOS
- SharePoint Server 2016 installation System Hardware requirements - SharePoint
- How to change Ping TTL value on macOS - MacOS
- Set Environment Variable in PowerShell for Mac - Powershell
- Install Node on Mac Ventura 13 - MacOS
- How to hide or remove quick launch left navigation from SharePoint Online Modern site page - SharePoint
- 5 Reasons Why Jupyter Notebook is Not Opening and Solutions - Python