Categories
Web development

How to put an image into HTML code?

The HTML Image tag is the last HTML element which I would like to have a look deeper before we will go further to CSS. The image <img> tag is used to insert an image into the document. 

HTML Image

The HTML image element mustn’t contain any content and doesn’t need a closing tag. The HTML <img> tag has two required attributes: src (source) and alt (text). 

Example:

<!DOCTYPE html>
<html>
<body>

<h4>HTML Image</h4>
<img src="avatar.jpg" alt="avatar" width="640" height="480">

</body>
</html>

Output:

avatar

To link an image to another website/ HTML document, nest the <img> tag inside <a> tags. 

Attributes: 

alt (text) defines alternative text for the image. Shows when the image can not be displayed. 


height (pixels) defines the height of the image. 


src (URL) defines the source of the image. 


width (pixels) defines the width of the image. 

Enjoy coding!

Read also:

HTML Attributes

HTML Radio Buttons