WEBLEB
Home
Editor
Login
Pro
English
English
Français
Español
Português
Deutsch
Italiano
हिंदी
change color
194
mambetov1237.b
Open In Editor
Publish Your Code
Recommended
1 December 2024
Gradient Color on Hover
9 December 2024
How to animate background-color
HTML
Copy
HELLO
Bienvenue sur mon site web!
Changer la couleur,
press twice
CSS
Copy
body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; height: 100vh; flex-direction: column; } h1 { color: white; /* color: #4caf50; */ font-size: 3rem; margin-bottom: 20px; } p { color: white; /* color: #ffd700; */ font-size: 1.5rem; } button { background-color: #4caf50; color: white; border: none; padding: 10px 20px; font-size: 1rem; cursor: pointer; margin-top: 20px; }<!-- Replace with your HTML Code (Leave empty if not needed) -->
JS
Copy
function changeColor() { const body = document.body; const h1 = document.querySelector("h1"); const p = document.querySelector("p"); if (body.style.backgroundColor === "rgb(244, 244, 244)") { body.style.backgroundColor = "#FFD700"; h1.style.color = "#4caf50"; p.style.color = "#4caf50"; } else { body.style.backgroundColor = "#f4f4f4"; h1.style.color = "#white"; p.style.color = "#white"; } }/* Replace with your JS Code (Leave empty if not needed) */