Dark Mode Toggle
Moon-to-sun emoji toggle that shifts between a dark and a warm golden background.
Dark Mode Toggle the 16th of 23 designs in the 23 CSS Checkboxes collection. The design is implemented in pure CSS — no JavaScript required. Copy the HTML and CSS panels below into your project. Because the demo is pure CSS, it works in any framework or templating engine you happen to use. The design honours prefers-reduced-motion and uses real semantic markup, so it ships accessibility-ready out of the box.
Live preview
The code
<label class="cb-darkmode">
<input class="cb-darkmode__input" type="checkbox" />
<span class="cb-darkmode__track">
<span class="cb-darkmode__thumb">
<span class="cb-darkmode__icon"></span>
</span>
</span>
<span>Toggle theme</span>
</label> .cb-darkmode {
display: inline-flex; align-items: center;
gap: 10px; cursor: pointer; user-select: none;
}
.cb-darkmode__input { display: none; }
.cb-darkmode__track {
width: 52px; height: 28px; border-radius: 14px;
background: #1a1a2e;
border: 1px solid rgba(255,255,255,.1);
position: relative; transition: background .4s;
}
.cb-darkmode__thumb {
position: absolute; top: 4px; left: 4px;
width: 20px; height: 20px; border-radius: 50%;
background: #fff; font-size: 11px;
display: flex; align-items: center;
justify-content: center;
box-shadow: 0 2px 8px rgba(0,0,0,.3);
transition: transform .4s cubic-bezier(.23,1,.32,1);
}
.cb-darkmode__icon::before { content: "\1F319"; }
.cb-darkmode__input:checked + .cb-darkmode__track {
background: linear-gradient(135deg, #f5a84a, #ffd700);
}
.cb-darkmode__input:checked
+ .cb-darkmode__track .cb-darkmode__thumb {
transform: translateX(24px);
}
.cb-darkmode__input:checked
+ .cb-darkmode__track .cb-darkmode__icon::before {
content: "\2600\FE0F";
}