Complete the code to enable dark mode based on user's system preference.
<html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Dark Mode Example</title> <script> tailwind.config = { darkMode: '[1]' } </script> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="bg-white dark:bg-gray-900 text-black dark:text-white"> <h1 class="text-2xl font-bold">Hello, World!</h1> </body> </html>
Setting darkMode to media tells Tailwind to use the user's system dark mode preference.
Complete the class attribute to apply dark mode background color.
<div class="bg-white [1]:bg-gray-800 p-4"> <p>This box changes color in dark mode.</p> </div>
The dark: prefix applies styles when dark mode is active.
Fix the error in the Tailwind config to enable media-based dark mode.
module.exports = {
darkMode: '[1]',
content: ['./src/**/*.{html,js}'],
theme: {
extend: {},
},
plugins: [],
}The value must be lowercase 'media' to work correctly in Tailwind config.
Fill both blanks to create a responsive dark mode button with hover effect.
<button class="bg-white [1]:bg-gray-700 text-black [2]:text-white px-4 py-2 rounded"> Click me </button>
The dark: prefix changes background in dark mode, and hover: changes text color on hover.
Fill all three blanks to create a dark mode card with shadow and rounded corners.
<div class="bg-white [1]:bg-gray-900 [2]shadow-lg [3]rounded-lg p-6"> <h2 class="text-xl font-semibold">Card Title</h2> <p>This card adapts to dark mode.</p> </div>
dark: changes background in dark mode, active: adds shadow on click, and hover: rounds corners on mouse hover.