Open In App
Related Articles

HTML DOM console clear() Method

Improve Article
Save Article
Like Article

The console.clear() method in HTML is used to clear the console and writes some message “Console was cleared” on the console whenever it is executed. This method does not require any parameter. 



Example: The below program illustrates the console.clear() method in HTML:


<!DOCTYPE html>
        DOM console.clear() Method in HTML
        h1 {
            color: green;
        h2 {
            font-family: Impact;
        body {
            text-align: center;
    <h2>DOM console.clear() Method</h2>
        To view the message in the console press the F12
        key on your keyboard.
        To clear the console, double click
        the button below:
    <button ondblclick="clear_console()">
        Clear Console
        console.log("GeeksforGeeks is a portal for geeks!");
        function clear_console() {


In the above example, we can see that the console is clear by double-clicking on the clear console button. 

Supported Browsers: The browser is supported by the console.clear() method are listed below:

  • Google Chrome 25
  • Edge 12
  • Firefox 39
  • Opera 12
  • Safari 7

Last Updated : 03 Aug, 2023
Like Article
Save Article
Similar Reads
Related Tutorials