<div class="pricing-toggle">
<span id="monthly" class="label active">Monthly</span>
<div class="toggle-bg" onclick="togglePricing()">
<div class="toggle-circle" id="circle"></div>
</div>
<span id="yearly" class="label">Yearly <span class="discount">-20%</span></span>
</div>.pricing-toggle {
font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
display: flex;
align-items: center;
gap: 15px;
background: #f9fafb;
padding: 10px 20px;
border-radius: 50px;
display: inline-flex;
border: 1px solid #e5e7eb;
}
.toggle-bg {
width: 50px;
height: 26px;
background: #e5e7eb;
border-radius: 50px;
position: relative;
cursor: pointer;
transition: background 0.3s;
}
.toggle-circle {
width: 20px;
height: 20px;
background: white;
border-radius: 50%;
position: absolute;
top: 3px;
left: 3px;
transition: transform 0.3s;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
.label {
font-weight: 500;
color: #9ca3af;
cursor: pointer;
transition: color 0.3s;
}
.label.active {
color: #1f2937;
font-weight: 600;
}
.discount {
font-size: 0.7rem;
background: #dbeafe;
color: #2563eb;
padding: 2px 6px;
border-radius: 4px;
margin-left: 5px;
}
/* Active State for Toggle */
.pricing-toggle.yearly .toggle-bg {
background: #3b82f6;
}
.pricing-toggle.yearly .toggle-circle {
transform: translateX(24px);
}function togglePricing() {
const container = document.querySelector(".pricing-toggle");
const mLabel = document.getElementById("monthly");
const yLabel = document.getElementById("yearly");
container.classList.toggle("yearly");
if (container.classList.contains("yearly")) {
mLabel.classList.remove("active");
yLabel.classList.add("active");
// Add logic to update prices here
} else {
mLabel.classList.add("active");
yLabel.classList.remove("active");
}
}Nothing to show yetType HTML, CSS or JavaScript and your page appears here.
Click any element to find its code Esc
Check this code before you run it
It came from a shared link. It runs with fewer permissions, so it cannot open pop-ups, submit forms or start downloads.
0.00s / 0.00s
Nothing has animated yet. Hover, click or type in the preview and each CSS animation, transition or
element.animate() call shows up here as it plays.