← Back to HTML & CSS, page 10

html-css-0183 · Easy fresher

What do cursor, pointer-events and user-select do, and what are their limits for accessibility?

cursor changes the pointer shape, pointer-events: none lets clicks pass through an element, and user-select: none prevents text selection. None of them change keyboard or screen reader behaviour, so use the disabled attribute or inert to switch off a control, and avoid blocking selection of real content.

Full answer

These three properties change how the mouse interacts with an element.

  • cursor changes the mouse pointer shape: pointer (a hand) for clickable things, not-allowed for disabled controls, text over text, grab for draggable items. It is only a visual hint for mouse users. It does not make an element clickable.
  • pointer-events: none makes an element ignore the mouse, so clicks, hovers and taps pass through to the element underneath. This helps with decorative overlays, such as a gradient on top of a scrolling list, and with children inside a button. pointer-events: auto brings it back, and it is inherited, so a child can turn it on again.
  • user-select: none stops the user from selecting text by mouse. It suits buttons and drag handles, where selection is a nuisance. Do not use it on content, because people copy text, and it hurts accessibility tools and users who select text to read it.

Limits and traps:

  • pointer-events: none does not remove an element from the keyboard. A button with it can still be focused with Tab and activated with Enter. It also does not hide it from screen readers. To disable a control for everyone, use the disabled attribute (or inert), and not only CSS.
  • A disabled button does not fire click events, and some browsers also stop hover events on it, which can break tooltips.
  • A custom cursor: pointer on a non-interactive element suggests a click that does nothing. Use it only for real controls.
  • On touch screens there is no cursor, so never depend on it to show what is clickable. Make the shape and the text clear.

The overlay covers the button but ignores the mouse, so the button underneath still receives clicks. The user-select: none text cannot be selected by dragging. The button shows a hand cursor when it is enabled. The last button has pointer-events: none, so the mouse ignores it, but Tab still focuses it and Enter still activates it.

Use disabled, not CSS alone, to switch a control off.

html
<style>
  #btn { cursor: pointer; }
  #btn:disabled { cursor: not-allowed; }
  .wrap { position: relative; width: 120px; height: 40px; }
  .overlay { position: absolute; inset: 0; background: rgba(255, 255, 255, 0.5); pointer-events: none; }
  .nosel { user-select: none; }
  #kb { pointer-events: none; }
</style>
<div class="wrap"><button id="btn" type="button">Click</button><div class="overlay" id="ov"></div></div>
<span class="nosel" id="ns">Not selectable</span>
<button id="kb" type="button">Mouse ignores me</button>
<script>
  window.clicks = 0; window.kclicks = 0;
  btn.addEventListener("click", () => { clicks++; });
  kb.addEventListener("click", () => { kclicks++; });
</script>

Checked with a mouse click and real key presses in Chrome. Touch was not tested. Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.

Key points

  • cursor is a visual hint only.
  • pointer-events: none lets clicks pass through.
  • user-select: none blocks text selection.
  • pointer-events: none does not stop keyboard activation.
  • Use disabled or inert to disable controls.

Common mistakes

  • Using pointer-events: none to disable a control and leaving it focusable by keyboard.
  • Applying user-select: none to article text.
  • Using cursor: pointer on things that are not clickable.

Follow-ups

  • How can a child element receive clicks inside a parent with pointer-events: none?
  • How do you disable a button properly?

Tips

  • Say what each property does and what it does not do.
  • State that pointer-events: none is not a way to disable a control.