jQuery width()Methods
Examples
Return the width of a <div> element:
Try it Yourself »
Definition and Usage
The width() method sets or returns the width of the selected elements.
When this method is used toreturnthe width,then it returns the width of the first matched element.
When this method is used tosetthe width, it sets the width of all matched elements.
As shown in the image below, this method does not include padding, border, or margin.

Related Methods:
- height()- Set or return the height of an element
- innerWidth()- Return the width of an element (including padding)
- innerHeight()- Return the height of an element (including padding)
- outerWidth()- Return the width of an element (including padding and border)
- outerHeight()- Return the height of an element (including padding and border)
Syntax
Return the width:
Set the width:
Set the width using a function:
| Parameter | Description |
|---|---|
| value | Required when setting the width. Specifies the width of an element in px, em, pt, etc. Default unit is px. |
| function(index,currentwidth) | Optional. Specifies a function that returns the new width of the selected elements.
|
More Examples
Set the width of an element
How to set the width of an element using different units.
Increase the width using a function
How to increase the width of an element using a function.
Return the width of the document and window elements
How to return the current width of the document and window elements.
Display dimensions using related methods
How to use width(), height(), innerHeight(), innerWidth(), outerWidth(), and outerHeight().
Other extensions
jQuery HTML/CSS Methods