Using the style property
The style property allows you to change CSS styles directly with JavaScript. This lets you create dynamic, interactive designs!
// HTML:
<div id="box">Hello!</div>
// JavaScript:
let box = document.getElementById("box");
// Change the background color
box.style.backgroundColor = "blue";
// Change the text color
box.style.color = "white";
// Change the font size
box.style.fontSize = "24px";Note: CSS properties with dashes (like background-color) become camelCase in JavaScript (backgroundColor)!