The Wayback Machine - https://web.archive.org/web/20230321223600/https://www.geeksforgeeks.org/hide-the-cursor-in-a-webpage-using-css-and-javascript/
Skip to content
Related Articles
Open in App
Not now

Related Articles

Hide the cursor in a webpage using CSS and JavaScript

Improve Article
Save Article
  • Last Updated : 16 Jan, 2023
Improve Article
Save Article

Given an HTML document and the task is to hide the cursor from the given element using CSS and JavaScript. 

Approach:

  • First, select the element where the cursor element needs to hide.
  • Add CSS style cursor: none to the class.
  • Add the class name (class name of CSS style cursor:none) to the particular element where the cursor element is to be hidden.

Example 1: This example hides the cursor from the <div> element. 

html




<style>
    #GFG_DIV {
        background: green;
        height: 100px;
        width: 200px;
        margin: 0 auto;
        color: white;
    }
      
    /* CSS style to hide cursor element */
    .newClass {
        cursor: none;
    }
</style>
  
<h1 style="color:green;">
    GeeksforGeeks
</h1>
  
<p id="GFG_UP" style="font-size: 19px; font-weight: bold;">
</p>
  
<div id="GFG_DIV">
    This is Div box.
</div>
<br>
  
<button onClick="GFG_Fun()">
    click here
</button>
  
<p id="GFG_DOWN">
</p>
  
<!-- Script to hide cursor element -->
<script>
    var up = document.getElementById('GFG_UP');
    var down = document.getElementById('GFG_DOWN');
    var div = document.getElementById('GFG_DIV');
      
    up.innerHTML = "Click on button to hide the cursor from DIV.";
      
    /* Function to add class name to hide cursor element */
    function GFG_Fun() {
        div.classList.add("newClass");
        down.innerHTML = "Cursor is removed from DIV!";
    }
</script>

Output:

 

Example 2: This example hides the cursor from the <body> of a web page. 

html




<style>
    #GFG_DIV {
        background: green;
        height: 100px;
        width: 200px;
        margin: 0 auto;
        color: white;
    }
      
    /* CSS style to hide cursor element */
    .newClass {
        cursor: none;
    }
</style>
  
<body id="body">
  
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
  
    <p id="GFG_UP">
    </p>
  
    <div id="GFG_DIV">
        This is Div box.
    </div>
    <br>
  
    <button onClick="GFG_Fun()">
        click here
    </button>
  
    <p id="GFG_DOWN">
    </p>
  
    <!-- Script to hide cursor element -->
    <script>
        var up = document.getElementById('GFG_UP');
        var down = document.getElementById('GFG_DOWN');
        var body = document.getElementById('body');
          
        up.innerHTML = "Click on button to hide the cursor from DIV.";
          
        /* Function to add class name to hide cursor element */
        function GFG_Fun() {
            body.classList.add("newClass");
            down.innerHTML = "Cursor is removed from body!";
        }
    </script>
</body>

Output:

 


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!