How To Create Dark and Light Mode Website using jQuery

Websolutionstuff | Nov-21-2020 | Categories : jQuery CSS HTML Bootstrap

In this article, we will see how to create a dark and light mode website using jquery. As you can see many websites and mobile applications provide a light theme as well as a dark theme to the user. It is useful for websites that have long content and requires users to focus on the screen for a long time.

Dark and light mode features are very useful for the user especially when your website has more content or text. So, here we will see how to add dark mode and light mode in the website step by step.

So, let's see how to create a dark/light mode website using javascript and day and night mode website using jquery.

Step 1: Create HTML File

Step 2: Add CSS for Dark and Light Mode

Step 3: Add Button for Dark and Light Mode

Step 4: Add Script for Dark and Light Mode Theme

 

Example:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <title>How To Create Dark and Light Mode Website using jQuery ?</title>        
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
    <style> 
        body{         
        text-align:center; 
        } 
        img{ 
            height:140px; 
            width:140px;  
        } 
        h1{ 
        color: #03aa96; 
        margin-top: 50px;
        } 
        .mode { 
            float:right; 
            margin-top: 20px;
            margin-right: 20px;
        } 
        .change { 
            cursor: pointer; 
            border: 1px solid #555; 
            border-radius: 10%; 
            width: 20px; 
            text-align: center; 
            padding: 8px; 
            margin-left: 8px; 
        } 
        .dark{ 
            background-color: #222; 
            color: #e6e6e6; 
        } 
    </style> 
</head>   
<body> 
    <div class="mode"> 
        <b>Select Mode:</b><span class="change">OFF</span> 
    </div><br>     
    <div> 
        <h1>Websolutionstuff</h1> 
        <p><i>We Give Best Stuff for You</i></p> 
        <h3>Light Mode and Dark Mode</h3>                    
        <p> 
            Click on the switch on <b>Top Right Corner</b>
            to move to <b>Dark Mode</b> and <b>Light Mode.</b>
        </p> 
    </div>       
    <script> 
        $( ".change" ).on("click", function() { 
            if( $( "body" ).hasClass( "dark" )) { 
                $( "body" ).removeClass( "dark" ); 
                $( ".change" ).text( "OFF" ); 
            } else { 
                $( "body" ).addClass( "dark" ); 
                $( ".change" ).text( "ON" ); 
            } 
        }); 
    </script> 
</body>   
</html>

 

 

Output: 

How_To_Create_Dark_Mode_Website_using_jQuery

 

 

How_To_Create_Light_Mode_Website_using_jQuery

 


You might also like:

Recommended Post
Featured Post
Implementing CQRS (Command Query Responsibility Segregation) in Laravel 11
Implementing CQRS (Command Que...

Hello, laravel web developers! In this guide, I'll show you how to implement CQRS (Command Query Responsibility Segr...

Read More

Sep-30-2024

Laravel 9 Resize Image Before Upload
Laravel 9 Resize Image Before...

In this article, we will see how to resize image before uploading in laravel 9. we will install the intervention/im...

Read More

Jun-15-2022

How To Create Pie Chart In Laravel 9 Using Highcharts
How To Create Pie Chart In Lar...

In this article, we will see how to create a pie chart in laravel 9 using highcharts. A pie chart is a circular statisti...

Read More

Oct-05-2022

CRUD Operation In PHP
CRUD Operation In PHP

In this tutorial, I will show you how to create a CRUD operation with login-logout in PHP. So, if you are a newcomer in...

Read More

Jul-20-2020