Update: Martin Payne has just come up with what I feel is the most *ingenius* solution to the not ‘not important‘ dilemma…
The first time I saw
!important, I also thought it meant “unimportant”. Even though I now know how to use it, I still don’t like it much. Perhaps a double negative !unimportant would have been better, but I guess that would cause just as much confusion for people not familiar with Boolean. How about!!importantinstead then? :o)
I LOVE IT!
Anybody have a contact on the CSS WG at the W3C? I’d send them the suggestion, but I’m pretty sure that if there isn’t one already, an automatic filter to send any emails from me directly to the “Trash” folder would be created soon thereafter. ;) :D
–
Update: I got home last night running on energy reserves, so I am just getting to this planned update now. As per this same linked comment below,
@David Håsäther, Anonymous,
All *VERY* good points. Thanks!
I am literally rushing out the door, and I need to read both of your comments more thoroughly to absorb things a bit more. One thing I will add to the top of the post later tonight when I return is the fact that,
a) This was obviously something that the designers of the spec *HAD* to take into consideration when they chose to move forward with it, and as such,
b) There’s probably a pretty good reason why they chose to move forward with it.
c) I’m probably being just a little too annoyingly nit picky.
So there ya have it. :)
There are some *REALLY* good follow-up comments below from the above mentioned folks, as well as David Buxton, and Asbjørn Ulsberg. If you have a moment, taking note of their comments would be *WELL* worth the time you invest.
Thanks folks!
[Original Post]
By force of habit, when I visit any of the documents that relate to a particular standard hoping to gain further in-sight into why something is not behaving the way I think it should, I will often times find myself running through this same specification from start to finish, just to make sure that the reason behind my misunderstanding relates to the specific question at hand, instead of something else in the specification that might override the specified behavior, and therefore be the source of my misunderstanding.
I was just brushing up on a few CSS-related things as they relate to the rules of inheritance. Of course, in doing so I came to the ‘!important’ section of the Assigning property values, Cascading, and Inheritance section of the CSS2 specification.
Maybe I’m the only person on the planet who feels this way, but coming from the perspective of a hacker who’s experience with coding is built from a ‘programming language’ foundation, instead of a ‘property=value’ pseudo language such as CSS [1], when I see the ‘!’ character in front of any other character, or set of characters thereof, I immediattelly think “not important”, which for those unaware, is the standard way in most modern day programming languages to negate the object, or element, or attribute, or operator, or etc… that follows it, using this to compare two of the same previous mentioned items, using the resulting boolean value (true or false) as a way to make a decision as to what to do next.
For example,
if (a != b) then print c; else print d
would read,
if the value of ‘a’ does *not* equal the value of ‘b’, then print the value of ‘c’. If it does, print the value of ‘d’.
So, with this in mind, consider the following,
… for balance, an “!important” declaration (the keywords “!” and “important” follow the declaration) takes precedence over a normal declaration. Both author and user style sheets may contain “!important” declarations, and user “!important” rules override author “!important” rules. This CSS feature improves accessibility of documents by giving users with special requirements (large fonts, color combinations, etc.) control over presentation.
While I understand the need for, and both respect and applaud your efforts in regards to,
This CSS feature improves accessibility of documents by giving users with special requirements (large fonts, color combinations, etc.) control over presentation.
Don’t you think “Programmers Usability” is important too?
Okay, fair enough… From the perspective of a non-programmer, the presence of ‘!important’ will more than likely invoke a sense of “this is REALLY important”, but to learn the concept of boolean comparison is not what I would term a “stumbling block”, and never in my life have I heard someone state “this ‘!’ = *not* stuff is just *TOO HARD* for me to understand. I JUST DON’T GET IT!”, and as such, I have never really understood that particular argument.
Taking this a bit further, wouldn’t ‘important!’ be a bit more meaningful to this same non-programmer than would ‘!important’? That said, I recognize that from the stand point of a parser, its faster to recognize a single ‘!’ character, and understand that what follows next to be given a higher weight when determining the total specificity of any given CSS value using the [browser, author, user] stylesheet order of precedence rules. But then why the use/need of ‘important’ that follows it? Wouldn’t ‘!’ be enough to suggest that what follows is “important”, and should take precedence? What value does ‘important’ bring to the table that can not be determined by using the ‘!’ character alone? In other words, if parser speed is the reason for breaking the standard syntax for boolean comparisons, then why slow the parser down by adding the ‘important’ keyword.
Of course, maybe the point was to allow the ability to add other keywords that follow ‘!’ in future versions of the specification, but if this is the case, then why the need for the ‘!’ character at all? If we have already slowed the parser down by adding the ‘important’ keyword, then the ‘!’ character is just added baggage, of which has now just made the language more complicated for no apparent reason other than “because.”
You know, there are times where I can understand the criticisms sent Microsoft’s direction for not implementing full support for CSS 2.x (e.g. attribute selectors), and then there are times where I want to applaud them for !implementing areas of the spec that make matters more confusing rather than less.
Then again, maybe there’s something that I’m missing thats not immediattely obvious. But in and of itself, that statement should be enough to understand my point: When you design a specification who’s purpose is to make the lives of those in whom choose to use the specified technology as part of their development, easier, if the purpose for something is not immediatelly obvious, and even further, holds potential to confuse matters by breaking away from the standard and common syntax used by a significant majority of other technical specifications, you have just had the opposite of the intended effect by making things harder to understand, and more complex that they should *EVER* be.
Just my two cents.
Thanks for reading. :)
—
[1] To all of you who are about to enter in “I hate you, you suck!” comments fan mail, please don’t do so on the basis of your belief that CSS *”IS TO A PROGRAMMING LANGUAGE!”*, err, I mean “!IS TO A PROGRAMMING LANGUAGE”.
For the record, no it’s not. CSS is a compact syntax that allows you to select elements within an (([X] and/or [HT])ML) document, and either set or change the setting of the value of the specified element. (e.g. a {color:red; text-decoration:none}). Nothing more, nothing less. Of course there are those who will argue that because you can dynamically change the values of a given property, and the fact that, for example, {display:none} will make any given element automagically “disappear”, that this alone means it is a programming language because you can
a) select items based on a certain criteria
b) change the values of the properties of these same selected items to something else.
Firstly, with CSS, no you can’t. To “change things” you need to use a programming language such as ECMAScript (Javascript).
Secondly, what you are really dealing with is Dynamic HTML (DHTML), which allows the ability to handle captured events that take place within a document (e.g. onmouseover), to then change the value of any given property, of any given element. Of course at this level, you have completely bypassed CSS all together, and gone directly to the Document Object Model, who’s spec contains a section termed ECMAScript language bindings, which will then point you directly to the ECMAScript language spec for programmatically dealing with things such as the aforementioned DHTML event model (although this is never explicitly stated. Ahhh… the nature of specification development politics. You gotta love it! No you don’t.)
Disclaimer: That last bit regarding the exclusion of any reference to DHTML having to do with politics is *MY OWN OPINION*, and is more than likely wrong. I’ve just never understood, completely, the reason for the lack of mention of the DHTML events model (designed by Scott Isaacs and built (at least, from what I understand) by the IE4 team headed by Adam Bosworth, who at the time (obviously) was with Microsoft.) inside *ANY* of the DOM specifications (I promise, I’ve looked through them all), or for that matter, other than random references here and there in various presentations and various “under development” specifications, anywhere on the W3C in any sort of official capacity.
Microsoft, did you forget to pay your W3C dues? If you did, that would certainly help explain things a bit better. ;) :D
While I realize it would be embarrasing, if you’re a bit short on cash, you know all you have to do is ask, right? ;)
You’re welcome :D


You can change styling of an element using CSS without recourse to Javascript. For example, CSS rules as follows changes the display of a link.
a { text-decoration:none; }
a:hover { text-decoration:underline; }
Dynamical styling (changing things) and no Javascript to be seen!
It is not what follows after !important that is important, it's what precedes it that is. And although I agree that a single exclamation mark would do the job as good as !important does, a single exclamation mark is harder to notice.
@David,
While I do appreciate your point, please also consider the fact that what you are refering to, in CSS terms, is called a pseudo-class. The name is a bit mis-leading, however, but not the pseudo portion, and instead the class portion.
As you are obviously well aware, to select an element within the document tree, you would use a selector (the element name, id, class name, combination thereof, and so forth). Pseudo-classes were designed to include the ability to refer to the state or position of any given element within the document tree. So the usage of the term 'class' doesn't truly reflect what these selectors represent, as in reality what they truly represent is that of an event taking place. However, if you look at the list of available pseudo-classes,
* :first-child
* :link
* :visited
* :hover
* :active
* :focus
* :lang(n)
Using the term 'event' really doesn't apply all that well, as when an event takes place (e.g. a mouse moves over a particular area on the screen in which maps to an element contained the document tree, a user clicks a link, etc...) a message is fired off, which then 'bubbles-up' the element hierarchy until it is handled by the various listeners in which are listening for any particular event, or until it reaches the top of the document. So in the case of :hover, then event would make sense, but thats pretty much it, as the rest represent state or position of a given element. Even :focus doesn't truly represent an event taking place, although one could arguably suggest that it does.
Of course, this is really not the point. Instead, my point is pretty simple: If you look at this same list of pseudo-classes,
* :first-child
* :link
* :visited
* :hover
* :active
* :focus
* :lang(n)
You should notice right off that these are limited to a tiny subset of possible positions, state, and events that transpire within the confines of an XML, XHTML, and/or HTML document. So while its *possible* to create scriptless dynamic effects using just CSS, you are limited to only this tiny subset of however you want to term this list of CSS selectors.
Furthermore, even though there are *some* cases in which you can get away with using scriptless CSS, creating some cool effects as a result, the reality is that you are still only changing the value of a given property. In other words, there is no way to programmatically process the contained data beyond that in which can be described using the pre-defined set of CSS properties.
So, for example, what if I wanted to parse the string of text contained within a given element in my document, look for certain occurences of words contained within a specified dictionary, adding a 'smarttag' to this text that, when the mouse hovered over this text, would display the associated text for this word that is contained in this same dictionary. Could I do this with CSS?
Of course not. Things of this nature do not fit within the confines of what CSS was designed for. And thats not a bad thing! For what CSS *WAS* designed for, its FANTASTIC!
But just because there are a few edge cases where CSS can handle a subset of dynamic effects without the needs for scripts, doesn't suddenly make it a programming language.
@Asbjørn,
>> It is not what follows after !important that is important, it's what precedes it that is.
Thanks for the clarification! Obviously you can see just how often I use this portion of the CSS spec :D
>> And although I agree that a single exclamation mark would do the job as good as !important does, a single exclamation mark is harder to notice.
I agree. But why then is there a need for the exclamation point in the first place? In and of itself, this is my annoyance... The leading exclamation point goes against what is pretty much standard usage in every other technology specification. If they chose to put the exclamation point at the end to help make it easier for the user to realize this was a way to emphasize that this took precedence over other matches, that would have worked just as well, and there wouldn't be any sort of confusion as to whether this was a statement of importance, or a statement of non-importance.
It was probably chosen to differentiate it from property values. "important" could very well be a value for some property in a future version of CSS. If so, e.g. shorthands could be made ambiguous. Consider:
selector {
future-property: blue important; /* shorthand */
}
Is "important" a value, or is it the same as the current "!important"?
"!" alone could probably have been used, but the disadvantage, as already said, is that it's not really visible. Also, as you say in your post, there may be other keywords added in the future.
I do agree that the "!" is confusing at first though.
My first reaction to !important was that it reminded me of Spanish =)
¡importante!
I'm not going to presume to speak for the spec designers, either, but it's worth reminding ourselves that (as you point out) the identifier is not a pseudo class, and the documents you're styling could have elements called important or classes called important, and this pretty much goes for any other purely alphabetic keyword one might choose to generate the cascading behaviour represented by !important. No programming language I'm familiar with has single language keywords.
So presumably a keyword along with a little bit of extra syntax was needed. The exclamation point indicates notability, and the overlap of serious CSSistas and serious programmers is small. Maybe this says something about how serious a programmer I am, or about how much Perl has affected my brain, but !important bothers me not one bit =)
@David Håsäther, Anonymous,
All *VERY* good points. Thanks!
I am literally rushing out the door, and I need to read both of your comments more thoroughly to absorb things a bit more. One thing I will add to the top of the post later tonight when I return is the fact that,
a) This was obviously something that the designers of the spec *HAD* to take into consideration when they chose to move forward with it, and as such,
b) There's probably a pretty good reason why they chose to move forward with it.
c) I'm probably being just a little too annoyingly nit picky.
With that, I will come back to this in about 6 hours or so and update accordingly.
Thanks to all of you for taking the time to comment! Your time is *MUCH* appreciated!
The first time I saw !important, I also thought it meant "unimportant". Even though I now know how to use it, I still don't like it much. Perhaps a double negative !unimportant would have been better, but I guess that would cause just as much confusion for people not familiar with Boolean. How about !!important instead then? :o)
>> !unimportant
I LOVE IT! :D
Actually, I do agree that it probably wouldn't fly for most folks, but,
!!important
Now *THAT* would make sense! It would allow us hacker types in whom have the concept of a preceding exclamation point negating (in boolean terms for those of you that might interpret negate to mean a negative integer) what follows to make sense of the fact that it means what it is attempting to represent, and to a non-hacker type it would just look like a way of marking something as Really, REALLY important. :D
Now we just have to convince the W3C CSS working group. :D
Hehe! I'm glad you like it. :o)
And good luck convincing the working group!
>> And good luck convincing the working group!
Thanks! Obviously luck is *exactly* what I would need, although cold hard cash might do the trick, and in fact my guess is that the two are often mistaken for each other in the real world :D
Or I could just save my money and get over it.
Hmmm... Decisions, decisions... ;)