EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

CSS Pointer Events

By Mahantesh NagathanMahantesh Nagathan

Home » Software Development » Software Development Tutorials » CSS Tutorial » CSS Pointer Events

CSS Pointer Events

Introduction to CSS Pointer Events

The CSS pointer-events property enables control of how HTML elements react to mouse or touch events including CSS hover or active states, JavaScript clicks or tap events, and whether the cursor is visible or not. The CSS pointer-events property sets out under what situations (if there is any) a specified graphic element may become the object of pointer events. The CSS pointer-events are DOM events that a pointing device is fired to. They are intended to create a single model of the DOM event to handle pointing input devices like a mouse.

The property of pointer-events is even more JavaScript-like, to prevent:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

  • Click on actions to do something
  • Default cursor pointer to show
  • CSS hover and cause active state
  • Click on JavaScript to fire events

Syntax

The syntax for CSS pointer-events can be written as shown below:

pointer-events: auto|none;

  • auto: This parameter can be used to specify that the element has to react to the pointer-events.
  • none: This parameter can be used to define that element may not react to pointing events.

For instance,

Consider the below code:

<div class="myclass"> click here <a href="https://www.google.com/html"> Google </a> </div>

For this class, we will give CSS with pointer event property as shown below:

div.myclass {
pointer-events: auto;
}

When you hover or click on the above link, the element will react to the pointer-events.

How does CSS Pointer Events property work?

Having a single pointer event model could facilitate website and application development, and can also provide a great user experience irrespective of user’s hardware. Even then, in circumstances where device-specific handling is required, pointer-events identify a pointer type property to inspect the type of device that generated the event. Comparable to mouse events such as mouse down / pointer down, mouse move/pointer move, etc are the events required to handle generic pointer input. Thus, the types of pointer events are purposely equivalent to the types of mouse events.

Popular Course in this category
CSS Training (9 Courses, 9+ Projects)9 Online Courses | 9 Hands-on Projects | 61+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,416 ratings)
Course Price

View Course

Related Courses
Bootstrap Training (2 Courses, 6+ Projects)jQuery Training (8 Courses, 5 Projects)

Examples to Implement CSS Pointer Events

Below are the examples mentioned:

Example #1

Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> CSS pointer-events Example </title>
<style>
.mytext {
pointer-events: auto;
}
</style>
</head>
<body>
<h2> Pointer Events - Auto </h2>
<br>
<div class = "mytext">
<a href="https://www.educba.com/"> EDUCBA (Corporate Bridge Consultancy Pvt Ltd) </a> is a leading global provider of skill based education addressing the needs of 500,000+ members across 40+ Countries. Our unique step-by-step, online learning model along with amazing 2500+ courses prepared by top-notch professionals from the Industry help participants achieve their goals successfully.
</div>
</body>
</html>

Output – Open the file in a browser and it will produce the following result:

CSS Pointer Events - 1

Explanation: As shown in the above example, we have set the pointer property to auto which determines that when the user hover on the link, the element will react to the pointer event. In other words, we can see the mouse pointer when we hover over the link, as we have set the property for pointer events.

Example #2

Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> CSS pointer-events Example </title>
<style>
.mytext {
pointer-events: none;
}
</style>
</head>
<body>
<h2> Pointer Events - None </h2>
<br>
<div class = "mytext">
<a href="https://www.educba.com/"> EDUCBA (Corporate Bridge Consultancy Pvt Ltd) </a> is a leading global provider of skill based education addressing the needs of 500,000+ members across 40+ Countries. Our unique step-by-step, online learning model along with amazing 2500+ courses prepared by top-notch professionals from the Industry help participants achieve their goals successfully.
</div>
</body>
</html>

Output:

CSS Pointer Events - 2

Explanation: As shown in the above example, we have set the pointer property to none which determines that when the user hovers on the link, the element will not react to pointer event. In other words, we cannot see the mouse pointer when we hover over the link, as we have set the none property for pointer events.

Example #3

Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> CSS pointer-events Example </title>
<style>
.one {
fill: grey;
}
.two {
fill: cyan;
}
.three {
fill: orange;
pointer-events: none;
}
.pntrevnt:hover {
stroke: red;
stroke-width: 3;
}
</style>
</head>
<body>
<h2> Pointer Events - SVG </h2>
<br>
<svg width="250" height="250">
<g transform="translate(30, 30)">
<path class="one pntrevnt" d="M 0 0 L 100 0 L 100 100 L 0 100 z" />
<path class="two pntrevnt" d="M 50 50 l 100 0 l 0 100 l -100 0 z" />
<path class="three pntrevnt" d="M 100 100 l 100 0 l 0 100 l -100 0 z" />
</g>
</svg>
</body>
</html>

Output:

CSS Pointer Events - 3

Explanation: In the above example, we have used the SVG element and used stroke value which specifies the target of pointer event when the user moves the mouse pointer over the perimeter of the element. The fill value specifies the target of pointer event when the user moves the mouse pointer over the element’s interior.

Conclusion

So far, we have used CSS pointer event property along with examples. Adopting pointer-events to prevent an element from becoming the target of pointer events does not imply that it will not trigger pointer event listeners. The CSS pointer-events are very effective when set to none to disable the target click and allow elements underneath to click.

Recommended Articles

This is a guide to CSS Pointer Events. Here we discuss an introduction to CSS Pointer Events, syntax, how does it work with programming examples. You can also go through our other related articles to learn more –

  1. CSS Flexbox Properties
  2. CSS Table Cell Padding
  3. CSS Text Underline
  4. Text Decoration CSS

CSS Training (9 Courses, 9+ Projects)

9 Online Courses

9 Hands-on Projects

61+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
CSS Tutorial
  • CSS
    • Introduction To CSS
    • What is CSS?
    • Uses Of CSS
    • Advantages of CSS
    • Career In CSS
    • CSS Commands
    • Is Css Case Sensitive
    • CSS object-fit
    • Types of CSS Selectors
    • CSS Radio Button
    • CSS Attribute Selector
    • CSS first child of class
    • CSS Selector nth Child
    • CSS Parent Selector
    • CSS Child Selector
    • CSS Not Selector
    • CSS Descendant Selector
    • CSS Inline Style
    • Checkbox CSS
    • CSS Appearance
    • CSS Font Properties
    • CSS font-variant
    • CSS Pagination
    • CSS Table Styling
    • CSS Table Cell Padding
    • CSS Padding Color
    • CSS Text Formatting
    • CSS for Text-Shadow
    • CSS text-stroke
    • CSS text-indent
    • CSS Rotate Text
    • CSS Text Color
    • CSS Center Div
    • CSS Arrow
    • CSS Arrow Down
    • CSS offset
    • CSS Cursor
    • CSS Layout
    • CSS Grid Layout
    • Button in CSS
    • CSS Button Border
    • text-align in CSS
    • CSS Horizontal Align
    • CSS Position
    • CSS Box Sizing
    • CSS box-shadow
    • CSS Text Underline
    • CSS Text Outline
    • CSS Blinking Text
    • Text Decoration CSS
    • CSS Vertical Align
    • CSS Word Wrap
    • CSS Padding
    • CSS Font Color
    • CSS Color Generator
    • CSS Margin Right
    • CSS Margin Color
    • CSS Color Codes
    • CSS Color Transparent
    • CSS Color Chart
    • CSS Link Color
    • CSS z-index
    • CSS Curved Border
    • CSS Border Left
    • CSS left
    • CSS Gradient Generator
    • Radial Gradient in CSS
    • CSS Shape Generator
    • CSS Triangle Generator
    • CSS background-color
    • CSS Background Image
    • CSS background-clip
    • CSS background-blend-mode
    • CSS Drop Shadow
    • CSS line height
    • CSS line break
    • Sticky Footer CSS
    • CSS Header Design
    • CSS Border Style
    • CSS Border Generator
    • Sticky Sidebar CSS
    • CSS Transparent Border
    • CSS Border Radius
    • CSS translate
    • CSS transform
    • CSS 3D Transforms
    • CSS Text Transform
    • CSS Transition Effects
    • CSS Transition Property
    • CSS Animation Transition
    • Negative Margin CSS
    • CSS Navigation Bar
    • CSS Overflow
    • CSS overflow-wrap
    • CSS Lists
    • CSS list-style
    • CSS Order
    • CSS Box Model
    • CSS Inner Border
    • CSS Icon
    • Menu Icon CSS
    • CSS Multiple Borders
    • Opacity in CSS
    • CSS Float Right
    • CSS Clear Float
    • CSS clip
    • CSS disabled
    • CSS Border Padding
    • Border Images in CSS
    • CSS Visibility
    • CSS Validator
    • CSS Clearfix
    • CSS Counter
    • CSS Letter Spacing
    • CSS root
    • CSS zoom
    • CSS calc()
    • CSS.supports()
    • CSS Loader
    • Media Query CSS
    • CSS @keyframes
    • CSS @bottom
    • CSS page-break-after Property
    • CSS page-break
    • CSS Position Fixed
    • CSS skew()
    • CSS Row
    • CSS Masking
    • CSS Scrollbar
    • CSS Overlay
    • CSS Important
    • CSS Cursor Hand
    • CSS Inherit
    • CSS Position Relative
    • CSS Compressor
    • CSS tricks
    • CSS Outline Property
    • CSS Flexbox Properties
    • CSS flex-direction
    • CSS content property
    • CSS Typography
    • CSS Formatter
    • CSS nowrap
    • CSS Column
    • GridView CSS
    • CSS Viewport
    • CSS Minify
    • CSS Combinators
    • CSS in React
    • CSS Matrix 
    • CSS Pseudo Elements
    • CSS Pseudo Classes
    • CSS Pointer Events
    • CSS Resize
    • CSS Inheritance
    • CSS Interview Questions
    • Cheat Sheet CSS
  • CSS3
    • What is CSS3?
    • CSS3 Interview Questions
    • Cheat sheet CSS3
  • sass
    • How to Install SASS
    • SASS Interview Questions
    • What is Sass
    • SASS Comments
    • Sass Variables
    • SASS Import
    • SASS if else
    • SASS Nesting
    • SASS @each
    • SASS @at-root
    • SASS @extend
    • SASS @media
    • SASS @for
    • SASS Map
    • SASS Selectors
    • SASS Color Functions
    • SASS Mixins

Related Courses

CSS Training Course

Bootstrap Training Course

JQuery Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - CSS Training (9 Courses, 9+ Projects) Learn More