Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
CSS checkbox examples (getcssscan.com)
147 points by guivr on Nov 1, 2022 | hide | past | favorite | 60 comments


Unfortunately, almost all of them are terrible for accessibility. Most of them cannot be focussed by keyboard. And even more do not have a focus styling. I did not check their code, but that alone does not make a good impression.

Please consider accessibility when you have the urge to build custom (form) components. For checkboxes, have a look at https://www.w3.org/WAI/ARIA/apg/patterns/checkbox/ for some guidelines.


Tailwind UI's checkboxes (https://tailwindui.com/components/application-ui/forms/check...) are fine, accessibility-wise. They can be tabbed to using the keyboard, they are proper <input type="checkbox"> elements in the DOM, they can be activated using the space key, they can be activated by clicking on their label.


It's kinda dangerous for the webpage to include the checkbox code to be copied as this. It's commercial product and from seeing tailwind public relations they are super stingy about it.


Looks like it needs javascript though.

Doesn't work for me on chrome mobile without JS.


Javascript is actually great for accessibility, it’s really hard to properly implement WAI-ARIA without it. Most people with screen readers will have js enabled too.


The main reason I can think of is trapping input inside a modal dialog when it's required.

Browsers recently rushed the dialog element and still have no easy solution for this.


Those are pictures. Not actual demos.


Tailwind is one of the vanishingly few css frameworks/css utility collections/css design systems that is really, really good about keeping semantic meaning of things and accessibilty intact, and whose examples show how to implement them correctly.

Almost everyone else is "screw this, we're going to use links as buttons and divs as lists".


Bootstrap has been pushing accessibility since v4, I believe.


What framework uses divs as lists without accessibility hints? I can't think of, or find, a major one that does.


You will not believe this, but it's called Semantic UI: https://semantic-ui.com/elements/list.html


Look at that.. My god. Point conceded.


This seems more like a gallery of art/starting point than a "use this as-is", so I'm sad to see this comment on the top of HN since as a show of what can be accomplished with checkboxes it's amazing.

We front-end devs would benefit from a lot more works of art like this, and then people trying to implement them into real systems would need to make them accessible. Similar to how we benefit greatly from Dribbble. If we don't allow for unrestricted just artistic bits like this, then creativity suffers.

Counterargument to myself: the click to copy though makes it seem like it's ready to use, and many newer devs would just use them straight away. It's on the hands of more senior devs to tell them that these snippets, similarly to many StackOverflow ones, need to be adapted to integrate in an actual app for things like accessibility, uniformity, etc.


I agree with the sentiment but there are problems besides accessibility here:

1. Crosses and squares being used instead of check marks.

2. Circles being used as containers instead of boxes.

3. Toggle switches being presented as checkboxes.

Maybe 5-10 of these are good inspiration for checkboxes.


I am so sad anyone can look at this amazing resource and with a straight face say that only 10% of it is valid as an inspiration. It's a magnificent source of inspiration! Sure some are not perfect, but that doesn't detract from the overall goal.


Naming element types by their style or form (box) rather than features in an implementation that encourages separating style leads to a more general problem.


They're fine.

In other news:

Nuclear power plant steering group improves reactor proposal! Committee stalls debating shade of yellow to be used for lines in parking lot.


Incidentally most of them _are_ focusable by the keyboard but just aren't tabbable.

I'm using a Chrome plugin Vimium - one of the shortcuts 'f' (documented as opening links) actually highlights all focusable elements. Using this feature shows most of the checkboxes are interactive.

Edit: I guess the reason for me pointing this out is hopefully there's an easy way to make these more accessible for keyboard users.


Good point. Indeed looks like only a few have. I'll try to add focus styles to all of them in the future. Thanks!


And if you use React, the react-aria library is excellent for this. See e.g. the useCheckbox hook: https://react-spectrum.adobe.com/react-aria/useCheckbox.html

Though if your "checkbox" is to take effect immediately, consider using a toggle button: https://react-spectrum.adobe.com/react-aria/useToggleButton....


Came to the comments to note the same. And to add that several has very poor color contrast.

They look great, but I would warn developers to use them as inspiration but not as-is.


How amazing it would be if we could style checkboxes using CSS and not have to replace them with images.


It was a fun exercise to go through each of the designs in this gallery and evaluate each one. It's easy to do that for individual form controls as design elements!

Lots of these made for a nice showcase but should never be used in a product ever - just horrendously unintuitive. For some, I wouldn't even know they were checkboxes if the page wasn't titled "here's a bunch of checkboxes". But a few of them were actually quite nice, accessible, and pleasantly useable.

Ultimately it seems that the checkboxes that were closest to the native OS checkboxes were the ones I enjoyed trying the most. I guess that's a predictable outcome. But it might be an indication that the further one strays from the OS defaults, the less good of a design it is? Maybe checkboxes are a solved problem, and there is only narrowly limited room for a brand to apply its personality on form controls before they become less usable for the sake of being "unique".

#33 was by far my favourite, for the record.


> #33 was by far my favourite, for the record.

That "pulse" on activation is pretty much Material Design. https://material-components.github.io/material-web/demos/che...


Some of these don't look like checkboxes at all, and wouldn't trigger any indication that they could be changed. For example, if I saw number 44 next to a line of text, I'd think "that must be something not available for some reason" rather than "I could click that to choose it". Same with 50 and 26 (that's a stop sign!) - they look like bullet points.

Some of the others are pretty nice though!


added to my list :) https://github.com/sw-yx/spark-joy/blob/master/README.md#any...

happy css scan customer here. just used it today to grab some annoying css.

feature request: convert the css to react style objects. i hate that i need to use react styles (just fix jsx! urgh.) but i had to constantly use https://staxmanade.com/CssToReact/ to convert it


Thanks swyx <3

Nice, yes, I plan to add "copy to react" feature soon. Will let you know when it's ready


Very difficult to resist going through and checking each and every one of them.


The pill boxes are awful. I never know if it means that it's on or off.


Pretty mixed feelings.

It's nice that there's all this "free" stuff that I can see and play with and just click to copy and drop into my own project without any thinking or worrying about buying UI kits…

… But I write novel CSS too. It's a very real part of my livelihood and this company is selling a product that can take my work without any attribution in the copied code. And then they seemingly use that work to market their product.

Important to remember that [even good] attribution is no substitute for an actual license to use somebody else's code. It's piracy. You wouldn't steal a policeman's helmet, etc.


I'd like to remind folks that switches and checkboxes mean two different things. Please do not use them interchangeably on the web.

Switches imply that changing the value has an immediate effect (i.e., the change is immediately saved). Checkboxes do not, and should have a corresponding Save button.

Switches were popularized by iOS, where they almost always have immediate effect. Checkboxes have been around much longer on the web, and have almost never had immediate effect (hell, it wasn't even possible until Web 2.0).


Thought I'd take this opportunity to thank you for your work. I came across your site searching for a box-shadow the other day, after spending too long attempting it myself


Thanks, merek. Happy it was helpful to you :D


Number 44 has issues internationally as it toggles between a tick and a cross.

I now live in a country which uses ticks to check a box, but I grew up in a country that uses crosses to check a box and had no idea what a tick was until I moved here.



The only clear and no margin for confusion is the one with "X" vs "check" inside the circle. If that "X" would be red and the check green that would add even more clarification. I hate UI's where I have to click everything first in order to understand what's what, I prefer intuitive design instead.


X is equivalent to a check mark for most people. I think it's mostly an American thing to see an X as meaning "not checked".


While these are all cool, the tool they're selling just openly is made for stealing styles from other pages? I mean I get that CSS isn't copyrighted (specifically), but it does just seem like its a tool made for stealing other peoples work?


I’m on mobile right now so can’t check the source code, but the transition duration of many (most?) of these are way too long, feels very janky. Some also seem to have a noticeable delay before the transitions even begin (Safari on iPadOS 16.1).


Assume JS is needed in order for the slide checkboxes to be slidable.


Funny you mention that, because hidden check boxes and radio inputs are often used creatively (in a kind of horrifying way) to store app state and avoid using JavaScript entirely, while still having complex animations. For instance, you can make a fully functional image gallery carousel with controls to navigate between each image with zero JavaScript like this, and this is just one of the simplest examples.


Why assume? You can copy-paste the code and see how it works.

Most pure CSS checkboxes make heavy use of pseudo-classes and pseudo-elements - but it is very possible to make these sliders without JS!


No JS, all made with pure CSS :D (you can copy the code to see how it works)


CSS transitions behind the scenes.


Tailwind UI is a commercial product, no? Whether the checkbox CSS meets the threshold for copyright or not, I'm not sure encouraging folks to copy its styles is a great idea.


Looking at some of the skeuomorphic designs, I can't help but feel that this design style went out of vogue way too soon.

It looks so...juicy.


It shows some signs of comeback. The problem with the last skeuomorphic design trend was that it wasn't "honest", for example leather elements didn't behave like leather and the illusion quickly fell apart making it tacky. With the current performance of the devices we can have much more convincing materials and object designs. Apple's blurry glass design on iOS and macOS is very nice for example, it blends the background very nicely and the way the colors bleed you can tell. that this is not simply a blur effect.


Windows 7's Aero effects were pretty honest, in my opinion.


No real-world application will sacrifice function for form. The web is an accessible platform, not a "beautiful" one.


I'm not sure we use the same web. "Accessible" or "function over form" are the exact opposite of how I'd describe it.


I think the green and red color is a must for all sliders.

It's very hard to tell if it's On or Off when it's a monochrome slider.


And green/red is not so great for the most common type of colour blindness: https://www.nei.nih.gov/learn-about-eye-health/eye-condition...


Color is nice but it should never be required to determine widget state. there should always be indicators showing on and off and what state the widget in in.

And... most of the sliders shown fail miserably. come on guys you are not helping my perception that design is a sick profession.


I would be interested in a multi-state looping widget, like "yet to start, ongoing, paused, finished"


Ironically I needed to enable JavaScript in order to view any checkbox. Terrible.


Would love to be able to size them with eg. CSS Variables. --width, --height etc.


#10 should be off by default like all the other ones.


Thanks for the heads up


How did it become normal in software to refer to describe your own work as beautiful?


The work here is just curation. The checkboxes were made by other people.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: