Media Query for Dark Mode
CSS
Hard
2 views
Problem Description
Use prefers-color-scheme to adjust colors.
Output Format
Print the HTML+CSS code in one block.
Constraints
Use @media (prefers-color-scheme: dark).
Official Solution
<!doctype html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>meetcode</title>
<style>
body { margin: 0; font-family: system-ui, Arial, sans-serif; background: #fff; color: #111; padding: 16px; }
@media (prefers-color-scheme: dark) {
body { background: #0b1220; color: #f7f7f7; }
}
</style>
</head>
<body>
<h1>meetcode</h1>
<p>Theme changes with system setting.</p>
</body>
</html>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!