Collected by
Elizabeth Janson

Home Page

Values and Units

 

There are six main types of values in CSS:

  1. keywords (e.g. "pitch-range: inherit")
  2. numbers (e.g. "orphans: 3")
  3. numbers with unit identifiers (e.g. "border-width: 0.2em")
    or expressed as percentages
  4. strings (e.g. "content: 'Figure: '")
  5. functions (e.g. "background: url(http://www.w3.org/image)")
  6. special cases (e.g. "color: #F00" and "font-size: Helvetica")

Properties are the elements of a declaration that use the values you choose.
Font properties include font-family, font-style, font-variant, font-weight, font-size and line-height, and the 'coverall' font property.
The color and background-color properties are enhanced by defining background-image using background-repeat, background-attachment, and background-position.
Text includes word spacing, letter spacing, text decoration, vertical align, text transform, text align and text indent.
Box properties involve margins, padding, border widths, colors, and also may specify the height & width, float and clear features.

Each CSS property has a formal definition of what types of values it accepts which can be found in the description of the property. Most properties accepts values from several of the above types. Some properties accept space- or comma-separated lists of values.

Keywords

In the formal definition of property values, keywords appear literally. All CSS3 properties accept the keyword value "inherit". Keywords are never quoted.
For example, here is the value definition for the 'border-collapse' property:
Value: collapse | separate | inherit
For example - table { border-collapse: separate }

Numbers

Numbering systems are described in Numbered Lists Number values can either be integer or real numbers. Integer values are denoted by <integer> and real number values are denoted by <number>. Integers and numbers are specified in decimal notation only. An <integer> consists of one or more digits "0" to "9". A <number> can either be an <integer>, or it can be zero or more digits followed by a dot (.) followed by one or more digits. Both integers and real numbers may be preceded by a "-" or "+" to indicate the sign.

Measurements and positions in Cascading Style Sheets (CSS) properties are indicated in length units. Internet Explorer supports two types of length units: relative and absolute.
Note that many properties that allow an integer or real number as a value actually restrict the value to some range, often to a non-negative value.

A relative length unit specifies a length in relation to another length property. Relative length units scale better from one output device to another, such as from a monitor to a printer.

Relative length unitsem The height of the element's font.
ex The height of the letter "x" in that font.
pxPixels.
%Percentage.

An absolute length unit specifies an absolute measurement, such as inches or centimeters. Absolute length units are useful when the physical properties of the output device are known.

Absolute length units  inInches (1 inch = 2.54 centimeters).
cmCentimeters.
mm Millimeters.
ptPoints (1 point = 1/72 inches).
pcPicas (1 pica = 12 points).

Compatibility note:

While it's possible to use other units of measurement besides pixels, such as points or em's, units other than pixels may be interpreted differently in different browsers or on different platforms.
What a PC-compatible regards as "one point" is entirely different than the same measurement displayed on a Mac. Pixels are the safest way to ensure your positioning is consistent. Remember the unit - use font-size: 17px, not font-size: 17
There is one final point of note - you must never have a space between the amount and the unit

Percentages

The format of a percentage value (denoted by <percentage> in this specification) is an optional sign character ('+' or '-', with '+' being the default) immediately followed by a <number> immediately followed by '%'.

Percentage values are always relative to another value, for example a length. Each property that allows percentages also defines the value to which the percentage refers. The value may be that of another property for the same element, a property for an ancestor element, or a value of the formatting context (e.g., the width of a containing block). When a percentage value is set for a property of the root element and the percentage is defined as referring to the inherited value of some property, the resultant value is the percentage times the initial value of that property.

Example(s):

Since child elements (generally) inherit the computed values of their parent, in the following example, the children of the P element will inherit a value of 12pt for 'line-height', not the percentage value (120%):

P { font-size: 10pt }
P { line-height: 120% }  /* 120% of 'font-size' */

Strings

Strings can either be written with double quotes or with single quotes. Double quotes cannot occur inside double quotes, unless escaped (as '\"' or as '\22'). Analogously for single quotes ("\'" or "\27").

Example(s):

"this is a 'string'"
"this is a \"string\""
'this is a "string"'
'this is a \'string\''

A string cannot directly contain a newline. To include a newline in a string, use the escape "\A" (hexadecimal A is the line feed character in Unicode, but represents the generic notion of "newline" in CSS).

Functions

1. Functions may be attribute identifiers
2. Functions may be URIs
3. Counters are denoted by identifiers 'counter-increment' and 'counter-reset' properties.

Special cases

There are two common cases that fall outside the types described above: color (due to the # notation) and font families (due to missing quotes being legal)

Font families

Font families are like strings, except one may drop the quotes around them.

Colours

Review my introduction page on Colour
The 'value' part for the properties <color:> or <background-color:> can either be a keyword, a numerical RGB specification in a functional notation, or a numerical RGB specification in a hexadecimal notation.

The list of keyword color names defined in HTML 4.0, is: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow.

The browser-safe HEX colour codes have pairs of 'digits' in the order red, green, blue.
The three-digit form '#f60' is converted into the six-digit form '#ff6600' by replicating digits.

Email
CSS begins here
Back to Syntax, or on to Background panels

This page is part of Elizabeth Janson's web site

http://www.oocities.org/elizatk/index.html

My other sites are the Anglican Parish of Northern Mallee,
Tetbury residents in the Eighteenth Century
my Australian Family History and Barrie, our Family Poet.