Apply hover styles only when a device can hover

Ever hovered on a touchscreen? Me neither.

But your CSS might still assume that every user can hover.

The hover media feature lets you apply styles only when the primary input device can hover conveniently:

@media (hover: hover) {
	.card:hover {
		transform: translateY(-0.25rem);
	}
}

You can also target primary input devices that cannot hover:

@media (hover: none) {
	.tooltip-trigger {
		/* Keep the information available on tap or focus */
	}
}

This is useful for dropdowns, tooltips, hover transitions, and any interaction that would otherwise disappear on touchscreens.

Use any-hover when you care whether any connected input can hover, not just the primary one. A touchscreen laptop with a mouse is a common example.

Hover should remain an enhancement. Important actions and information still need to work with touch and keyboard input.

You Don’t Need JavaScript ebook mockup

I wrote a guide about building modern UI with HTML and CSS first. It covers practical patterns you can use before reaching for JavaScript.

Learn more

    No strings attached, unsubscribe anytime!

    Other short articles you might like

    Explore more articles on front-end development, covering HTML, CSS and JavaScript for building high-performance websites.