Change the width of an image to 300px:
The width property sets or returns the value of the width attribute of an image.
The width attribute specifies the width of an image.
This property can also return the width of an image that has been styled with CSS (See More Examples).
Tip: Use the height property to set or return the value of the height attribute of an image.
The width property is supported in all major browsers.
Return the width property:
Set the width property:
Value | Description |
---|---|
pixels | The width in pixels (e.g. height="100") |
Return Value: | A Number, representing the width of the image, in pixels |
---|
Return the width of an image:
The result of x will be:
Change the height and width of an image to 300px:
Return the width of an image that has been styled with CSS:
HTML reference: HTML <img> width attribute