Skip to content
Tutorials Center
My learning

Topics

Lesson 82 of 139 ยท Responsive Design

Hover, Pointer and Touch: Designing for Every Input

Design for mouse, finger and keyboard. Combine hover and pointer media queries with touch-action, cursor, user-select and pointer-events.

A responsive page is not only about screen width. People reach your page with a mouse, a trackpad, a finger, a stylus, a keyboard, a game controller or a screen reader. A hover menu that delights a desktop user can be impossible to open on a phone. A tiny close button that a mouse clicks easily is a frustrating target for a thumb.

CSS gives you two groups of tools for this. Interaction media features (hover, pointer, and their any- versions) let you ask what kind of input the device has. Interaction properties (touch-action, cursor, user-select, pointer-events) change how elements react to input. This lesson covers both, and ties them into a few practical patterns. It builds on Media Queries, which introduced the syntax.

Asking what the input can do

Four media features describe the person's pointing devices:

Feature Values Meaning
hover hover, none Can the primary input hover over elements?
pointer fine, coarse, none Accuracy of the primary input
any-hover hover, none Can any available input hover?
any-pointer fine, coarse, none Accuracy of the best available input

A phone is typically hover: none and pointer: coarse. A laptop with a trackpad is hover: hover and pointer: fine. A convertible laptop with a touchscreen has a fine primary pointer, but any-pointer: coarse is also true, because a finger is available too.

The primary input is the device's main way of interacting, as the browser decides it. Use pointer and hover when you want to match the main input, and any-pointer and any-hover when you want to avoid excluding anyone. A rule of thumb:

  • Enhance with hover: hover. Put hover-only decoration inside @media (hover: hover) so it never traps touch users in a sticky hover state.
  • Make controls friendlier with any-pointer: coarse. If a finger is possible anywhere, give controls generous size.
What does this device report?

On a desktop you will see fine and hover, on a phone coarse and none. Open the browser's device emulation in DevTools to see the table change.

Hover effects that do not break on touch

On touchscreens, "hover" is simulated: the first tap triggers :hover and it often sticks until the user taps elsewhere. A card that reveals its buttons only on hover is therefore unusable, and a dropdown can seem to open at random.

The pattern is progressive enhancement. Show content by default, and only hide it behind hover where hover truly exists:

CSS
.card .actions { opacity: 1; }                 /* visible by default */

@media (hover: hover) and (pointer: fine) {
  .card .actions { opacity: 0; transition: opacity 0.2s; }
  .card:hover .actions,
  .card:focus-within .actions { opacity: 1; }  /* keyboard users too */
}

Notice :focus-within. Anything revealed on hover must also be reachable by keyboard, and :focus-within is the companion that makes it so (see Pseudo-classes).

Hover actions with a safe fallback

Touch target size

A fingertip covers about 7 to 10 mm. Interactive controls should be at least about 44 by 44 CSS pixels (WCAG's enhanced target size is 44, and the minimum is 24), with space between neighbours. Use the pointer query to enlarge controls only when needed:

CSS
button, .icon-button { min-height: 2rem; min-width: 2rem; }

@media (pointer: coarse) {
  button, .icon-button { min-height: 2.75rem; min-width: 2.75rem; }
}

An invisible extension is another option: a pseudo-element that grows the clickable area without changing the visible size, using ::after { content: ""; position: absolute; inset: -0.5rem; } (the button needs position: relative).

cursor: telling mouse users what to expect

The cursor property changes the mouse pointer over an element. It is a hint, not behavior, but good cursors make interfaces feel precise.

Value Use for
pointer Clickable things that are not links, such as custom buttons or cards
text Editable or selectable text
grab / grabbing Draggable items (switch to grabbing while dragging)
not-allowed Disabled controls
wait / progress Busy states
zoom-in / zoom-out Image lightboxes
col-resize, row-resize Resize handles
default, help, crosshair, move Context-specific cases

Real <button> and <a href> elements do not need cursor: pointer for the browser to behave, and many designs deliberately leave buttons with the arrow cursor. Add it where you build clickable things from other elements, but treat that as a warning sign: a real button or link is almost always the better element (Buttons). Cursors do nothing on touch screens, so never rely on them to explain something.

user-select: controlling text selection

user-select decides whether text can be highlighted:

  • none stops selection. Use it on UI chrome that people click repeatedly, such as tabs, toolbar buttons and drag handles, so a double-click does not highlight the label.
  • all selects the whole element with one click. It is handy for things people copy: a code, a token, a share URL.
  • text forces selection on, auto is the default.

Never put user-select: none on article text or anything people may need to copy, quote or have read by assistive tools. It annoys users and does not stop copying, since content can still be reached through developer tools or the page source.

touch-action: who handles the gesture?

When a finger moves across the screen, the browser decides whether it is a scroll, a pinch zoom or a double-tap zoom. touch-action lets an element say which of those built-in behaviors may apply to touches that start on it:

Value Meaning
auto Browser handles everything (default)
none The browser does nothing; your JavaScript receives all the pointer events
pan-x, pan-y Only horizontal or vertical panning is browser-handled
pinch-zoom Pinch zoom stays on
manipulation Panning and pinch zoom, but no double-tap zoom

Two everyday uses:

  • Drawing surfaces, sliders, maps and games: touch-action: none on the canvas or draggable element, so dragging does not scroll the page, and your pointermove handlers work. Without it, the browser takes over the gesture and fires pointercancel.
  • Buttons and controls: touch-action: manipulation removes the delay and accidental zoom on rapid taps, without disabling normal scrolling or pinch zoom.

Be sparing with none. If an element covers most of the screen, users cannot scroll past it.

Draw with a finger or mouse

Pointer events unify mouse, touch and pen into one set of events, and event.pointerType tells you which it was. On a touchscreen, remove the touch-action: none line and try again: the page starts scrolling instead of drawing.

pointer-events: letting clicks pass through

pointer-events: none makes an element invisible to the pointer: clicks, hovers and touches go to whatever is behind it. It is useful for:

  • Decorative overlays, gradient fades or glow effects that sit on top of buttons.
  • Disabling a whole region while something loads (.loading { pointer-events: none; opacity: 0.6; }).
  • Layered layouts where a container is transparent but its children should still respond: set none on the container and auto on the children.
CSS
.fade-edge {
  position: absolute; inset: 0 0 auto auto;
  background: linear-gradient(to right, transparent, white);
  pointer-events: none;      /* clicks reach the carousel underneath */
}

pointer-events: none does not disable keyboard access: a link or button can still be focused with Tab and activated with Enter. For truly disabled controls, use the real disabled attribute (or inert on a whole region), not just CSS.

Putting it together

A solid interaction checklist for any component:

  1. Is everything reachable by keyboard, with a visible :focus-visible style?
  2. Does hover only add polish, never hide the only way to do something?
  3. Are targets at least about 44 px with pointer: coarse?
  4. Do custom gestures set touch-action appropriately?
  5. Are decorative overlays pointer-events: none?
  6. Is text you want copied left selectable?

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. A laptop has a trackpad and a touchscreen. Which media query is true because of the touchscreen?

    pointer describes only the primary input (the trackpad, which is fine). any-pointer asks about any available input, and a finger is coarse.
  2. 2. Why wrap hover-reveal styles in @media (hover: hover)?

    Content hidden by default and shown on hover becomes unreachable on touch. Scoping the hiding to hover-capable devices keeps it visible elsewhere.
  3. 3. What does touch-action none on a canvas do?

    With touch-action none the browser does not claim the gesture. Your pointermove handlers receive the movement.
  4. 4. What is true about pointer-events none?

    pointer-events none only affects pointing devices. A focusable control can still be reached with the keyboard, so use the disabled attribute or inert to disable it properly.
  5. 5. When is user-select none appropriate?

    It prevents accidental highlighting on controls. Applying it to content hurts usability and does not really prevent copying.

Summary

  • Use hover/pointer for the primary input and any-hover/any-pointer for everything available; a phone is typically hover: none and pointer: coarse.
  • Put hover-only effects inside @media (hover: hover), pair them with :focus-within, and enlarge targets when pointer: coarse.
  • cursor hints at behavior for mouse users, user-select stops accidental highlighting on UI chrome, and neither replaces good semantics.
  • touch-action decides whether the browser or your code handles a gesture; none for drawing surfaces, manipulation for buttons.
  • pointer-events: none lets clicks pass through overlays but does not disable keyboard access.

Next lesson: Mobile-First CSS, where you start from the small screen and add enhancements as space allows.