Loading video...

Video Failed to Load

Go Home

Created this fully "accessible" dropdown using pure Tailwind CSS 🤩 × No javascript × No custom styles Can you guess which CSS property is this?

169,711 views • 3 years ago •via X (Twitter)

78 Comments

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

The correct answer is :focus-within ✨ People who guessed it right → @Xewl @cometkim @czechhater @szympajka 👏 Check out the code here 👇

Colm Tuite's profile picture
Colm Tuite3 years ago

@tailwindcss It's not possible to build an accessible dropdown without JS. I recommend using Radix or React Aria.

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Yes, true. This is Keyboard accessible I meant.

Andrey Okonetchnikov's profile picture
Andrey Okonetchnikov3 years ago

@colmtuite @tailwindcss Tab isn’t the right key of making a select accessible with a keyboard. Please don’t ship this to production since it will confuse lots of people.

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@colmtuite @tailwindcss Yes, there are some limitations because this is a CSS only proof of concept.

Shruti Balasa's profile picture
Shruti Balasa3 years ago

@tailwindcss Checkbox hack? Using peer-* utility classes I guess

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Found a better way 😉

Mo Youssouf | Web Designer's profile picture
Mo Youssouf | Web Designer3 years ago

@shrutibalasa @tailwindcss Is it :focus?

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@shrutibalasa @tailwindcss You are close :) Check out the code here 👇

Shruti Balasa's profile picture
Shruti Balasa3 years ago

@MedMYA @tailwindcss Really nice!

Bhanu Teja P's profile picture
Bhanu Teja P3 years ago

@tailwindcss Probably <details> and <summary> Atleast that’s what I use for these type of things.

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Its possible, but closing by clicking outside will be nightmare :)

Amy Sans MS ✨— in my cat lady era's profile picture
Amy Sans MS ✨— in my cat lady era3 years ago

@tailwindcss How do you update the aria-expended without js ?

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Keyboard accessible 🙈

Mike's profile picture
Mike3 years ago

@tailwindcss Mind sharing the code? I'm interested what approach you used

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Sure

Essomouah's profile picture
Essomouah3 years ago

@tailwindcss Purposely not sharing the code ?

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Nope, Check out the code here 👇

Timothée Guignard's profile picture
Timothée Guignard3 years ago

@tailwindcss Not really related to your question but which software do you use to show keyboard keys while taking the video screenshot?

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Cleanshot.

Dananz's profile picture
Dananz3 years ago

@tailwindcss It's cool and all until you try to use it inside an overflow: hidden container

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss yeah, will be a problem then. This is a simple POC :)

Dananz's profile picture
Dananz3 years ago

@tailwindcss Looks amazing btw, great job!

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss thank you

𝗫𝗲𝘄𝗹 / Ken V. ☄️'s profile picture
𝗫𝗲𝘄𝗹 / Ken V. ☄️3 years ago

@tailwindcss • focus-visible + peer • focus-within on container + group I need aria-expanded support, which I do with Alpine; so sadly not sufficient.

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss This is keyboard accessible. Sadly no way to change aria-* attributes.

𝗫𝗲𝘄𝗹 / Ken V. ☄️'s profile picture
𝗫𝗲𝘄𝗹 / Ken V. ☄️3 years ago

@tailwindcss With styles alone, I guess not. For a11y I use eg. AlpineJS & then style according/along to the aria-expanded's value instead.

Trecia Kat 👩🏽‍💻's profile picture
Trecia Kat 👩🏽‍💻3 years ago

@tailwindcss Code 🙏 🤲

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Sure.

Trecia Kat 👩🏽‍💻's profile picture
Trecia Kat 👩🏽‍💻3 years ago

@tailwindcss Link to source 🙏

btter's profile picture
btter3 years ago

@tailwindcss how did you implement that ?

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@philipbr12 @tailwindcss Check out the code here 👇

btter's profile picture
btter3 years ago

@tailwindcss Thank you very much

Angel A. Núñez's profile picture
Angel A. Núñez3 years ago

@tailwindcss It looks amazing! 👏

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss thank you

kurky_tweets's profile picture
kurky_tweets3 years ago

@tailwindcss Code pls

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Check out the code here 👇

Danilo Gacevic's profile picture
Danilo Gacevic3 years ago

@tailwindcss Cool! Does it look the same on mobile browsers?

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Yes, tested on ios safari & chrome. animations not showing up on chrome though.

Jose Antonio Dominguez's profile picture
Jose Antonio Dominguez3 years ago

@tailwindcss Focus! :) I love css without js powers

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Almost there 👇

Anand Chowdhary's profile picture
Anand Chowdhary3 years ago

@tailwindcss Target?

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Check out the code here 👇

asraf_ai's profile picture
asraf_ai3 years ago

@tailwindcss wow!!!

Abdullahi Jimoh 's profile picture
Abdullahi Jimoh 3 years ago

@tailwindcss Checkbox

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Check out the code here 👇

Gleb Varganov's profile picture
Gleb Varganov3 years ago

@tailwindcss Looks nice! Good job!

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss 😇

Senith's profile picture
Senith3 years ago

@tailwindcss It's smooth like butter.

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Thank you

Oliver Franke's profile picture
Oliver Franke3 years ago

@tailwindcss Wow that’s awesome! Would you mind sharing the code?

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Check out the code here 👇

Alvaro Aquije's profile picture
Alvaro Aquije3 years ago

@tailwindcss That looks awesome, mind sharing the code?

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@alvaro_dotdev @tailwindcss Check out the code here 👇

Pingero's profile picture
Pingero3 years ago

@tailwindcss Smooth!

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Check out the code here 👇

Martin Lexelius's profile picture
Martin Lexelius3 years ago

@tailwindcss It's a nice little css hack using a button and a div (which should not have role menu/menuitem). Keyboard nav does not follow established patterns and the state of the button is not communicated. Why not just build a real disclosure? Don't call it accessible 🤷‍♂️

Markus Lutz 🥨☢️☯️'s profile picture
Markus Lutz 🥨☢️☯️3 years ago

@tailwindcss Is it possible to get the code? Have tried there for hours with js.

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Check out the code here 👇

Markus Lutz 🥨☢️☯️'s profile picture
Markus Lutz 🥨☢️☯️3 years ago

@tailwindcss many thanks. This is great 🥰

hyeseong.kim's profile picture
hyeseong.kim3 years ago

@tailwindcss :focus-within?

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss You are right 👏 Check out the code here 👇

Martin Lexelius's profile picture
Martin Lexelius3 years ago

@tailwindcss I hope it’s not the checkbox hack

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Nope :)

Basharath's profile picture
Basharath3 years ago

@tailwindcss Nice work, Surjith 👏

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Thank you

Lukas's profile picture
Lukas3 years ago

@tailwindcss Why not using custom CSS? Now there is a hard dependency on @tailwindcss

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Pretty much easy to do this in pure CSS as well. You can always copy paste the css to avoid tailwind as dependency.

Youenn's profile picture
Youenn3 years ago

@tailwindcss There is a way to close the dropdown after click on one off the button ? I need this but not for navigation :)

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss I guess you need js for that

creativenull's profile picture
creativenull3 years ago

@tailwindcss Looks like some simple css transitions :D

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@creativenullll @tailwindcss Check out the code here 👇

Marian Benčat's profile picture
Marian Benčat3 years ago

@tailwindcss Focus within.

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss You are right 👏 Check out the code here 👇

WinnersDaily's profile picture
WinnersDaily3 years ago

@tailwindcss Can we have the code?

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Check out the code here 👇

Mr. Ridlafalah's profile picture
Mr. Ridlafalah3 years ago

@tailwindcss amazing, really appreciate if you can show us the magic behind it 😁

Surjith S M ✪'s profile picture
Surjith S M ✪3 years ago

@tailwindcss Sure :)

Related Videos