Using <img> only with a class but without attributes at all

2082 views html

I used to have this for a button:

<img class="left" src="<?php echo $this->webroot."img/arrowleft.png";?>" width="32" height="31" alt="Arrow left button" />

Now I want to use this:

<img class="left" />

Then with CSS I can put a background image, define the size of the button and do everything that I want 100% with CSS. But I was wondering if it is acceptable and according to proper HTML coding standards to have <img> simply with a class and with no properties at all.

answered question

CSS is for presentation. HTML is for content. If you have an img element and don't put a foreground image on it, then you're doing something wrong.

I think there would be no problem with the browser but.. Why don't you use a div or a button element?

For what it's worth, class is an attribute.

@DanFarrell Interesting, you are right, in this case class is an attribute. My question should probably be if it is acceptable to use <img> without the src attribute.

1 Answer


From the spec:

The src attribute must be present, and must contain a valid non-empty URL potentially surrounded by spaces referencing a non-interactive, optionally animated, image resource that is neither paged nor scripted.

posted this

Have an answer?


Please login first before posting an answer.