Building a dropdown or a modal sounds simple until you try to do it properly. Keyboard navigation, focus trapping, screen reader announcements, closing on Escape — accessibility is a long checklist. Headless UI, from the Tailwind CSS team, gives you fully accessible components with zero styling, so you can make them look however you want.
Here is a dropdown menu:
import { Menu } from '@headlessui/react';
function UserMenu() {
return (
<Menu>
<Menu.Button className="px-4 py-2 bg-blue-600 text-white rounded">
Account
</Menu.Button>
<Menu.Items className="absolute mt-2 w-48 bg-white shadow-lg rounded">
<Menu.Item>
{({ active }) => (
<a className={active ? 'bg-gray-100 block px-4 py-2' : 'block px-4 py-2'} href="/profile">
Profile
</a>
)}
</Menu.Item>
<Menu.Item>
{({ active }) => (
<a className={active ? 'bg-gray-100 block px-4 py-2' : 'block px-4 py-2'} href="/settings">
Settings
</a>
)}
</Menu.Item>
</Menu.Items>
</Menu>
);
}
You write the markup and the classes; Headless UI handles the behaviour. Arrow keys move between items, Enter selects, Escape closes, and focus returns to the button. The active render prop tells you which item is highlighted so you can style it.
Headless UI includes the components you reach for most: Menu, Dialog (modals), Disclosure (accordions), Listbox (custom selects), Popover, Switch, Tabs, and Radio Group. Each one follows the WAI-ARIA patterns, so screen readers understand them correctly.
The tradeoff is that you style everything yourself. If you want ready-made beautiful components, a library like MUI is faster. But if you have a custom design system — or you use Tailwind and want your components to match your design exactly — Headless UI gives you accessibility for free and styling freedom in return.
Headless UI is for React developers who care about accessibility but want full control over how their components look. Pair it with Tailwind CSS and you can build a polished, accessible interface without writing the tricky interaction logic yourself.
Top comments (0)