Does omitting the px matter?

I could define a padding with padding: 5 10 2 8; in CSS.
And a width with <img … width=“100” /> in HTML.

But is this acceptable as a standard? Or do I have to end all values with px?

Personally I’m lazy to type px all the time. Its 8 characters just for a padding of 4 sides.

THe image width=“100” in the HTML doesn’t matter since it can be accepted as a value.

Ommiting the px is foolish and invalid. First of all, if you do this
padding:6

What’s the value? em? %? px? elephant? computer? It c ould be anything in the world…just looking outside…ladder…grass…plant

It can be anything. The width=“100” is valid, though not your padding example.

As far as I know, it’s necessary. I know it’s standards-compliant.

That’s the flip side. It’s just 8 characters to make sure your site displays properly in all browsers. Not a lot to ask.

:lol: Ryan, we’re crossposting. Grandma sends cookies. :cookie:

Omitting units for paddings and margins in CSS is not permitted unless the value is 0.

You can omit the unit in your img element, however. It’ll then fall back to the default unit which is pixels.

glad i asked. ok…shall keep my codes up to standards then.

kohoutek, can you explain how you know the “default unit” for WIDTH is pixels?

Let’s say for example you have as follows: <img src=“…” alt=“…” /> the IMG is an empty ‘replaced element’ thus would not have a “default unit” for a “width”.

If anything it would be a percentage (%) width if I understand it correctly and not actually pixel units.

I assume you meant if the IMG had a WIDTH attribute omitted and no CSS was involved that you believe it would be replaced by “pixel units”, which I cannot see is the case.

Or do you actually mean the actual image SRC file let’s say ‘sample.png’ would “default override” and force the issue.

Otherwise I cannot see how it has a default unit in the absence of either CSS or an explicit ‘width’ value, i.e. =“100” or “100%” .

If I ‘misunderstood/misread’ your answer; then that’s fine. :slight_smile:

No, that is not valid CSS. You have to specify a unit for all non-zero values.
For values that are zero, it’s optional to specify a unit. I personally recommend omitting them.

In this case it is an error to add a ‘px’ unit. Length values in HTML attributes are automatically in pixels, unless you add a ‘%’ character at the end.

The HTML 4.01 DTD specifies it, at least here.

Like I said it doesn’t say pixels but %Length; and as it is replaced it cannot have a known default unit.

What I originally meant it can be either; ‘pixel’ or ‘percentage’ just in case I wasn’t clear. Most likely I just misread her answer to mean; “only” pixel would be ‘default’. :slight_smile:

Hi XHTMLCoder.

Yes, that is what I mean. If no unit is specified via CSS then the HTML element’s value (width=“100”) will be automatically in pixels.

I’m not sure anyone actually said but in a strict doctype values without a unit will be treated as zero so the above will be rendered as padding:0 0 0 0;

Are you sure that they actually get treated as zero or is it just that the default unit is attometres and so the distances are sub-microscopic but still there and just get rounded to zero. I guess if you specified sizes like 1000000000000000000000000 we could find out since that many attometres would actually round up to be a pixel:):):slight_smile:

Thanks, I suspected as such - I misread the answer - I have a damn head-cold at the moment; and that combined with word-blindness means my reading ability diminishes considerably.

Ah, I see they actually changed the values slightly from 3.2 to 4.01:

http://www.w3.org/TR/REC-html32.html#img
width %Pixels #IMPLIED – suggested width in pixels –

http://www.w3.org/TR/1999/REC-html401-19991224/struct/objects.html#h-13.2
width %Length; #IMPLIED – override width –

That explains why you said that; you were referring to an earlier version where it got treated differently - previously pixels only - interesting nonetheless. :cool:

Thankee

I really don’t see there being much to contend about, it’s almost like saying “how long is a piece of string”, providing unit numbers without the implied unit value is pretty crazy. Especially as the unit values have a very big difference between how the design would be affected as a result. Why play guessing games with the rendering engines, there’s enough “loose” interpretations of the spec’s without designers confusing the browsers to boot with generic number values. :slight_smile: