HTML Images

HTML img element adds an image in a page. Firstly we write an image tag. Then, we add the src attribute in the <img> tag.

Syntax to add an image.

Example

<img src="files/logo.png"  alt="codingb-logo" width="300"/>

Try </>

src attribute specifies the location (address) of the image.

Image Related Attributes

src attribute

src attribute specifies the location (address) of the image.

Example

<img src="files/logo.png" alt="codingb logo is present here."/>
Try </>

alt attribute

alt attribute is used to give the alternate name to an image in the form of text.

Example

<img src="files/logo.png" alt="codingb logo is present here."/>

Try </>

This text can be seen when an image is not available due to slow network or wrong address.

height attribute

height attribute represents the vertical dimension.

Example

<img src="files/web.png" height="400px">

Try </>

width attribute

height attribute represents the horizontal dimension.

Example

<img src="files/web.png" width="400px">

Try </>

NOTE: align attribute was used to align the image in the text but now it is obsolete. align attribute is not included in HTML5.

Tip: Always remember there is no end tag for <Img>. Therefore, only one tag is used. You can also use <img /> tag.



Was this article helpful?