The pointer-events Property in CSS

CSS | pointer-events Property: Here, we are going to learn about the pointer-events property with examples in CSS.
Submitted by Anjali Singh, on December 17, 2019

CSS | pointer-events Property

Pointers are the mouse cursors on the web page that are used to navigate and click an option.

Yes, pointers can also be formatted specifically. If you plan on carving every detail of your web page then you must not forget about pointers. To deal with pointers we use Pointer-events property in CSS.

The pointer-events property in CSS allows controlling how elements are supposed to react to mouse/touch events. It also specifies whether or not the cursor is visible.

Those are quite a load of features. Let us understand them with the following example,

Syntax:

Element {
    pointer-event: none|auto;
}

pointer-events Property values

1) auto

If we add auto as a prefix to something, we assume that the functionality would be automatic, which is quite true most of the time. The case is the same here, the element reacts to pointer events such as when we hover over an element. Thereby making the auto a default property of pointers-event.

Well, why stop at the definition? Go ahead and try the below-mentioned example,

Syntax:

Element {
    pointer-event: auto;
}

Example:

<!DOCTYPE html>

<html>

<head>
    <style>
        div {
            pointer-events: auto;
        }
    </style>
</head>

<body>
    <h2>Pointer-events in CSS</h2>
    <div>Go to <a href="https://www.includehelp.com/">IncludeHelp</a></div>
</body>

</html>

Output

CSS | the pointer-event property | Example 1

In the above example, hover over and click the link "IncludeHelp" to see the effect in the above example,

2) none

"none" is used when we do not want any task to be performed by the cursor. Therefore, this property prevents all click, state and cursor options on the specified element.

Let us try to understand this property much better with the help of an example,

Syntax:

Element {
    pointer-events: none;
}

Example:

<!DOCTYPE html>

<html>

<head>
    <style>
        div {
            pointer-events: none;
        }
    </style>
</head>

<body>
    <h2>Pointer-events in CSS</h2>
    <div>Go to <a href="https://www.includehelp.com/">IncludeHelp</a></div>
</body>

</html>

Output

CSS | the pointer-event property | Example 2

In the above example, if you hover over the "IncludeHelp" link you won't be able to click and go to the next page.

Tip: none should be used very wisely. As most of the time, we do want our cursor to perform some tasks but if you apply this property nothing would happen.

CSS Tutorial & Examples »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.