Friday, October 24, 2025
HomeLanguagesJavascriptWhat is the use of the “no-js” class in HTML ?

What is the use of the “no-js” class in HTML ?

Purpose:

  • The primary purpose of the no-js class is to allow the use of CSS to style JavaScript-free pages, i.e. defining CSS styles for JavaScript-enabled browsers as well as for JavaScript-disabled browsers.
  • Thus, the “no-js” class will only be present if JavaScript has been disabled. This enables styling a pure HTML and CSS page without the use of any client side-scripting.
  • But if JavaScript is enabled, it removes the “no-js” class automatically.
  • The “no-js” class is available in the markup by default.
  • The “no-js” class is basically a way to be able to style things with or without using JavaScript.
  • The “no-js” class is added to the topmost html element which serves as an instruction for Modernizr.

Syntax:

<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->

Example:




<!DOCTYPE html>
<html class="no-js">
  
<head>
    <script>document.documentElement.className
        = document.documentElement.className
        .replace(/\bno-js\b/g, '') + ' js ';
    </script>
  
    <!-- Other files and libraries
        to be included -->
    <head>
  
    <body>
        <center>
            <h1>neveropen</h1>
        </center>
    </body>
  
</html>


Output:

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS