What’s the difference between HTML’s and CSS’s width attribute?

I checked the documents, but they don’t make clear what will happen if both of them are set..

That’s hidden away somewhere here:

The UA may choose to honor presentational attributes in an HTML source document. If so, these attributes are translated to the corresponding CSS rules with specificity equal to 0, and are treated as if they were inserted at the start of the author style sheet. They may therefore be overridden by subsequent style sheet rules. In a transition phase, this policy will make it easier for stylistic attributes to coexist with style sheets.

Now, as I’ve implied in my humorous comment, I don’t know for certain why they would set a variety of values for the HTML width attribute on the img elements and have a single, different value for the CSS width property for all of them. Perhaps they’re accounting for when the .thumbnail class is missing, or something else. As always, Alohci is in a better position to explain why the width and height attributes are specified anyway, even if they differ from the dimensions specified in CSS for whatever reason.

What I can tell you, however, is that this basically means the CSS does indeed take precedence anyway, even if both are set.

Leave a Comment