Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Topics

CSS pointer-events Property

Posted in CSS Tutorial
Updated on Oct 07, 2024
By Mari Selvan
👁️ 39 - Views
⏳ 4 mins
💬 1 Comment
CSS pointer-events Property

Photo Credit to CodeToFun

🙋 Introduction

The pointer-events property in CSS is used to control whether an element can be the target of pointer events, such as mouse clicks, touch events, or cursor hovers.

This property is particularly useful for creating interactive web elements and managing user interactions on your webpage.

💡 Syntax

The syntax for the pointer-events property is simple and can be applied to any HTML element.

Syntax
Copied
Copy To Clipboard
element {
  pointer-events: value;
}

Here, value can be one of the predefined keywords that determine the behavior of pointer events for the element.

🎛️ Default Value

The default value of the pointer-events property is auto, which means that the element can be the target of pointer events as usual.

🏠 Property Values

ValueDescription
autoThe element behaves as it would if the pointer-events property were not specified. It can be the target of pointer events.
noneThe element is never the target of pointer events. All pointer events will be ignored for this element.
visiblePaintedThe element can be the target of pointer events only when it is visible and painted. This is the default value for SVG content.
visibleFillThe element can be the target of pointer events when the fill is visible.
visibleStrokeThe element can be the target of pointer events when the stroke is visible.
visibleThe element can be the target of pointer events when it is visible (can apply to both fill and stroke for SVG).
paintedThe element can be the target of pointer events when it is painted (fill, stroke, or any other visible part).
fillThe element can be the target of pointer events when the fill is painted.
strokeThe element can be the target of pointer events when the stroke is painted.
allThe element can be the target of pointer events regardless of visibility or paint status.
inheritThe element inherits the pointer-events property from its parent.

📄 Example

In this example, we'll disable pointer events for a button.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS pointer-events Example</title>
  <style>
    button {
      pointer-events: none;
      background-color: grey;
      color: white;
      border: none;
      padding: 10px 20px;
      font-size: 16px;
    }
  </style>
</head>
<body>
  <h1>Button with Disabled Pointer Events</h1>
  <button>Click Me</button>
  <p>The button above cannot be clicked because pointer events are disabled.</p>
</body>
</html>

🖥️ Browser Compatibility

The pointer-events property is supported in all modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it is always a good practice to test your website across different browsers to ensure compatibility.

🎉 Conclusion

The pointer-events property is a versatile tool for managing user interactions with web elements.

By using this property, you can control whether an element responds to pointer events, which is useful for creating custom interactions and enhancing user experience. Experiment with different values to see how this property can improve the interactivity of your web projects.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy