pointer-events

pointer-events CSS attributes specify when (if any) a specific graphic element can become a mouse event target (en-US)

css
 /* Keyword values */
 pointer-events : auto ;
 pointer-events : none ;
 pointer-events : visiblePainted ;  /* SVG only */
 pointer-events : visibleFill ;  /* SVG only */
 pointer-events : visibleStroke ;  /* SVG only */
 pointer-events : visible ;  /* SVG only */
 pointer-events : painted ;  /* SVG only */
 pointer-events : fill ;  /* SVG only */
 pointer-events : stroke ;  /* SVG only */
 pointer-events : all ;  /* SVG only */

 /* Global values */
 pointer-events : inherit ;
 pointer-events : initial ;
 pointer-events : unset ;

When this property is not specified, visiblePainted The same characteristics of values apply to SVG (Scalable Vector Graphics) content.

In addition to indicating that the element is not the target of a mouse event, the value none Indicates that the mouse event "penetrates" the element and specifies anything "below" the element.

Initial value auto
Applicable elements all elements
Whether it is an inherited attribute yes
Calculated value as specified
Animation type discrete

grammar

pointer-events Property is specified as a keyword selected from the list of values below.

value

auto

And pointer-events The performance effect is the same when the attribute is not specified. For SVG content, this value is the same as visiblePainted Same effect

none

Element will never become a mouse event target (en-US) However, when the pointer-events Property, the mouse event can point to a descendant element. In this case, the mouse event will trigger the event listener of the parent element during the capture or bubbling phase.

visiblePainted

Only applicable to SVG. An element becomes the target of a mouse event only if:

  • visibility The attribute value is visible , and the mouse pointer is inside the element, and fill Property specifies none Value other than
  • visibility The attribute value is visible , the mouse pointer is on the element boundary, and stroke Property specifies none Value other than
visibleFill

Only applicable to SVG. Only in elements visibility The attribute value is visible , and the mouse pointer is inside the element, the element will become the target of the mouse event, fill Property does not affect event handling.

visibleStroke

Only applicable to SVG. Only in elements visibility The attribute value is visible , and the mouse pointer is at the element boundary, the element will become the target of the mouse event, stroke Property does not affect event handling.

visible

Only applicable to SVG. Only in elements visibility The attribute value is visible , and the mouse pointer is inside or at the boundary of the element, the element will become the target of the mouse event, fill and stroke Property does not affect event handling.

painted

Only applicable to SVG. An element becomes the target of a mouse event only if:

  • The mouse pointer is inside the element, and fill Property specifies none Value other than
  • The mouse pointer is on the element boundary, and stroke Property specifies none Value other than

visibility Property does not affect event handling.

fill

Only applicable to SVG. Only when the mouse pointer is inside the element will the element become the target of the mouse event, fill and visibility Property does not affect event handling.

stroke

Only applicable to SVG. Only when the mouse pointer is on the element boundary will the element become the target of the mouse event, stroke and visibility Property does not affect event handling.

all

Only applicable to SVG. Only when the mouse pointer is inside or at the boundary of the element will the element become the target of the mouse event, fill stroke and visibility Property does not affect event handling.

Example

Example 1

css
 /* Example 1: Makes all the img non-reactive to any mouse events such as dragging, hovering, clicking etc */
 img  {
   pointer-events : none ;
 }

Example 2

Click the link http://example.com Will not jump

html
 < ul >
   < li > < a  href = " https://developer.mozilla.org/ " > MDN </ a > </ li >
   < li > < a  href = " http://example.com " > example.com </ a > </ li >
 </ ul >
css
 a[href=" http://example.com "]
 {
   pointer-events : none ;
 }

Tips

use pointer-events To prevent an element from becoming a mouse event target does not necessarily mean that the event listener on the element will never be triggered. If element descendants explicitly specify pointer-events Property and allow it to be the target of mouse events, then any event pointing to this element will pass through the parent element in the event propagation process and trigger the event listener on it in an appropriate way. Of course, mouse activity on the parent element but not on the descendant element will not be captured by the parent element and descendant element (mouse activity will pass through the parent element and point to the element below it).

We want to provide more sophisticated control over HTML (not just auto and none )To control which part of the element will capture mouse events when. If you have a unique idea, please add it to Wiki page The Use Cases section of the pointer-events

This attribute can also be used to increase the frame rate when scrolling. Indeed, when the mouse hovers over some elements during scrolling, it triggers the hover effect on them. However, these effects are usually not noticed by users, and most of them lead to problems with scrolling. yes body Element application pointer-events:none , including disabled hover To improve scrolling performance.

standard

Specification
CSS Basic User Interface Module Level 4
# pointer-events-control
Scalable Vector Graphics (SVG) 2
# PointerEventsProperty

Its extension to HTML elements, though present in early drafts of CSS Basic User Interface Module Level 3, has been pushed to its level 4 .

Browser compatibility

BCD tables only load in the browser

See