9

Am I not allowed to specify the unit for width and height on <img> tags in HTML5?

I am getting this error from the validator:

Bad value 122px for attribute width on element img: Expected a digit but saw p instead.

3 Answers 3

23

Drop the 'px' part. Use only non-negative integers.

Sign up to request clarification or add additional context in comments.

6 Comments

I know that's what it's asking me, but why so? I come from an XHTML background and am fond of px at the end. It seems normal. Why does it let me end the image tag with a short closing XML syntax, <img/> but doesn't let me specify px?
In previous versions of HTML, other units were supported but pixels were the default. The HTML5 specification drops (wisely, in my opinion) support for other units. Anything more complex should be handled in CSS.
These tags never have had units, other than as a %. Remember that they are relics of the bad old days! w3.org/TR/1999/REC-html401-19991224/types.html#type-length
@Francisc: Can you provide a reference for that?
It's not true, XHTML doesn't specify (as it's not a difference from HTML4), and HTML4 doesn't allow it. style="width:100px;" is of course correct, but width=100px is wrong.
|
7

Move the percentage width from the html tag to the in-line style:

For example:

Change this line

<iframe width="100%" height="588" style="border:none; background:transparent; overflow:hidden;" />

to this:

<iframe height="588" style="border:none; background:transparent; overflow:hidden; width:100%;" />

then it will validate...

Comments

4

just write 122 instead of 122p

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.