JavaScript – Clear Inline Style of HTML Element

To clear Inline Style of a HTML Element using JavaScript, get reference to the HTML Element element, and assign empty string value to the property.

Note: This solution clears only the inline style. Any global styles using style sheets shall be applied to the element.

In the following example, we will clear the inline style of HTML Element with id "myElement", in JavaScript, using property.


<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <h2>Clear Inline Style of HTML Element in JavaScript</h2>
    <div id="myElement" style="border:1px solid #CCC;width:100px;height:100px;">Hello World!</div>
    <button type="button" onclick="changeStyle()">Click Me</button>
    function changeStyle(){
        var element = document.getElementById("myElement"); = "";
Try Online


In this JavaScript Tutorial, we learned how to clear inline style of a HTML Element using JavaScript.