0

I have this code:

<img src="Media//Service//rightImage.jpg" alt="Watch Repair" width="380px" height="272px" style="float:right;" />

and the HTML validation tool on the w3.org website I am using is saying that I cannot use a width of "380px" because:

Bad value 380px for attribute width on element img: Expected a digit but saw p instead. …ge.jpg" alt="Watch Repair" width="380px" height="272px" style="float:right;" /> Syntax of non-negative integer: One or more digits (0–9). For example: 42 and 0 are valid, but -273 is not.

Does this mean I should just delete the px part and it will run fine? I thought I have to define the width as pixels?

Very confused! Can anyone explain this to me? Thanks guys!

Mayron
  • 59
  • 5
  • @Pekka웃 Any proof for that? The w3c says width attribute for img tag is absolutely valid, even in html5: http://dev.w3.org/html5/markup/img.html#img.attrs.width – bouscher Jun 06 '13 at 09:07
  • Where exactly have you found width properthy is deprecated? @Pekka웃 – Lenin Jun 06 '13 at 09:07
  • Also, you wrote the inline style. Which is not suggested unless is EXTREMELY unavoidable. @Pekka웃 – Lenin Jun 06 '13 at 09:09
  • @Lenin oh, you're right, it's not deprecated, not even in HTML 5: http://dev.w3.org/html5/markup/img.html I restate, use of the CSS `width` property is generally encouraged; ideally, in an external class definition (which may not alway be feasible with images though) – Pekka Jun 06 '13 at 09:10
  • If you check with markup validators. Some of them looks for the width and height of given images. @Pekka웃 – Lenin Jun 06 '13 at 09:11
  • @Lenin it's not a required property though. – Pekka Jun 06 '13 at 09:12
  • Check this out @Pekka웃 :) http://stackoverflow.com/questions/640190/image-width-height-as-an-attribute-or-in-css – Lenin Jun 06 '13 at 09:14

4 Answers4

2

You don't need to write "px" with width or height property of img

The width attribute specifies the width of an image, in pixels.

just write something like this

<img src="Media//Service//rightImage.jpg" alt="Watch Repair" width="380" height="272" style="float:right;" />

and the preferred way is to use style property to define these properties

<img src="Media//Service//rightImage.jpg" alt="Watch Repair" style="width:380px;height:272px;float:right;" />
Sachin
  • 40,216
  • 7
  • 90
  • 102
  • Thank you. Not sure if it really matters which way. To me the way without using the style property seems simpler but that is just me. – Mayron Jun 06 '13 at 09:11
  • http://stackoverflow.com/questions/2414506/should-image-size-be-defined-in-the-img-tag-height-width-attributes-or-in-css Worth following. @Mayron – Lenin Jun 06 '13 at 09:23
  • 1
    You *must not* use `px` there. And the use of an external style sheet is preferred over `style` attributes, but no HTML specification recommends against `height` and `width` attributes when used to specify the actual, inherent size of the image (as opposite to rescaling). – Jukka K. Korpela Jun 06 '13 at 10:43
1

Yes, its very trivial. You'd have to delete the px part and leave the numbers, they are always in pixels anyway. http://www.w3schools.com/tags/att_img_width.asp

A related thread for this which would help others: Image width/height as an attribute or in CSS?

Another on the same is: Should image size be defined in the img tag height/width attributes or in CSS?

Community
  • 1
  • 1
Lenin
  • 570
  • 16
  • 36
  • 1
    Ah okay thank you, so after looking it up as well I finally found that it is done in pixels anyway so it is not needed. – Mayron Jun 06 '13 at 09:10
  • 1
    w3schools should not be cited as any kind of authority, or at all, see http://w3fools.com – Jukka K. Korpela Jun 06 '13 at 10:41
  • I am aware of [w3fools.com](http://w3fools.com). But I have quoted from the same topic of the OP. And the other SO links I have placed are worth reading. Dont just rely on w3fools, because its not complete. Just a ranter! – Lenin Jun 06 '13 at 14:49
1

By HTML5 rules, the dimension attributes, if used, must have values that are valid non-negative integers. No unit is needed, or accepted. The implied unit is CSS pixel. So yes, you should simply remove the px parts.

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390
0

remove 'px' from height & width attributes

Jay
  • 3,353
  • 5
  • 25
  • 34