DevPlatform
Home
Components
Search
Submit
Earn
Login
Sign Up Free
Day Night Toggle - Preview | DevPlatform
DevPlatform
Categories
Accordion
Animation
Box Shadow
Button
Card
Footer
Form
Gallery
Hero Section
Inputs
Loader
Marquee
Modal
Modules
Navbar
Progress Bar
Radio Buttons
Search-Bar
Sections
Slider
Tab
Timeline
Toggle
Day Night Toggle
jitesh208
Jan 28, 2026
2
0
Share
Live Preview
Refresh
Live Editor
HTML
CSS
JS
HTML
CSS
JavaScript
1
<div class="container"> <div class="title">Cosmic Switch</div> <input type="checkbox" id="cosmic-toggle" class="toggle-input"> <label for="cosmic-toggle" class="toggle-label"> <div class="orbit-ring"></div> <div class="toggle-sphere"></div> <div class="particle"></div> <div class="particle"></div> <div class="particle"></div> <div class="energy-wave"></div> <div class="energy-wave"></div> <div class="energy-wave"></div> <div class="energy-wave"></div> </label> <div class="status-text">Day Mode</div>
1
* { margin: 0; padding: 0; box-sizing: border-box; } body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #0a0e27; overflow: hidden; position: relative; } /* Animated starfield background */ body::before, body::after { content: ''; position: absolute; width: 100%; height: 100%; top: 0; left: 0; } body::before { background: radial-gradient(2px 2px at 20px 30px, #eee, transparent), radial-gradient(2px 2px at 60px 70px, #fff, transparent), radial-gradient(1px 1px at 50px 50px, #ddd, transparent), radial-gradient(1px 1px at 130px 80px, #fff, transparent), radial-gradient(2px 2px at 90px 10px, #fff, transparent); background-size: 200px 200px; animation: stars 20s linear infinite; opacity: 0.3; } body::after { background: radial-gradient(1px 1px at 10px 10px, #fff, transparent), radial-gradient(1px 1px at 100px 50px, #ddd, transparent), radial-gradient(2px 2px at 150px 150px, #eee, transparent); background-size: 250px 250px; animation: stars 30s linear infinite reverse; opacity: 0.2; } @keyframes stars { from { transform: translateY(0); } to { transform: translateY(-200px); } } .container { text-align: center; z-index: 1; } .title { font-family: 'Orbitron', monospace; font-size: 1.2em; color: #fff; text-transform: uppercase; letter-spacing: 4px; margin-bottom: 50px; text-shadow: 0 0 20px rgba(0, 255, 255, 0.5); animation: flicker 3s infinite alternate; } @keyframes flicker { 0%, 100% { opacity: 1; } 50% { opacity: 0.8; } } /* Hide the default checkbox */ .toggle-input { display: none; } /* Toggle container */ .toggle-label { display: inline-block; width: 200px; height: 200px; cursor: pointer; position: relative; } /* Outer orbit ring */ .orbit-ring { position: absolute; width: 100%; height: 100%; border: 3px solid rgba(0, 255, 255, 0.3); border-radius: 50%; animation: rotate 4s linear infinite; } .orbit-ring::before { content: ''; position: absolute; top: -6px; left: 50%; transform: translateX(-50%); width: 6px; height: 6px; background: #00ffff; border-radius: 50%; box-shadow: 0 0 15px #00ffff, 0 0 30px #00ffff; } @keyframes rotate { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } /* Central sun/moon toggle */ .toggle-sphere { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 80px; height: 80px; border-radius: 50%; background: linear-gradient(135deg, #ff6b35, #f7931e); box-shadow: 0 0 40px rgba(255, 107, 53, 0.8), 0 0 80px rgba(247, 147, 30, 0.5), inset -10px -10px 20px rgba(0, 0, 0, 0.3); transition: all 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55); z-index: 2; } /* Sun rays */ .toggle-sphere::before { content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 120px; height: 120px; background: linear-gradient(0deg, transparent 45%, rgba(255, 107, 53, 0.3) 50%, transparent 55%), linear-gradient(45deg, transparent 45%, rgba(255, 107, 53, 0.3) 50%, transparent 55%), linear-gradient(90deg, transparent 45%, rgba(255, 107, 53, 0.3) 50%, transparent 55%), linear-gradient(135deg, transparent 45%, rgba(255, 107, 53, 0.3) 50%, transparent 55%); border-radius: 50%; animation: rotate-rays 8s linear infinite; opacity: 1; transition: opacity 0.6s ease; } @keyframes rotate-rays { from { transform: translate(-50%, -50%) rotate(0deg); } to { transform: translate(-50%, -50%) rotate(360deg); } } /* Orbital particles */ .particle { position: absolute; top: 50%; left: 50%; width: 8px; height: 8px; background: #ff6b35; border-radius: 50%; box-shadow: 0 0 10px #ff6b35; opacity: 0; transition: all 0.6s ease; } .particle:nth-child(1) { animation: orbit1 3s linear infinite; } .particle:nth-child(2) { animation: orbit2 3s linear infinite; animation-delay: 1s; } .particle:nth-child(3) { animation: orbit3 3s linear infinite; animation-delay: 2s; } @keyframes orbit1 { 0% { transform: translate(-50%, -50%) rotate(0deg) translateX(70px) rotate(0deg); opacity: 1; } 100% { transform: translate(-50%, -50%) rotate(360deg) translateX(70px) rotate(-360deg); opacity: 1; } } @keyframes orbit2 { 0% { transform: translate(-50%, -50%) rotate(120deg) translateX(70px) rotate(-120deg); opacity: 1; } 100% { transform: translate(-50%, -50%) rotate(480deg) translateX(70px) rotate(-480deg); opacity: 1; } } @keyframes orbit3 { 0% { transform: translate(-50%, -50%) rotate(240deg) translateX(70px) rotate(-240deg); opacity: 1; } 100% { transform: translate(-50%, -50%) rotate(600deg) translateX(70px) rotate(-600deg); opacity: 1; } } /* Energy waves */ .energy-wave { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 80px; height: 80px; border: 2px solid rgba(255, 107, 53, 0.6); border-radius: 50%; opacity: 0; animation: wave-pulse 2s ease-out infinite; } .energy-wave:nth-child(2) { animation-delay: 0.5s; } .energy-wave:nth-child(3) { animation-delay: 1s; } .energy-wave:nth-child(4) { animation-delay: 1.5s; } @keyframes wave-pulse { 0% { width: 80px; height: 80px; opacity: 0.8; } 100% { width: 200px; height: 200px; opacity: 0; } } /* CHECKED STATE - Transform to Moon */ .toggle-input:checked ~ .toggle-label .toggle-sphere { background: linear-gradient(135deg, #4a5568, #cbd5e0); box-shadow: 0 0 40px rgba(203, 213, 224, 0.6), 0 0 80px rgba(74, 85, 104, 0.4), inset 15px -15px 30px rgba(0, 0, 0, 0.5); transform: translate(-50%, -50%) rotate(180deg); } /* Hide sun rays when checked */ .toggle-input:checked ~ .toggle-label .toggle-sphere::before { opacity: 0; } /* Moon craters */ .toggle-input:checked ~ .toggle-label .toggle-sphere::after { content: ''; position: absolute; width: 100%; height: 100%; border-radius: 50%; background: radial-gradient(circle at 30% 30%, rgba(0, 0, 0, 0.3) 8px, transparent 8px), radial-gradient(circle at 60% 50%, rgba(0, 0, 0, 0.2) 12px, transparent 12px), radial-gradient(circle at 45% 75%, rgba(0, 0, 0, 0.25) 6px, transparent 6px), radial-gradient(circle at 70% 70%, rgba(0, 0, 0, 0.2) 8px, transparent 8px); } /* Change particle colors when checked */ .toggle-input:checked ~ .toggle-label .particle { background: #cbd5e0; box-shadow: 0 0 15px #cbd5e0, 0 0 30px rgba(203, 213, 224, 0.5); } /* Change orbit ring when checked */ .toggle-input:checked ~ .toggle-label .orbit-ring { border-color: rgba(203, 213, 224, 0.4); animation: rotate 4s linear infinite reverse; } .toggle-input:checked ~ .toggle-label .orbit-ring::before { background: #cbd5e0; box-shadow: 0 0 15px #cbd5e0, 0 0 30px #cbd5e0; } /* Change energy waves when checked */ .toggle-input:checked ~ .toggle-label .energy-wave { border-color: rgba(203, 213, 224, 0.4); } /* Status text */ .status-text { font-family: 'Orbitron', monospace; font-size: 1.5em; margin-top: 40px; color: #ff6b35; text-transform: uppercase; letter-spacing: 3px; font-weight: 900; transition: all 0.6s ease; text-shadow: 0 0 20px currentColor; } .toggle-input:checked ~ .status-text { color: #cbd5e0; } /* Hover effect */ .toggle-label:hover .toggle-sphere { transform: translate(-50%, -50%) scale(1.1); } .toggle-input:checked ~ .toggle-label:hover .toggle-sphere { transform: translate(-50%, -50%) rotate(180deg) scale(1.1); } /* Click effect */ .toggle-label:active .toggle-sphere { transform: translate(-50%, -50%) scale(0.95); }
1
const toggle = document.getElementById('cosmic-toggle'); const statusText = document.querySelector('.status-text'); toggle.addEventListener('change', function() { if (this.checked) { statusText.textContent = 'Night Mode'; } else { statusText.textContent = 'Day Mode'; } });
Comments
0
Want to comment?
Please
login
or
sign up
to post comments.
No comments yet
Be the first to comment on this component!
Comments 0
Want to comment?
Please login or sign up to post comments.
No comments yet
Be the first to comment on this component!