HTML img Tag width Attribute Tutorial

In this section, we will learn what the width attribute is and how to use it.

What is width Attribute in HTML <img> Tag?

The width attribute in HTML <img> element is used to set the width of the target image in a document.

You should know that by default, browsers use the default width of the target image when they render it on a page. So if the width is, for example, 100 pixels, then the rendered image in the document would have the same width!

But depending on the structure of our document, we might need to change the width of the target image. This is where we can use the width attribute.

HTML width Attribute in <img> Tag Syntax:

<img src = “image” width = “value”>

<img> Tag width Attribute Values

The value we set for the width attribute could be any number with supported relative and absolute units.

Example: using width attribute in HTML <img> tag

See the Pen using width attribute in HTML <img> tag by Omid Dehghan (@odehghan) on CodePen.

Leave a Reply