The DOM clientWidth Property is used to return the viewable width of a specific element including padding but excluding the measurement of margin, border, and scrollbar width. This property only returns the actual width of an element that is viewable or visible to the user. It is a read-only property.
Syntax:
element.clientWidth
Return Value: It returns a Numeric value that represents the viewable width of an element.
Example: In this example, we will use DOM clientWidth property
HTML
<!DOCTYPE html>
< html >
< head >
< title >
HTML | DOM clientWidth Property
</ title >
< style >
h1 {
color: green;
font-size: 35px;
}
#GFG {
height: 200px;
width: 250px;
padding: 40px;
margin: 25px;
border: 5px solid coral;
background-color: green;
}
</ style >
</ head >
< body >
< center >
< h1 >GeeksForGeeks</ h1 >
< h2 >DOM clientWidth Property </ h2 >
< div id = "GFG" >
< h4 style = "color:white;font-size:40px;" >
GeeksforGeeks
</ h4 >
< p id = "sudo" style = "color:white;" ></ p >
</ div >
< button onclick = "Geeks()" >Submit</ button >
< script >
function Geeks() {
let w = document.getElementById("GFG");
let x = "viewable Height is: "
+ w.clientHeight +
"px< br >";
x += "viewable width is:: "
+ w.clientWidth + "px";
document.getElementById("sudo").innerHTML = x;
}
</ script >
</ center >
</ body >
</ html >
|
Output:
Supported Browsers: The browser supported by DOM clientWidth property are listed below:
- Google Chrome 1.0
- Edge 12.0
- Internet Explorer 5.0
- Firefox 1.0
- Opera 8.0
- Safari 3.0
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
09 Jun, 2023
Like Article
Save Article