<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Interactive Color Changer</title>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
transition: background-color 0.5s ease;
background-color: #f0f0f0;
}
.container {
background-color: rgba(255, 255, 255, 0.8);
padding: 30px;
border-radius: 15px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
text-align: center;
}
h1 {
color: #333;
margin-bottom: 20px;
font-size: 2.5em;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}
select {
padding: 12px;
font-size: 18px;
border: 2px solid #ccc;
border-radius: 8px;
outline: none;
cursor: pointer;
margin-bottom: 20px;
width: 200px;
transition: all 0.3s ease;
}
select:hover {
border-color: #888;
}
select:focus {
border-color: #555;
box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
}
.color-preview {
width: 100px;
height: 100px;
border-radius: 50%;
margin: 20px auto;
border: 3px solid #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
.color-name {
font-size: 1.2em;
font-weight: bold;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>Interactive Color Changer</h1>
<select id="colorChange">
<option value="">Choose a color</option>
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
<option value="purple">Purple</option>
<option value="orange">Orange</option>
<option value="pink">Pink</option>
</select>
<div class="color-preview"></div>
<div class="color-name"></div>
</div>
<script>
const color = document.getElementById("colorChange");
const header = document.querySelector("h1");
const container = document.querySelector(".container");
const colorPreview = document.querySelector(".color-preview");
const colorName = document.querySelector(".color-name");
color.addEventListener("change", () => {
const selectColor = color.value;
if (selectColor) {
document.body.style.backgroundColor = selectColor;
colorPreview.style.backgroundColor = selectColor;
colorName.textContent =
selectColor.charAt(0).toUpperCase() + selectColor.slice(1);
const isDark = ["blue", "purple"].includes(selectColor);
header.style.color = isDark ? "white" : "black";
container.style.backgroundColor = isDark
? "rgba(255, 255, 255, 0.9)"
: "rgba(255, 255, 255, 0.8)";
colorName.style.color = isDark ? "white" : "black";
} else {
document.body.style.backgroundColor = "#f0f0f0";
colorPreview.style.backgroundColor = "transparent";
colorName.textContent = "";
header.style.color = "#333";
container.style.backgroundColor = "rgba(255, 255, 255, 0.8)";
}
});
</script>
</body>
</html>