Reputation: 41
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
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>
Attributesalign
Deprecated since HTML4.01, Obsolete since HTML5 Use the vertical-align CSS alt
border
Deprecated since HTML4.01, Obsolete since HTML5crossorigin
(HTML5)height
hspace
Deprecated since HTML4.01, Obsolete since HTML5ismap
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
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
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