YouTip LogoYouTip

Prop Element Clientwidth

HTML DOM clientWidth Property |

-- Learning not just technology, but dreams!

JavaScript Reference

Overview

JavaScript Objects

Browser Objects

DOM Objects

HTML Objects

HTML DOM Document Object

HTML DOM Attribute Object

HTML DOM clientWidth Property

Element Object Reference Element Object

Example

Get the width of a div element, including padding:

var elmnt = document.getElementById("myDIV");
var txt = "div element height, including padding: " + elmnt.clientHeight + "px<br>";
txt += "div element width, including padding: " + elmnt.clientWidth + "px";

Try it yourself Β»


Definition and Usage

The clientWidth property is a read-only property that returns the width of an element in pixels. The width includes padding, but does not include border, margin, or scrollbar. It returns an integer, in pixels (px).

The clientWidth property of inline elements and elements without CSS styles is 0.

CSS Box Model

Note: To understand this property, see the CSS Box Model.

Tip: This property is often used together with the clientHeight property.

Tip: Use the offsetHeight and offsetWidth properties to return the visible height and width of an element, including padding and border.

Tip: To add a scrollbar to an element, use the overflow property.

This is a read-only property.

CSS Box Model Diagram


Browser Support

Property
clientWidth Yes Yes Yes Yes Yes

Syntax

element.clientWidth

Technical Details

Return Value: Returns an integer, representing the width of the element in pixels.

More Examples

Example

The following example demonstrates the difference between clientHeight/clientWidth and offsetHeight/offsetWidth properties:

var elmnt = document.getElementById("myDIV");
var txt = "";
txt += "Height including padding: " + elmnt.clientHeight + "px<br>";
txt += "Height including padding and border: " + elmnt.offsetHeight + "px<br>";
txt += "Width including padding: " + elmnt.clientWidth + "px<br>";
txt += "Width including padding and border: " + elmnt.offsetWidth + "px";

Try it yourself Β»

Example

The following example demonstrates clientHeight/clientWidth after adding a scrollbar to an element:

(Note: The original tutorial content for this example appears to be cut off in the provided source.)

← Docker Cp CommandDocker Wait Command β†’