tags:

views:

1071

answers:

4

What's the "correct" semantic way to specify image height and width? In CSS...

width:15px;

or inline...

<img width="15"

?

CSS seems like the right place to put visual information. On the other hand, few would argue that image "src" should not be specified as an attribute and the height/width seem as tied to the binary image data as the "src" is.

(Yes, I realize from a technical, end-user perspective this really doesn't matter.)

+2  A: 

If it's part of your site template, I'd place it in the CSS file.

If it's just on one page, it should be inline (or defined in a block of page-specific CSS at the top).

Nerdling
+8  A: 

It should be defined inline. If you are using the img tag, that image should have semantic value to the content, which is why the alt attribute is required for validation.

If the image is to be part of the layout or template, you should use a tag other than the img tag and assign the image as a CSS background to the element. In this case, the image has no semantic meaning and therefore doesn't require the alt attribute. I'm fairly certain that most screen readers would not even know that a CSS image exists.

VirtuosiMedia
Ah yes, excactly the right answer. Img tags are for information, css backgrounds are for layout.
Pim Jager
A: 

I'd say CSS.

HTML is about content,
CSS is about presentation.

stevenvh
A: 

My take is that it is part of the content,as you mentioned, much as the src attribute is too.

On the other hand there's no real need to specify width or height in either html or css, though it might help your page render faster.

spiral