DEV Community

Cover image for How I Made This Realistic Red Switch (Pure CSS)

How I Made This Realistic Red Switch (Pure CSS)

Yoav Kadosh on March 22, 2021

I created this pen last week after stumbling across this 3D Red Switch design on Dribble. Since then it gained a lot of popularity (much more t...
Collapse
 
jh3y profile image
Jhey Tompkins

Looks great! One tiny thing I'd change 🤏

Move the input outside the label and make the clickable area of the label half the size of the switch. That way, you can't click the side that's pressed in. Then it'll be "realistic" 😉

Collapse
 
ykadosh profile image
Yoav Kadosh

Yes, others have suggested this also, however, I think that this is problematic in terms of accessibility since the user expects the whole switch to be clickable.

Collapse
 
jh3y profile image
Jhey Tompkins

I think that would be the least of the concerns in making this accessible 😅

However, If you want to take it a step further though, divs aren't allowed as children of label 👍
Switch them to span and use display to style them up.

Thread Thread
 
ykadosh profile image
Yoav Kadosh

Yes, I guess you're right... 😅
And that's a good point regarding the divs 👍

Collapse
 
devggaurav profile image
Gaurav

Nicely explained!

Collapse
 
moopet profile image
Ben Sinclair

This looks really nice (though it's not "pure CSS").

If I could make one suggestion? Drop the opacity on the characters to maybe 0.8 or so so they let a little of the light through.

Collapse
 
ykadosh profile image
Yoav Kadosh

Thanks for the feedback, interesting suggestion.
May I ask why you don't consider this as pure CSS?

Collapse
 
moopet profile image
Ben Sinclair

It needs a bunch of HTML to back it up? There are several DIVs there whose sole purpose is presentation.

Thread Thread
 
ykadosh profile image
Yoav Kadosh

Pure CSS does not mean zero HTML, you need HTML elements to apply the CSS to.

Thread Thread
 
moopet profile image
Ben Sinclair

I know what you're getting at. But pure CSS to me means using the elements that are already there, and no more.

If you're allowing adding HTML, then you may as well say, "Let's have 1920x1080 DIVs and give them all unique IDs", because then "Pure CSS" will let you do full HD video, and it all becomes meaningless.

To me, pure CSS is what you could apply to an existing page without having to ask the authors to change their markup.

Thread Thread
 
samjarman profile image
Sam Jarman 👨🏼‍💻

I’ve always thought developers meant “no JavaScript” when they say pure CSS/ HTML.

Semantics aside, I’d say this is pretty impressive right?

Thread Thread
 
moopet profile image
Ben Sinclair

Nobody says that though, they say "Pure CSS". It's kind of a trend.

Yes, it looks really good!

Collapse
 
7tonshark profile image
Elliot Nelson

Nice work! Never knew you could stack multiple box-shadow like that.

Collapse
 
christiangroeber profile image
Christian Gröber

I LOVE THIS SO MUCH!

Spent a good 15 minutes just toggling the switch, it's so satisfying! Great job

Collapse
 
shivams136 profile image
Shivam Sharma

Amazing step-by-step guide. I have learned a lot. Thanks.
Since when I saw your last article, I was curious to have a step-by-step guide and you provided better than my expectations.

Collapse
 
ykadosh profile image
Yoav Kadosh

Thanks, Shivam! 🙏

Collapse
 
juhoheinonen profile image
juhoheinonen

Looks wonderful. Thanks!

Collapse
 
ocdalex profile image
Alex Walker

Very cool and some of the possibilities of css very well explained, have bookmarked for future reference.

Collapse
 
pris_stratton profile image
pris stratton

Wow! Incredible. Reminds me a bit of HAL9000 too.

Collapse
 
nikmors profile image
Nik Moraitis

This is genius! Great job. I will definitely try this one. The level of realism you are giving it it's amazing. Thank you for sharing this!

Collapse
 
bartosz profile image
Bartosz Wójcik

One of the best if not THE BEST looking CSS gems I've seen in my entire life! Well done Yoav!

Collapse
 
ykadosh profile image
Yoav Kadosh

Thank you!

Collapse
 
codeboi profile image
Timothy Rowell

Nice, I saw this on Codepen I know you made it.

Collapse
 
abhishekcghosh profile image
Abhishek Ghosh

Impressive!

Collapse
 
samjarman profile image
Sam Jarman 👨🏼‍💻

This is really impressive. Nice.

Collapse
 
andreidascalu profile image
Andrei Dascalu

Amazing! Actual result aside, as far as tutorials/showcases go, this point but point approach works great for teaching.

Collapse
 
pabloverdier profile image
pablo verdier

Genial! and very well explained, thnks

Collapse
 
possan profile image
Per-Olov Jernberg

I have been clicking this for too long now, beautiful attention to detail!

Collapse
 
muzammilaalpha profile image
muzammilaalpha

Nicely explained!

Collapse
 
ayhan_yildiz_d7b5f946bb72 profile image
ayhan yildiz

impressive work! very interesting that so many feedback for improvement 🙄