Who's Idea Was '!important' Anyway

by M. David Peterson

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 !!important instead 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,

11 Comments

David Buxton
2006-08-08 06:41:56
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!


Asbjørn Ulsberg
2006-08-08 08:35:19
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.
M. David Peterson
2006-08-08 08:47:20
@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.



M. David Peterson
2006-08-08 08:56:51
@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.


David Håsäther
2006-08-08 12:52:23
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.


2006-08-08 12:59:54
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 =)

M. David Peterson
2006-08-08 13:08:44
@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!

Martin Payne
2006-08-09 11:42:22

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)

M. David Peterson
2006-08-09 12:01:05
>> !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


Martin Payne
2006-08-09 13:24:05

Hehe! I'm glad you like it. :o)


And good luck convincing the working group!

M. David Peterson
2006-08-09 14:39:28
>> 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... ;)