radio buttons to filter items with pure html/css & accessibility
I found this tutorial on how to filter cards using radio buttons and css. No JS needed. My question is, from an accessibility standpoint, is it a bad idea to use radio buttons in this manner? They're not being used for a form so I have a feeling it's not good practice. I know I can achieve the same result with JavaScript, but just wondering if it's okay to do with just html/css.
https://www.youtube.com/watch?v=q5Sax0oeun4
h3webdevtuts
YouTube
Filter Cards Pure Css
Udemy Courses:
- 9 React Projects on Udemy - https://bit.ly/2D83M8c
- 9 React Projects on Gumroad - https://h3webdevtuts.gumroad.com/l/oOgYi
Social Media:
- Web Dev Discord - https://discord.gg/sHtWt6w
- Github - https://github.com/h3h394
- Twitter - https://twitter.com/h3webdeveloper
- Instagram - https://www.instagram.com/h3webdevtuts/
2 Replies
Hmm, that's a good question.
Radio buttons aren't a bad approach from an a11y pov here to be honest.
Let's say it wasn't colors, but it was tech stacks for projects projects, where you could sort by the tech you used.
The radio button would announce which ones is selected, I think you'd want something before it to say what the choices are for of course, but it would probably be okay.
I did something similiar with
:has()
awhile back for picking a color scheme, and has my radios set up like this:
The form doesn't actually have to submit anything here...
codepen is here https://codepen.io/kevinpowell/pen/MWXybWJ?editors=1000
If I was going to put this into production, I'd probably do a quick screen reader test, and probably try to get outside input (which you are doing 😄 ) but my first impressions are it would be okay?
You might even be able to fancy it up with some view transitions 😄Thank you, i appreciate you taking the time to answer the question. This was very helpful! I'll definitely get outside feedback on this one.