<button class="btn">Click me</button>Tailwind applies styles to disabled elements using the [disabled] attribute selector syntax inside class names. Option B uses [disabled]:bg-gray-400 and [disabled]:pointer-events-none, which correctly target disabled buttons.
<button disabled class="bg-blue-600 text-white px-4 py-2 rounded [disabled]:bg-gray-400 [disabled]:cursor-not-allowed">Submit</button>
The [disabled]:bg-gray-400 changes the background to gray only when disabled. The [disabled]:cursor-not-allowed changes the cursor to not-allowed always when disabled, not just on hover.
pointer-events-none to a disabled button in Tailwind CSS?pointer-events-none disables mouse interactions like clicks and hover effects, ensuring the disabled button cannot be clicked or hovered.
Option A uses disabled:opacity-50 which is invalid because Tailwind requires attribute selectors to be wrapped in square brackets like [disabled].
Using aria-disabled="true" communicates the disabled state to assistive technologies. Styling with [aria-disabled='true'] ensures consistent visual feedback. This approach supports accessibility better than just the disabled attribute.