ajkishore
ajkishore

Reputation: 41

Can we give a name attribute in <img> in HTML

Is the "name" attribute can given in an "img" tag in HTML?

Kindly let me know if whoever knows and thanks in advance.

Upvotes: 2

Views: 13003

Answers (3)

Roko C. Buljan
Roko C. Buljan

Reputation: 206121

No. You cannot1 have such attribute.

1The name attribute on the <img> tag is deprecated since HTML4.1 and obsolete since HTML5.
Use id or data-* attribute instead (like: data-name="whatever") if you need custom attributes.


<img> Attributes

  • align Deprecated since HTML4.01, Obsolete since HTML5 Use the vertical-align CSS
  • alt
  • border Deprecated since HTML4.01, Obsolete since HTML5
  • crossorigin (HTML5)
  • height
  • hspace Deprecated since HTML4.01, Obsolete since HTML5
  • ismap
  • longdesc
  • name Deprecated since HTML4.01, Obsolete since HTML5 Use id or data-*
  • referrerpolicy
  • sizes (HTML5)
  • src
  • srcset (HTML5)
  • width
  • usemap
  • vspace Deprecated since HTML4.01, Obsolete since HTML5

https://www.w3.org/TR/html-markup/img.html
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img

Upvotes: 1

Adnan D.
Adnan D.

Reputation: 440

Yes you can by using alt, here is an example:

<img src="smiley.gif" alt="Smiley face" height="42" width="42">

Upvotes: 0

Bhavin Solanki
Bhavin Solanki

Reputation: 4818

Yes, you can give name attribute to image , but instead of giving name attribute, i suggest use data-name. It is good habit to give private use of attribute name.

Upvotes: 2

Related Questions