Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close <img> tag properly?

Tags:

html

<img src='stackoverflow.png'>
<img src='stackoverflow.png'></img>
<img src='stackoverflow.png' />

Which one(s) of them is correct?

like image 422
insertusernamehere Avatar asked Oct 01 '22 18:10

insertusernamehere


People also ask

How do you close an IMG tag?

The <img /> Tag This tag is different than other tags, in that it has no closing tag. It is called a self-closing tag, which means that there is just a slash at the end of the opening tag (ex. <img />). There are very few self-closing tags in HTML.

Does IMG tag have closing tag?

<img> HTML – Image Tag Tutorial. In HTML, you use the <img> tag to add images to websites. It is an inline and empty element, which means that it doesn't start on a new line and doesn't take a closing tag (unlike the paragraph ( <p> ) tag, for instance).


1 Answers

This one is valid HTML5 and it is absolutely fine without closing it. It is a so-called void element:

<img src='stackoverflow.png'>

The following are valid XHTML tags. They have to be closed. The later one is also fine in HTML 5:

<img src='stackoverflow.png'></img>
<img src='stackoverflow.png' />
like image 201
Marvin Rabe Avatar answered Oct 19 '22 09:10

Marvin Rabe