Skip to main content

Lesson 7 of 10

Custom Checkboxes & Radio Buttons

Default browser checkboxes and radio buttons look different on every OS and are hard to style. This mini-build creates beautiful custom checkboxes and radio buttons using CSS - maintaining full accessibility and keyboard support.

15 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Custom Control Technique

  • Hide the default input - appearance: none or opacity: 0 with absolute positioning
  • Style the label - The visible control is built with the label element and pseudo-elements
  • Use :checked - input:checked + label::before to change the visual state
  • Maintain accessibility - The actual <input> stays in the DOM for screen readers and keyboard
  • Focus styles - Style :focus-visible on the input to show keyboard focus ring
  • Transition - Add smooth transitions for check/uncheck state changes

Mini-Build: Custom Controls

Mini-Build: Custom ControlsHTML
HTML
✓ Valid
HTML|29 lines|✓ Valid syntax
UTF-8

Tip

Always keep the real <input> in the DOM when building custom controls. Use appearance: none or visually hide it (not display: none). The real input provides keyboard support, screen reader access, and form submission for free.

Diagram
Loading diagram…

Hide native inputs visually while maintaining keyboard focus accessibility and custom SVG checkmarks

Common Mistake

Using display: none on checkbox inputs removes them from the accessibility tree - screen readers can't find them, keyboard Tab skips them. Use opacity: 0 + position: absolute instead to keep them accessible.

Practice Task

Customize the controls in the editor: (1) Change checked checkbox color to a gradient, (2) Add scale(1.1) animation on check, (3) Add :focus-visible outline for keyboard users, (4) Build a toggle switch using the same input:checked + label pattern.

Quick Quiz

Key Takeaways

  • Default browser checkboxes and radio buttons look different on every OS and are hard to style.
  • Hide the default input - appearance: none or opacity: 0 with absolute positioning
  • Style the label - The visible control is built with the label element and pseudo-elements
  • Use :checked - input:checked + label::before to change the visual state

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/10 done