What Can JavaScript Do?
       3 - Change HTML Styles (CSS)

Changing the style of an HTML element, is a variant of changing an HTML attribute:

HTML file: Displayed by browser:
<!DOCTYPE html>
<html>
<body>

<p id="demo">JavaScript can change the style of an HTML element.</p>

<script>
function myFunction() {
    var x = document.getElementById("demo");
    x.style.fontSize = "25px";
    x.style.color = "red";
}
</script>

<button type="button" onclick="myFunction()">Click Me!</button>

</body>
</html>

JavaScript can change the style of an HTML element.


BackTable of ContentsNext