This unique CSS slider switch has different rendering outcomes based on the resolution:
- It is pixel-perfect on a laptop display with a resolution of around 1400 x 800.
- However, it is not pixel-perfect on a 1920 x 1080 display with Windows 10's "Scale and layout" set to 100% and browser zoom at 125%.
- Interestingly, it becomes pixel-perfect on a 4k display when Scale and layout are at 150%, along with a browser zoom set to 150%.
When I say it's "not pixel perfect", there is some subpixel white space between the border and the dark circle as shown in this image:
https://i.sstatic.net/zq6bd.png
Adjusting the value from transparent -9px
can help bring the circle closer to the left border, but it can create overlap with a new circle on the right side.
The question remains: How can we achieve a perfect rendering for this switch regardless of the resolution?
.switch {
appearance: none;
padding: 9px 18px;
border-radius: 13px;
background: radial-gradient(circle 9px, #001122 100%, transparent 100%) transparent -9px;
border: 1px solid #001122;
}
.switch:checked {
background-position: 9px;
}
<input type="checkbox" class="switch">