Challenge #002 - Toggle switch

- Takes about 3 minutes to complete

Toggle switches are so hot right now, but ever-so-often they’re implemented terribly, so naturally, that means we’re going to do a damn good job of this one to counter that!

This second challenge is free to participate, but the solution to the challenge will be for paying members only, so subscribe to see the upcoming solution.

What you’re building

Demo shows toggle switch toggle between “on”, which is illustrated with a moon icon and “off”, which is illustrated with a sun icon. A consistent “dark mode” label is visible.

The brief

Take the design assets and re-create this toggle switch with whatever front-end technology you want. Don’t worry too much about how the toggle switch affects wider state, such as affecting the page theme, but if you want to push it further, go for it!

Make sure that your challenge solution does the following as a minimum:

  • Uses semantic elements
  • Is usable with mouse, touch and keyboard
  • Is appropriately labeled
  • Presents focus state (you can find it in the design assets)

Bonus points awarded if:

  • You use modern CSS
  • Your solution is lightweight and performant
  • Your solution is fully accessible and uses appropriate aria attributes
  • You create appropriate transitions and/or animations between states


I’ve used Figma to design this challenge because some folks couldn’t access Sketch. With Figma, you can run it with a completely free account!

Here’s some assets to get you going:

Here are some CSS Custom Properties for your colours:

:root {
  --color-day-bg: #0984e3;
  --color-day-icon: #ffe4a1;
  --color-night-bg: #032b43;
  --color-night-icon: #b9c6d3;
  --color-light: #ffffff;
  --color-dark: #4a4a4a;
  --color-shadow-light: rgba(48, 48, 48, 0.15);
  --color-shadow-mid: rgba(0, 0, 0, 0.25);
  --color-shadow-dark: rgba(0, 0, 0, 0.9);


This challenge is for you to learn and if you want to just want keep it to yourself, that’s all good. If you want to share it with the Front-End Challenge Club Community, tweet a publicly accessible link, using the hashtag: #FrontEndChallengesClub or directly to @FEChallengeClub and I’ll pick up and link to my favourites in my solution post.

Wrapping up

Enjoy this challenge and remember: we’re all in this together, so if folks have questions, tweet using the hashtag #FrontEndChallengesClub or tweet directly to @FEChallengeClub.

Only paying members get to see my solution to this challenge, so make sure you subscribe to a paid plan.

See you at the next one 👋

Other challenges

  1. #006 - Auto-scrolling, responsive grid

  2. #005 - Tabs

  3. #004 - Progress Button

  4. #003 - Duotone Card

  5. #001 - Email sign-up form

Sign up for a membership

Front-End Challenges club members get all sorts of benefits, including:

  • Full access to all content
  • Access to a private community of other members
  • Access to exclusive AMA sessions

Membership starts at $10 per month or $95 per year.

Sign Up For A Membership