No id or name attribute for img?

(Apologize in advance – My sitepoint search comes up empty, so starting new thread)

The W3C specs http://www.w3.org/wiki/HTML/Elements/img#HTML_Attributes show neither “id” nor “class” as valid img attributes. Does that mean I need to enclose the img tag within a block element such as “div” or “p”?

I have two images in my paragraph. I want the second image to appear below the text.I want to float the first image left of the text-and-second-image.block via css.

an id or class in the img tag would obviate additional markup, and I see that done in most examples on the net … but is it “legal”?

rgrds.

grNadpa

Any tag inside the <body> is allowed to have an id and/or class attribute.

The page you linked to lists those attributes that are specific to <img> tags. There is a link at the bottom of that section to the global attributes that are allowed for any tag in the body.

Thank you. BTW, I hear you folks are having a bit of a heat wave down under. It’s below zero here … and I’ve shoveled enough snow to last me for awhile.

The w3c RFCs do take a while to get used to enough to comprehend them. But IMHO they are pretty much the defintive reference for all web things Standard and you can’t go wrong studying them.

Off Topic:

Snow! You and me both. Between the wind chill factor and my being not-so-young-anymore it sure is a chore.

I notice that your title asks about id and name attributes for the <img> tag, but the body of your query lists id and class.

id and class are valid HTML attributes for the <img> tag but name is not, although browsers may still recognize it. My advise is not to use name as an <img> attribute.

Nice catch. So it actually becomes two questions doesn’t it? And agree with your answer. Thanks

name attributes are only valid on input and textarea fields. They are used to pass the value from the field to the server.No other HTML tag has a value attribute that needs to be passed to the server and so none of the others need a name attribute.

Basically the name and value attributes are a key/value pair and so you shouldn’t have one without the other (except for JavaScript only forms where the name becomes optional for some fields).