HTML | DOM Style width Property Last Updated : 05 Aug, 2022 Comments Improve Suggest changes Like Article Like Report The Style width property in HTML DOM is used to set or return the width of an element which can be block-level elements or elements with fixed position. Syntax: It is used to return the width property:object.style.widthIt is used to set the width property:object.style.width = "auto|length|%|initial|inherit" Property Value Description auto-This value automatically sets the default width value by the browser.length-This value sets the width value in the specified length units.%-Percentage value sets the width value in the specified percentage of the parent element’s width.initial-This value sets the width property to its browser’s default value.inherit-This value sets the width property to the value from its parent element. Return Value: A String, representing the width of an element. Example 1: HTML <!DOCTYPE html> <html> <head> <style> #GfG { width: 100px; height: 100px; background-color: green; color: white; } </style> </head> <body> <p>HTML|DOM Style Width Property:</p> <button onclick="myFunction()">Click here!</button> <div id="GfG"> <h1>GfG</h1> </div> <script> function myFunction() { document.getElementById("GfG") .style.width = "500px"; } </script> </body> </html> Output: Before click on the button: After click on the button: Example 2: html <!DOCTYPE html> <html> <body> <h1>GeeksforGeeks</h1> <h2>HTML|DOM Style Width Property:</h2> <button type="button" id="myBtn" onclick="myFunction()">Click Here!</button> <script> function myFunction() { document.getElementById("myBtn") .style.width = "500px"; } </script> </body> </html> Output: Before click on the button: After click on the button: Supported Browsers: The browser supported by DOM style width property are listed below: Google Chrome 1Edge 12Internet Explorer 4Firefox 1Safari 1Opera 3.5 Create Quiz Comment D divyatagoel0709 Follow 0 Improve D divyatagoel0709 Follow 0 Improve Article Tags : JavaScript Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)8 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like