CSS @media any-pointer Property

You are Here:

CSS @media any-pointer

CSS @media any-pointer can be used to tests whether the user has any pointing device (such as a mouse), and if so, how accurate it is.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> @media (any-pointer: none){ h1{ color: black; } } @media (any-pointer: coarse){ h1{ color: blue; } } @media (any-pointer: fine){ h1{ color: green; } } </style> </head> <body> <h1>CSS @media any-pointer</h1> </body> </html>

Syntax

Using CSS

@media (any-pointer: fine) { element{ color: red; } }

Using Javascript

elementelegram.dogdia = "(any-pointer: fine)";

Media Query Value

The following table provides the list of media query value for any-pointer.

ValueExplanation
noneNo pointing device is available.
coarseAt least one input mechanism includes a pointing device of limited accuracy.
fineAt least one input mechanism includes an accurate pointing device.

Using JavaScript

In the following example, we will demonstrate how to set the CSS @media any-pointer media feature by using javascript.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <h1>CSS @media any-pointer</h1> <button onclick="myFunction()">Click Me</button> <script> function myFunction(){ var styles = 'h1{ color:green;}'; var styleSheet = document.createElement("style"); styleSheet.type = "text/css"; styleSheet.media = "(any-pointer: fine)"; styleSheet.innerText = styles; document.head.appendChild(styleSheet); } </script> </body> </html>

Reminder

Hi Developers, we almost covered 98.7% of CSS Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in CSS.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author