why is a px in css considered redundant?

why is a px in css considered redundant? according to the css inspection tip, producing a warning. I understand I can turn that warning off. I understand px is the default, but it's just explicit, not redunant, no?


lol. That circular argument doesn't even make sense. 1 is 1 no matter the unit of measure. 2 is 2 no matter the unit of measure. Circular logic aside, greater specificity wins, that's why they call it "cascading" style sheets. Another declaration in another sheet may have different defaults. The general <div> for the site may have 5px margins. You may need 0px for your specific box. That should not generate a warning.


0px is redundant, only if it's zero

lol. That circular argument doesn't even make sense. 1 is 1 no matter the unit of measure. 2 is 2 no matter the unit of measure.

You are so wrong! You need to review your maths.

0px = 0pt = 0em = 0

1px != 1pt != 1em != 1


That's why I said I disabled it in the first post. You gotta read what I've written. Does 0 light years equal 0 inches equal 0 people in the room? Sure, the digit matches. The context is different. The error message itself is reduntant because it's trying to solve a problem that the minifier takes care of anyway. So what's the point? The misconception of trying to save bytes? It's redundant to save something that gets saved anyway further down the pipeline. Plus the error totally disregards the iterative cycle that real programmers go through. If you're testing different sizes, why keep typing out 3 characters when you can type out one. Why go from 0 to 1px, from 1px to 0. Go from 1px to 0px, and 0px to 1 px. You're only pivoting off of one character. This is why you'll find that most design is done this way. It's simply doing what's most efficient and not trying to be cute for cute sakes. Go pro an get a realtime minifier in this IDE instead of flippant mickey mouse parlor tricks like useless default, irritating, texteditor-noisy, redundant error checks like that. All I can do is offer advice from a customer perspective. If you can't listen to a user of one's product, well, why be in business?


Not if it's overriding a cascade. Anyway, I'll turn it off.


Huh? No, it's saying the px is redundant if it's 0, meaning 0px = 0pt = 0em (etc..) 0 is 0, no matter the unit of measure.


Andriy is definitely correct :)


If your more specific delcaration's value is 0px and the more general is 0px it's the same. If they are 1px, it's the same. If they are 2px, it's the same. If they are 1em they are the same.
If they are 2em they are the same.  Doesn't matter what the number is, and there is nothing redundant in increasing the specificity.  This is the whole purpose and key skill of CSS. Out of the hundreds of cascades in a single httprequest, if one value matches the more general value, that is not an error.
You find me in the CSS specification where that is an error. Plus find me a use case where that inspection error is solving a problem that exists. General rule: Don't solve problems that don't exist.
I'm not sure what use case your example is going for but you would never have two different measure types in the same decleration, so it's a moot point. You would never for example do:
div { margin:1px; margin:1em } Doesn't make sense. That is redundancy, and a syntax error. If you're cascading, it doesn't matter what the more general decalaration value is, 0, 1, 2, or 3, or what type it is, px, em, or percentage. It's irrelevent and contains no side-effects.


I'm afraid you've completely missed the point of that particular message/warning.

The message means: "Because the value is 0 (ZERO), there is no real need of specifying the measure unit (px, pt, em etc) as zero is always a zero regardless of the measure unit -- that's a basic maths for you". Whether you like that inspection or not -- it's up to you (just disable it and relax). Full stop.


Skimming the net, at best it appears that 0 having units is optional, but it is NEVER required.


Well, I'm a customer and I agree with their decision. We are an intranet only site and don't use a minifier anyway.


Please sign in to leave a comment.