1

Zero Trickery Custom Radios and Checkboxes - CSS-Tricks

 2 years ago
source link: https://css-tricks.com/zero-trickery-custom-radios-and-checkboxes/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Zero Trickery Custom Radios and Checkboxes

Chris Coyier on

Nov 17, 2021

Grow sales with a smart marketing platform.

I feel like half of all “custom-designed radio buttons and checkboxes” do two things:

  1. Make them bigger
  2. Colorize them

I always think of SurveyMonkey for having big chunky radios and checkboxes. And indeed, just poking at their interface quickly, even internally, the app uses has those all over the place:

Screen-Shot-2021-11-14-at-12.43.57-PM.png?resize=452%2C414&ssl=1SurveyMonkey’s implementation appears to be pseudo-elements on a <label> element with icon fonts and such.

I think it’s worth noting that if that’s all you are doing, you might be able to do that with zero CSS trickery. Just… make them bigger and colorize them.

Like…

input[type="radio"],
input[type="checkbox"] {
  width: 3em;
  height: 3rem;
  accent-color: green;
}

That’ll chunk those suckers up and colorize them pretty good!

Screen-Shot-2021-11-14-at-12.47.31-PM.png?resize=942%2C256&ssl=1Firefox
Screen-Shot-2021-11-14-at-12.47.16-PM.png?resize=996%2C282&ssl=1Chrome

Except (obligatory sad trombone) in Safari:

Screen-Shot-2021-11-14-at-12.48.24-PM.png?resize=375%2C117&ssl=1Safari

We’re so close to having some very simple CSS to accomplish the main use-case for custom checkboxes and radios. But no cigar, that is, unless you can bring yourself to just not care about the Safari UI (it is still perfectly functional, after all).

If you do need to give up and go for a completely custom design, Stephanie Eckles has got you covered:

In related news, I always think of a “toggle” UI control as a set of 2 radio buttons progressively enhanced, but it turns out <button> is the way, as Michelle Barker covers here. No native UI for slider toggle thingies, alas.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK