Kiti
Kiti

Reputation: 543

is </img> tag for embedding Title of Image?

Just wondering why do we need </img>?

For example, <img src="myurl.com/pic.gif" /> is enough for showing image but we can also do thing like this:

<img src="myurl.com/pic.gif"> This is my image</img>, then it will show the text "This is my image" next to the picture.

so my question is:

is tag for embedding Title of Image?

But we can do the same thing like this:

<img src="myurl.com/pic.gif" /> This is my Image.

Upvotes: 3

Views: 81

Answers (4)

geoff
geoff

Reputation: 2276

If you try to put this code through an HTML5 validator, it will say it's invalid and that the closing tag </img> is not needed. You are right that all you need is <img ... />.

In the past, all tags were declared as <tag></tag> In XHTML, you may see <img></img> but no content will appear between the tags.

So you are right, you should simply use <img .../> Some Text Here to display text next to any image.

Upvotes: 4

Quentin
Quentin

Reputation: 943579

Just wondering why do we need </img>?

You do not. img is an EMPTY element. The end tag is forbidden in HTML.

In XHTML you may use either <img></img> or <img /> (the latter syntax is required for HTML Compatible XHTML) but you may not have content between <img> and </img>.

<img src="myurl.com/pic.gif"> This is my image</img>, then it will show the text "This is my image" next to the picture.

As far as the browser is concerned, this means:

  1. Start of img element
  2. img element has a forbidden end tag, so also end of img
  3. Some text
  4. Invalid end tag which is ignored

Upvotes: 1

adam
adam

Reputation: 240

Unfortunately, in the img tag, you cannot set a title that will appear next to the image.

Only title, which will be the text of the toolltip above the image and alt which will be displayed if there is some problem with getting the image.

Upvotes: 1

psur
psur

Reputation: 4519

According to HTML 4.01 standard it's empty element: http://www.w3.org/TR/1999/REC-html401-19991224/struct/objects.html#h-13.2

The IMG element has no content (...)

Moreover, you shouldn't close it unless using XHTML (<img> not <img/>).

Upvotes: 2

Related Questions