Entry 02
Hover styles only where hover exists
Use it on every :hover rule, so a tap on a touch screen does not leave the hover state stuck.
Code
@media (hover: hover) and (pointer: fine) {
.button:hover { background: var(--primary-hover); }
}Why it works, the rules and the credits
Why it works
- Touch browsers apply
:hoveron tap and keep it until the next tap elsewhere.hover: hoverasks whether the primary input can hover. pointer: fineasks whether it is precise, like a mouse. It rules out styluses and the Android devices that claim hover support.
Rules
- Tailwind v4's
hover:variant wraps itself in(hover: hover)only. Write the full query by hand everywhere else. - Touch users still need feedback on press. Give it with
:active, which works for every input.
Support
- Chrome
- 38
- Firefox
- 64
- Safari
- 9
Credits
Borrowed from: Emil Kowalski, mobile-native skill and emil-design-eng skill · Rauno Freiberg, Web Interface Guidelines