matthewbaskey
matthewbaskey

Reputation: 1037

Difference between CSS Keywords and Properties?

Someone asked me what CSS Keywords were and I was confused by this question and thought it might be some new feature of CSS3 or LESS, things that I am not really up to date on.

However after googling a bit it seems that CSS Keywords are just CSS properties such as background-color:yellow;

Am I correct?

Upvotes: 0

Views: 957

Answers (4)

Manish Kumar
Manish Kumar

Reputation: 10482

background-color:yellow

Here background-color comes under background property.See this

Upvotes: 0

BoltClock
BoltClock

Reputation: 723448

No, background-color: yellow is a declaration, not a keyword.

A keyword in CSS2.1 is nothing more than a lone identifier (i.e. a word that isn't surrounded by quotes like a string). A property is the name of the style that you're applying, so in the given declaration the property name is background-color and its value is yellow.

The identifier yellow also happens to be a keyword representing, well, the color yellow, because 'yellow' as a string is not a valid color value — when specifying names of colors they must always be keywords. In some sense you could say that a "keyword" is equivalent to an "identifier" in terms of the CSS2.1 grammar.

Other examples of keywords include auto, inherit, initial and none.

Upvotes: 5

David Storey
David Storey

Reputation: 30394

Not quite.

A keyword is a pre-defined value that can be used as the value of a CSS property, which combined become a declaration. For example, left and right are keywords that can be used with the float property. There are also other kinds of values that can be used with properties, such as length values (such as 10px or 20em for properties like width or height), strings such as "hello!" for properties such as content, and functions, such as rgba() for the color and background-color properties. Functions use round brackets to hold additional values.

See the definition of keywords at http://www.w3.org/TR/css3-values/#keywords

Upvotes: 3

govako
govako

Reputation: 61

The css keywords are the words that you can add to a css property that are inherit in css as yellow, blue, etc, and the properties are the characteristics you can change in a style...

background-color(property): yellow(keyword)

Upvotes: 1

Related Questions