1

I know the <img> tag is an inline element.

Which means that the width property of css should not be applicable on img.

width and height are not applied on inline divs.

Then why the width property is applicable on img tag which is an inline element?

Jon B
  • 71
  • 1
  • 7

1 Answers1

1

By default img is an inline element but the dimensions are defined by the dimension of the image itself. You can set the value for with and height allowing it to take up space before it loads, to mitigate content layout shifts.

From MDN : <img> is a replaced element; it has a display value of inline by default, but its default dimensions are defined by the embedded image's intrinsic values, like it were inline-block. You can set properties like border/border-radius, padding/margin, width, height, etc. on an image.

Sfili_81
  • 2,377
  • 8
  • 27
  • 36