Simple Light/Dark Mode Toggle with HTML, CSS & JavaScript Simple Light/Dark Mode Toggle with HTML, CSS & JavaScript

Simple Light/Dark Mode Toggle with HTML, CSS & JavaScript

Light/Dark Mode Toggle

Hello, World!

This is a simple light/dark mode toggle demo.

This is a terminal-style loader component featuring animated typing and deleting text that mimics a command-line interface. It includes a mock terminal window header with colored control buttons (close, minimize, maximize) for a realistic developer environment feel. Ideal for portfolios or developer-themed web interfaces.

				
					<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>Light/Dark Mode Toggle</title>
  <style>
    :root {
      --background-color: #ffffff;
      --text-color: #000000;
      --button-bg: #007bff;
      --button-text: #ffffff;
      --container-bg: #ffffff;
    }

    body {
      font-family: Arial, sans-serif;
      margin: 0;
      padding: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      background-color: var(--background-color);
      color: var(--text-color);
      transition: background-color 0.3s, color 0.3s;
    }

    .container {
      text-align: center;
      padding: 30px;
      border-radius: 10px;
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
      max-width: 600px;
      background-color: var(--container-bg);
      transition: background-color 0.3s;
    }

    button {
      padding: 10px 20px;
      font-size: 16px;
      border: none;
      border-radius: 5px;
      cursor: pointer;
      background-color: var(--button-bg);
      color: var(--button-text);
      transition: background-color 0.3s;
    }

    button:hover {
      background-color: #0056b3;
    }

    body.dark-mode {
      --background-color: #121212;
      --text-color: #ffffff;
      --button-bg: #444444;
      --button-text: #ffffff;
      --container-bg: #1e1e1e;
    }
  </style>
</head>
<body>
  <div class="container">
    <h1>Hello, World!</h1>
    <p>This is a simple light/dark mode toggle demo.</p>
    <button id="theme-toggle">Switch to Dark Mode</button>
  </div>

  <script>
    const toggleButton = document.getElementById('theme-toggle');
    const body = document.body;

    toggleButton.addEventListener('click', () => {
      body.classList.toggle('dark-mode');
      toggleButton.textContent = body.classList.contains('dark-mode')
        ? 'Switch to Light Mode'
        : 'Switch to Dark Mode';
    });
  </script>
</body>
</html>