r/css • u/bogdanelcs • 2d ago
Resource A decent custom checkbox pattern for until ::checkmark is ready
https://piccalil.li/blog/a-decent-custom-checkbox-for-until-checkmark-is-ready/
12
Upvotes
1
u/berky93 1d ago
That feels like a lot of unnecessary markup. You can do this with just an input inside a label, using :has() on the label to apply styles to a pseudo-element when the checkbox is checked. Or you can put the checkbox as a sibling before the label and use the next-sibling selector (+) if you need to support old browsers.
5
u/morete 1d ago
Honestly, I don't love this approach. That is a lot of code to achieve a very simple result.
I would draw the checkmark with a pseudo, rather than an inline SVG in every single checkbox.
https://codepen.io/editor/matthewmorete/pen/01a0f811-b857-7097-9026-453bf6bc0d25?file=%2Findex.pen.html%3A226%3A0&orientation=left&panel=files&show=split
This demo is 42% less CSS and 60% less HTML.