For example, in JavaScript, !important means ‘not important’. In CSS, it means ‘this is important’.
Are there languages other than CSS where an exclamation mark is used for affirmation rather than negation? Why was the ‘!’ chosen in CSS?
EDIT
I don’t know if it’s a coincidence, but ! is the earliest non-system and non-whitespace character in the ASCII table (at #32). In terms of parsing, would that make it quicker?
!is more of an escape character than it is an operator. It is part ofimportant, rather than a separate piece (e.g. in JavaScript I’d see this as!andsomevar, whereas in CSS I see this as!important). So, it isn’t so much affirmation as you put it; it just so happens to be the character they chose to throw in front of the keywordimportant.Also, in non-programming languages,
!is often used to draw attention to something, although it is often accompanied by some other sort of shape/symbol as well (e.g. ⚠), and this is likely the reason why!was chosen. It may be helpful to see it asimportant!or¡important!(!importantis just easier to parse and type than the alternatives).Edit: As noted by @mike-samuel: “The lexical scanner section of the CSS2.1 grammar spec lists
!importantas a single token ("!"({w}|{comment})*{I}{M}{P}{O}{R}{T}{A}{N}{T} {return IMPORTANT_SYM;}) although it does allow whitespace and comments between the!andimportant.”