CSS Units
Length Units
A length value is formed by an optional + or -, followed by a number, followed by a two-letter abbreviation that indicates the unit. There are no spaces in a length value; e.g., 1.3 em is not a valid length value, but 1.3em is valid. A length of 0 does not require the two-letter unit identifier.
Both relative and absolute length units are supported in CSS1. Relative units give a length relative to another length property, and are preferred since they will better adjust to different media. The following relative units are available:
- em (ems, the height of the element's font)
- ex (x-height, the height of the letter "x")
- px (pixels, relative to the canvas resolution)
Absolute length units are highly dependent on the output medium, and so are less useful than relative units. The following absolute units are available:
- in (inches; 1in=2.54cm)
- cm (centimeters; 1cm=10mm)
- mm (millimeters)
- pt (points; 1pt=1/72in)
- pc (picas; 1pc=12pt)
Percentage Units
A percentage value is formed by an optional + or -, followed by a number, followed by %. There are no spaces in a percentage value.
Percentage values are relative to other values, as defined for each property. Most often the percentage value is relative to the element's font size.
Color Units
A color value is a keyword or a numerical RGB specification.
The 16 keywords are taken from the Windows VGA palette: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow.
RGB colors are given in one of four ways:
- #rrggbb (e.g., #00cc00)
- #rgb (e.g., #0c0)
- rgb(x,x,x) where x is an integer between 0 and 255 inclusive (e.g., rgb(0,204,0))
- rgb(y%,y%,y%) where y is a number between 0.0 and 100.0 inclusive (e.g., rgb(0%,80%,0%))
The examples above all specify the same color.
Douglas R. Jacobson has also developed a handy quick reference RGB Color Chart (61 kB).
URLs
A URL value is given by url(foo), where foo is the URL. The URL may be optionally quoted with either single (') or double (") quotes and may contain whitespace before or after the (optionally quoted) URL.
Parentheses, commas, spaces, single quotes, or double quotes in the URL must be escaped with a backslash. Partial URLs are interpreted relative to the style sheet source, not to the HTML source.
Note that Netscape Navigator 4.x incorrectly interprets partial URLs relative to the HTML source. Given this bug, authors may wish to use full URLs where possible.
Examples:
BODY { background: url(stripe.gif) }
BODY { background: url(http://www.htmlhelp.com/stripe.gif) }
BODY { background: url( stripe.gif ) }
BODY { background: url("stripe.gif") }
BODY { background: url(\"Ulalume\".png) } /* quotes in URL escaped */
- CSS Menus
- CSS Introduction
- CSS Reference
- 1 About the CSS2 Specification
- 2 Introduction to CSS2
- 3 Conformance: Requirements and Recommendations
- 4 CSS2 syntax and basic data types
- 5 Selectors
- 6 Assigning property values, Cascading, and Inheritance
- 7 Media types
- 8 Box model
- 9 Visual formatting model
- 9.1 Introduction to the visual formatting model
- 9.2 Controlling box generation
- 9.3 Positioning schemes
- 9.4 Normal flow
- 9.5 Floats
- 9.6 Absolute positioning
- 9.7 Relationships between 'display', 'position', and 'float'
- 9.8 Comparison of normal flow, floats, and absolute positioning
- 9.9 Layered presentation
- 9.10 Text direction: the 'direction' and 'unicode-bidi' properties
- 10 Visual formatting model details
- 10.1 Definition of "containing block"
- 10.2 Content width: the 'width' property
- 10.3 Computing widths and margins
- 10.4 Minimum and maximum widths: 'min-width' and 'max-width'
- 10.5 Content height: the 'height' property
- 10.6 Computing heights and margins
- 10.7 Minimum and maximum heights: 'min-height' and 'max-height'
- 10.8 Line height calculations: the 'line-height' and 'vertical-align' properties
- 11 Visual effects
- 12 Generated content, automatic numbering, and lists
- 13 Paged media
- 14 Colors and Backgrounds
- 15 Fonts
- 16 Text
- 17 Tables
- 18 User interface
- 19 Aural style sheets
- 19.1 Introduction to aural style sheets
- 19.2 Volume properties: 'volume'
- 19.3 Speaking properties: 'speak'
- 19.4 Pause properties: 'pause-before', 'pause-after', and 'pause'
- 19.5 Cue properties: 'cue-before', 'cue-after', and 'cue'
- 19.6 Mixing properties: 'play-during'
- 19.7 Spatial properties: 'azimuth' and 'elevation'
- 19.8 Voice characteristic properties: 'speech-rate', 'voice-family', 'pitch', 'pitch-range', 'stress', and 'richness'
- 19.9 Speech properties: 'speak-punctuation' and 'speak-numeral'
- Appendix A. A sample style sheet for HTML 4.0
- Appendix B. Changes from CSS1
- Appendix C. Implementation and performance notes for fonts
- Appendix D. The grammar of CSS2
- Appendix E. References
- Appendix F. Property index
- Appendix G. Descriptor index
- Appendix H. Index
