CSS-Only Toggle Switch

Treehouse on YouTubeWatch on YouTube

SaveMark complete

Sign in to save videos and track what you’ve finished.

BeginnerDesign Engineering4 min

About this video

Shows how to build a toggle switch for a user interface using only HTML and CSS, without JavaScript, using the ::after pseudo-element and the :checked pseudo-class. Suited to people starting out with web code.

What you’ll learn

  • Build a toggle switch with HTML and CSS alone
  • Draw the toggle knob with the ::after pseudo-element
  • Change the switch state using the :checked pseudo-class