9

What is the difference between width, naturalWidth, and clientWidth?

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
galeb
  • 155
  • 2
  • 8

2 Answers2

10

Read this:

Understanding offsetWidth, clientWidth, scrollWidth and -Height, respectively

example: <img> tag

naturalWidth: it is the original width of the image used in tag.

width: it is the value/default value of width attribute of tag.

Community
  • 1
  • 1
Vijay
  • 2,965
  • 1
  • 15
  • 24
2

clientWidth represents the width of the element and is subject to manipulation by the browser. For example, a 300px wide image can be resized and this manipulated value will come through in clientWidth.

naturalWidth is the natural width of the element. In the example of a 300px wide image, the naturalWidth will still be 300 even if the image is resized in the browser via CSS or JavaScript.

Chris Troutner
  • 477
  • 6
  • 7