<pre class='metadata'>
Title: Cascading Style Sheets (CSS) Level 2
Shortname: css2
Level:
Status: ED
Work Status: Stable
Group: csswg
ED: https://drafts.csswg.org/css2/
TR: https://www.w3.org/TR/CSS2/
Previous version: https://www.w3.org/TR/2011/REC-CSS2-20110607/
Previous version: https://www.w3.org/TR/2008/REC-CSS2-20080411/
Editor: Sam Sneddon, https://gsnedders.com
Editor: Tantek &Ccedil;elik, tantek@cs.stanford.edu
Former Editor: Editor: Bert Bos, W3C, mailto:bert@w3.org, w3cid 3343
Former Editor: Elika J. Etemad / fantasai, Apple, http://fantasai.inkedblade.net/contact, w3cid 35400
Former Editor: Ian Hickson, ian@hixie.ch
Former Editor: H&aring;kon Wium Lie, Opera Software, howcome@opera.com
WPT Display: inline
Abstract:
  This specification defines Cascading Style Sheets level&nbsp;2 (CSS&nbsp;2)
  revision&nbsp;2 (CSS&nbsp;2.2). CSS is a style sheet language
  that allows
  authors and users to attach style (e.g., fonts and spacing) to
  structured documents (e.g., HTML documents and XML
  applications). By separating the presentation style of documents from
  the content of documents, CSS simplifies Web authoring and
  site maintenance.

  It supports media-specific style sheets so that authors may tailor the
  presentation of their documents to visual browsers, aural devices,
  printers, braille devices, handheld devices, etc. It also supports
  content positioning, table layout, features for internationalization
  and some properties related to user interface.

  See [[#app-changes]] for changes from CSS&nbsp;2.1,
  and <a href="/TR/2011/REC-CSS21-2011-06-07/changes.html">appendix C of CSS&nbsp;2.1
  for changes from CSS2&nbsp;(1998)</a>.
  Note that several CSS2&nbsp;(1998) features
  were removed from CSS&nbsp;2 in CSS&nbsp;2.1 due to lack of implementations;
  specifications that wish to reference those features
  should reference the latest applicable CSS module, see [[CSS]].

Required IDs: abs-non-replaced-height, abs-non-replaced-width, absolutely-positioned
Required IDs: absolute-positioning, absrel-units, abs-replaced-height, abs-replaced-width, abstract
Required IDs: acknowledgements, actual-value, addressing, adjacent-selectors, algorithm, alignment-prop
Required IDs: all-media-group, allowed-page-breaks, almost, ancestor, angles, anonymous
Required IDs: anonymous-block-level, anonymous-boxes, applies-to, at-import, at-media-rule, at-rules
Required IDs: attribute, attribute-selectors, audio-media-group, aural-intro, aural-media-group, aural-tables
Required IDs: author, authoring, AutoNumber2, auto-table-layout, background, background-properties
Required IDs: baseline-below, before-after-content, before-and-after, best-page-breaks, bfc-next-to-float
Required IDs: bidi, bidi-box-model, bitmap-media-group, block, block-boxes, block-container-box
Required IDs: block-formatting, block-level, block-replaced-width, block-root-margin, blockwidth
Required IDs: border-color-properties, border-conflict-resolution, border-edge, border-properties, borders
Required IDs: border-shorthand-properties, border-style-properties, border-width-properties, box-border-area
Required IDs: box-content-area, box-dimensions, box-gen, box-margin-area, box-model, box-padding-area
Required IDs: break-inside, canvas, caps-prop, caption-position, cascade, cascading-order, changes, characters
Required IDs: charset, child, child-selectors, choose-position, clarifications, class-html, clearance
Required IDs: clipping, collapsing-borders, collapsing-margins, colors, color-units, column-alignment, columns
Required IDs: combinator, comment, comments, comp-abspos, comparison, comp-float, comp-normal-flow
Required IDs: comp-relpos, computed-defs, computed-value, Computing_heights_and_margins
Required IDs: Computing_widths_and_margins, conformance, conformance-term, containing-block
Required IDs: containing-block-details, content, content-edge, content-height, content-width
Required IDs: continuous-media-group, conventions, counter, counters, counter-styles, ctrlchars, cue-props
Required IDs: cursive-def, cursor-props, declaration, decoration, default-attrs, default-style-sheet
Required IDs: defined-to-exist, defs, descendant, descendant-selectors, design-principles, direction
Required IDs: display-prop, dis-pos-flo, doc-language, doclanguage, doctree, dynamic-effects, dynamic-outlines
Required IDs: dynamic-pseudo-classes, each-box, egbidiwscollapse, element, Emacspeak, empty, empty-cells
Required IDs: em-width, errors, escaped-characters, escaping, ex, fantasy-def, first-child
Required IDs: first-formatted-line, first-letter, first-line, first-line-pseudo, fixed-positioning
Required IDs: fixed-table-layout, float-position, float-replaced-width, float-rules, floats, float-width
Required IDs: flow-control, following, font-boldness, font-family-prop, font-shorthand, fonts-intro
Required IDs: font-size-props, font-styling, forced, formatting-structure, frequencies, generated-text
Required IDs: generic-font-families, grammar, grid-media-group, grouping, height-layout, html-tutorial
Required IDs: id-selectors, ignore, illegal, illegalvalues, images-and-longdesc, img-anon-block, img-bach1
Required IDs: img-bach2, img-bg-repeat, img-boxdim, img-boxdimeg, img-cell-align, img-changebar, img-clip
Required IDs: img-CSStbl3, img-doctree, img-first-letter, img-first-letter2, img-float2p, img-floatclear
Required IDs: img-floateg, img-flow-absolute, img-flow-abs-rel, img-flow-clear, img-flow-clear2
Required IDs: img-flow-float, img-flow-generic, img-flow-relative, img-flow-static, img-frame
Required IDs: img-inline-layout, img-list-inout, img-overflow1, img-overflow2, img-page-info, img-pixel1
Required IDs: img-pixel2, img-table1, img-table-overlap, img-tbl-border-conflict, img-tbl-empty
Required IDs: img-tbl-layers, img-tbl-spacing, img-tbl-width, important-rules, indentation-prop, informative, inheritance
Required IDs: inherited-prop, initial-containing-block, initial-value, inlineblock-replaced-width
Required IDs: inlineblock-width, inline-box, inline-boxes, inline-box-height, inline-formatting, inline-level
Required IDs: inline-non-replaced, inline-replaced-height, inline-replaced-width, inline-width, inner-edge
Required IDs: interactive-media-group, internal, internal-table-element, intrinsic, keywords, known-errors
Required IDs: lang, layers, leading, length-units, line-box, line-height, lining-striking-props
Required IDs: link-pseudo-classes, lists, list-style, magnification, margin-edge, margin-properties
Required IDs: matching-attrs, media-applies, media-groups, media-intro, media-sheets, media-types
Required IDs: message-entity, min-max-heights, min-max-widths, mixing-props, model, monospace-def
Required IDs: mpb-examples, multi-font-inline-height, new, normal-block, normal-flow, normative
Required IDs: notes-and-examples, numbers, organization, outer-edge, outline-focus, outlines, outside-page-box
Required IDs: overflow, overflow-clipping, overlapping-example, padding-edge, padding-properties, page-area
Required IDs: page-box, page-break-props, page-breaks, page-cascade, page-context, paged-media-group
Required IDs: page-intro, page-margins, page-selectors, painting-order, parent, parsing-errors
Required IDs: pattern-matching, pause-props, percentage-units, percentage-wrt, phantom-line-box
Required IDs: positioned-element, positioning-scheme, position-props, preceding, preshint, principal-box
Required IDs: processing-model, propdef-azimuth, propdef-background, propdef-background-attachment
Required IDs: propdef-background-color, propdef-background-image, propdef-background-position
Required IDs: propdef-background-repeat, propdef-border, propdef-border-bottom, propdef-border-bottom-color
Required IDs: propdef-border-bottom-style, propdef-border-bottom-width, propdef-border-collapse
Required IDs: propdef-border-color, propdef-border-left, propdef-border-left-color, propdef-border-left-style
Required IDs: propdef-border-left-width, propdef-border-right, propdef-border-right-color
Required IDs: propdef-border-right-style, propdef-border-right-width, propdef-border-spacing
Required IDs: propdef-border-style, propdef-border-top, propdef-border-top-color, propdef-border-top-style
Required IDs: propdef-border-top-width, propdef-border-width, propdef-bottom, propdef-caption-side
Required IDs: propdef-clear, propdef-clip, propdef-color, propdef-content, propdef-counter-increment
Required IDs: propdef-counter-reset, propdef-cue, propdef-cue-after, propdef-cue-before, propdef-cursor
Required IDs: propdef-direction, propdef-display, propdef-elevation, propdef-empty-cells, propdef-float
Required IDs: propdef-font, propdef-font-family, propdef-font-size, propdef-font-style, propdef-font-variant
Required IDs: propdef-font-weight, propdef-height, propdef-left, propdef-letter-spacing, propdef-line-height
Required IDs: propdef-list-style, propdef-list-style-image, propdef-list-style-position
Required IDs: propdef-list-style-type, propdef-margin, propdef-margin-bottom, propdef-margin-left
Required IDs: propdef-margin-right, propdef-margin-top, propdef-max-height, propdef-max-width
Required IDs: propdef-min-height, propdef-min-width, propdef-orphans, propdef-outline, propdef-outline-color
Required IDs: propdef-outline-style, propdef-outline-width, propdef-overflow, propdef-padding
Required IDs: propdef-padding-bottom, propdef-padding-left, propdef-padding-right, propdef-padding-top
Required IDs: propdef-page-break-after, propdef-page-break-before, propdef-page-break-inside, propdef-pause
Required IDs: propdef-pause-after, propdef-pause-before, propdef-pitch, propdef-pitch-range
Required IDs: propdef-play-during, propdef-position, propdef-property-name, propdef-quotes, propdef-richness
Required IDs: propdef-right, propdef-speak, propdef-speak-header, propdef-speak-numeral
Required IDs: propdef-speak-punctuation, propdef-speech-rate, propdef-stress, propdef-table-layout
Required IDs: propdef-text-align, propdef-text-decoration, propdef-text-indent, propdef-text-transform
Required IDs: propdef-top, propdef-unicode-bidi, propdef-vertical-align, propdef-visibility
Required IDs: propdef-voice-family, propdef-volume, propdef-white-space, propdef-widows, propdef-width
Required IDs: propdef-word-spacing, propdef-z-index, properties, property, property-defs, pseudo-classes
Required IDs: pseudo-class-selectors, pseudo-elements, pseudo-element-selectors, q1.0, q10.0, q11.0, q14.0
Required IDs: q15.0, q16.0, q17.0, q18.0, q19.0, q2.0, q20.0, q22.0, q23.0, q24.0, q25.0, q25.4, q26.0, q27.0
Required IDs: q3.0, q4, q4.0, q5.0, q6.0, q7.0, q9.0, quotes, quotes-insert, quotes-specify, reading, relative-positioning, rendered-content
Required IDs: replaced-element, root, root-height, rule-sets, run-in, sample, sans-serif-def, scanner, scope
Required IDs: selector-syntax, separated-borders, serif-def, shorthand, shrink-to-fit-float, sibling
Required IDs: simple-selector, small-caps, source-document, spacing-props, spatial-props, speak-headers
Required IDs: speaking-props, specificity, specified-value, speech-media-group, speech-props, stacking-defs
Required IDs: stacking-notes, stack-level, statements, static-media-group, static-position, strings
Required IDs: strut, style-sheet, sTypoAscender, subject, syntax, system-colors, system-fonts
Required IDs: table-border-styles, table-display, table-layers, table-layout, tables-intro, tabular-container
Required IDs: tactile-media-group, TanteksColorDiagram20020613, text-css, the-canvas, the-height-property
Required IDs: the-page, the-width-property, times, title, toc, tokenization, tokenizer-diffs, type-selectors
Required IDs: ua, undisplayed-counters, unexpected-eof, universal-selector, unsupported-values, uri
Required IDs: used-value, usedValue, user, user-agent, valid-style-sheet, value-def-absolute-size
Required IDs: value-def-angle, value-def-armenian, value-def-block, value-def-bo-none, value-def-border-style
Required IDs: value-def-border-width, value-def-bottom, value-def-circle, value-def-close-quote
Required IDs: value-def-color, value-def-counter, value-def-dashed, value-def-decimal
Required IDs: value-def-decimal-leading-zero, value-def-disc, value-def-dotted, value-def-double
Required IDs: value-def-family-name, value-def-frequency, value-def-generic-family, value-def-generic-voice
Required IDs: value-def-georgian, value-def-groove, value-def-hidden, value-def-identifier, value-def-inherit
Required IDs: value-def-inline, value-def-inline-block, value-def-inline-table, value-def-inset
Required IDs: value-def-integer, value-def-invert, value-def-left, value-def-length, value-def-list-item
Required IDs: value-def-lower-greek, value-def-lower-latin, value-def-lower-roman, value-def-margin-width
Required IDs: value-def-no-close-quote, value-def-no-open-quote, value-def-number, value-def-open-quote
Required IDs: value-def-outset, value-def-padding-width, value-def-percentage, value-def-relative-size
Required IDs: value-def-ridge, value-def-right, value-defs, value-def-shape, value-def-solid
Required IDs: value-def-specific-voice, value-def-square, value-def-string, value-def-table
Required IDs: value-def-table-caption, value-def-table-cell, value-def-table-column
Required IDs: value-def-table-column-group, value-def-table-footer-group, value-def-table-header-group
Required IDs: value-def-table-row, value-def-table-row-group, value-def-time, value-def-top
Required IDs: value-def-upper-latin, value-def-upper-roman, value-def-uri, values, value-stages
Required IDs: vendor-keyword-history, vendor-keywords, viewport, visibility, visual-media-group
Required IDs: visual-model-intro, voice-char-props, volume-props, whitespace, white-space-model
Required IDs: white-space-prop, width-constraints, width-layout, xml-tutorial, z-index
</pre>

<pre class=biblio>
{
    "CSS20": {
        "aliasOf": "CSS2-19980512"
    }
}
</pre>
<style>
 span.colorsquare { float:left; width:5em; height:3em; text-align:center; padding:1.2em 0 .8em }
 span.colorname { font-weight:bold }
 div.colordiagram { width:25em; height:20em; margin:1em auto; font-family:Verdana,sans-serif; font-size:12px }
 div.diagramrow { height:5em }
blockquote.math {display: table}
blockquote.math p {display: table-row}
blockquote.math span {display: table-cell; padding-right: 0.3em}
blockquote.math span:first-child {text-align: right}
.egbidiwsaA,.egbidiwsbB,.egbidiwsaB,.egbidiwsbC
{ white-space:pre;font-size:80%;font-family:monospace; vertical-align:2px; margin:1px }
.egbidiwsaA { background:lime;padding:2px; }
.egbidiwsbB { border:2px solid blue }
.egbidiwsaB { background:yellow;border:2px dotted white }
.egbidiwsbC { border:2px dotted red }
pre.ascii-art {
  display: table; /* shrinkwrap */
  margin: 1em auto;
  line-height: normal;
}
</style>

<h2 id="about"><span id="q1.0">About the CSS&nbsp;2.2 Specification</span></h2>

<h3 id="css2.2-v-css2">CSS&nbsp;2.2 vs CSS&nbsp;2</h3>

<p>The CSS community has gained significant experience with the CSS2
specification since it became a recommendation in 1998. Errors in the
CSS2 specification [[CSS20]] have subsequently been corrected in the first
revised edition [[CSS21]] in 2011, but new errata were necessary.

<p>While many of the issues will be addressed by the upcoming CSS3
specifications, the current state of affairs hinders the
implementation and interoperability of CSS2. The CSS&nbsp;2.2 specification
attempts to address this situation by:

<ul>
<li>Maintaining compatibility with those portions of CSS2 that are
widely accepted and implemented.

<li>Incorporating all published CSS2 errata.

<li>Where implementations overwhelmingly differ from the CSS2
specification, modifying the specification to be in accordance with
generally accepted practice.

<li>Removing CSS2 features which, by virtue of not having been
implemented, have been rejected by the CSS community. CSS&nbsp;2.2 aims to
reflect what CSS features are reasonably widely implemented for HTML
and XML languages in general (rather than <em>only</em> for a
particular XML language, or <em>only</em> for HTML).

<li>Removing CSS2 features that will be obsoleted by CSS3, thus
encouraging adoption of the proposed CSS3 features in their place.

<li>Adding a (very) small number of <a href="#new">new
property values,</a> when implementation experience has shown that
they are needed for implementing CSS2.
</ul>

<p>Thus, while it is not the case that a CSS2 style sheet is
necessarily forwards-compatible with CSS&nbsp;2.2, it is the case that a
style sheet restricting itself to CSS&nbsp;2.2 features is more likely to
find a compliant user agent today and to preserve forwards
compatibility in the future. While breaking forward compatibility is
not desirable, we believe the advantages to the revisions in CSS&nbsp;2.2
are worthwhile.

<p>CSS&nbsp;2.2 is derived from and is intended to replace
CSS&nbsp;2.1 and CSS2. Some parts of CSS2 are unchanged in
CSS&nbsp;2.2, some parts have been
altered, and some parts removed. The removed portions may be used in a
future CSS3 specification. Future specs should refer to CSS&nbsp;2.2
(unless they need features from CSS2 which have been dropped in
CSS&nbsp;2.2, and then they should only reference CSS2 for those
features, or preferably reference such feature(s) in the respective
CSS3 Module that includes those feature(s)).

<section class="non-normative">
<h3 id="reading">Reading the specification</h3>

<p>This section is non-normative.

<p>This specification has been written with two types of readers in
mind: CSS authors and CSS implementors. We hope the specification will
provide authors with the tools they need to write efficient,
attractive, and accessible documents, without overexposing them to
CSS's implementation details. Implementors, however, should find all
they need to build <a href="#conformance">conforming user
agents</a>.

The specification begins with a general presentation of CSS and
becomes more and more technical and specific towards the end. For
quick access to information, a general table of contents,
specific tables of contents at the beginning of each section,
and an index provide easy navigation, in both the electronic
and printed versions.

<p>The specification has been written with two modes of presentation
in mind: electronic and printed. Although the two presentations will
no doubt be similar, readers will find some differences. For example,
links will not work in the printed version (obviously), and page
numbers will not appear in the electronic version. In case of a
discrepancy, the electronic version is considered the authoritative
version of the document.
</section>

<section class="non-normative">
<h3 id="organization">How the specification is organized</h3>

<p>This section is non-normative.

<p>The specification is organized into the following sections:

<dl>

<dt><strong>Section 2: An introduction to CSS&nbsp;2</strong>

<dd>The introduction includes a brief tutorial on CSS&nbsp;2 and
a discussion of design principles behind CSS&nbsp;2.

<dt><strong>Sections 3 - 18: CSS&nbsp;2 reference manual.</strong>

<dd>The bulk of the reference manual consists of the CSS&nbsp;2 language
reference. This reference defines what may go into a CSS&nbsp;2 style sheet
(syntax, properties, property values) and how user agents must
interpret these style sheets in order to claim <a href="#conformance">conformance</a>.


<dt><strong>Appendixes:</strong>

<dd>Appendixes contain information about <a href="#html-stylesheet">a
sample style sheet for HTML 4</a>, <a href="#app-changes">changes
from CSS&nbsp;2.1</a>, <a href="#app-grammar">the grammar of CSS&nbsp;2</a>,
a list of normative and informative <a href="#references">references</a>,
and two indexes: one for
<a href="#property-index">properties</a> and one
<a href="#index">general index</a>.
</dl>
</section>

<h3 id="conventions">Conventions</h3>

<h4 id="doc-language">Document language elements
and attributes</h4>

<ul>
<li>CSS property and pseudo-class names are delimited
by single quotes.
<li>CSS values are delimited by single quotes.
<li>Document language attribute names are in lowercase letters
and delimited by double quotes.
</ul>

<h4 id="property-defs">CSS property definitions</h4>
<p>Each CSS property definition begins with a summary of key
information that resembles the following:</p>

<xmp class="propdef">
Name: property-name
Value: legal values &amp; syntax
Initial: initial value
Applies to: elements this property applies to
Inherited: whether the property is inherited
Percentages: how percentage values are interpreted
Media: which media groups the property applies to
Computed Value: how to compute the computed value
Animation type: how the property is animated
</xmp>



<h5 id="value-defs">Value</h5>

<p>This part specifies the set of valid values for the property whose
name is 'property-name'. A property
value can have one or more components. Component value types are designated
in several ways:

<ol>
<li> <span id="syndata.html#keywords">keyword</span> values (e.g., auto,
disc, etc.)

<li> basic data types, which appear between "&lt;" and "&gt;" (e.g.,
<<length>>, <<percentage>>, etc.). In the electronic version
of the document, each instance of a basic data type links to its
definition.

<li> types that have the same range of values as a property bearing
the same name (e.g., &lt;'border-width'&gt;
&lt;'background-attachment'&gt;, etc.).  In this case, the type name
is the property name (complete with quotes) between "&lt;" and "&gt;"
(e.g., &lt;'border-width'&gt;).  Such a type does <strong>not</strong>
include the value ''inherit''.  In the electronic version of the
document, each instance of this type of non-terminal links to the
corresponding property definition.


<li> non-terminals that do not share the same name as a property. In this
case, the non-terminal name appears between "&lt;" and "&gt;", as in
&lt;border-width&gt;.  Notice the distinction between
&lt;border-width&gt; and &lt;'border-width'&gt;; the latter is defined
in terms of the former. The definition of a non-terminal is located
near its first appearance in the specification.  In the electronic
version of the document, each instance of this type of value links to
the corresponding value definition.
</ol>

<p>Other words in these definitions are keywords that must appear
literally, without quotes (e.g., red). The slash (/) and the comma (<dfn dfn-type="grammar" data-export="" id="comb-comma">,</dfn>)
must also appear literally.

<p>Component values may be arranged into property values as follows:</p>

<ul>
<li>Several juxtaposed words mean that all of them must occur, in the
given order.
<li>A bar (<dfn dfn-type="grammar" data-export="" id="comb-one">|</dfn>) separates two or more alternatives:
exactly one of them must occur.
<li>A double bar (<dfn dfn-type="grammar" data-export="" id="comb-any">||</dfn>) separates
two or more options: one or more of them must occur, in any order.
<li>A double ampersand (<dfn dfn-type="grammar" data-export="" id="comb-all">&amp;&amp;</dfn>) separates two or more components, all of which
must occur, in any order.
<li>Brackets ([&nbsp;]) are for grouping.
</ul>

<p>Juxtaposition is stronger than the double ampersand, the double
ampersand is stronger than the double bar, and the double bar
is stronger than the bar. Thus, the following lines are equivalent:
<pre>
    a b   |   c ||   d &amp;&amp;   e f
  [ a b ] | [ c || [ d &amp;&amp; [ e f ]]]
</pre>

<p> Every type, keyword, or bracketed group may be followed by one of
the following modifiers:</p>

  <ul>
    <li>
      An asterisk (<dfn dfn-type="grammar" data-export="" id="mult-zero-plus">*</dfn>) indicates that the preceding type, word, or group
      occurs zero or more times.

    <li>
      A plus (<dfn dfn-type="grammar" data-export="" id="mult-one-plus">+<a class="self-link" href="#mult-one-plus"></a></dfn>) indicates that the preceding type, word, or group
      occurs one or more times.

    <li>
      A question mark (<dfn dfn-type="grammar" data-export="" id="mult-opt">?</dfn>) indicates that the preceding type, word, or
      group is optional.

    <li>
      A pair of numbers in curly braces (<dfn dfn-type="grammar" data-export="" id="mult-num-range">{<var>A</var>,<var>B</var>}<a class="self-link" href="#mult-num-range"></a></dfn>) indicates that the
      preceding type, word, or group occurs at least <var>A</var> and at most
      <var>B</var> times.
  </ul>


<p>The following examples illustrate different value types:

<blockquote><p>
    <em>Value:</em> N | NW | NE<br>
    <em>Value:</em> [ <<length>> | thick | thin ]{1,4}<br>
    <em>Value:</em> [&lt;family-name&gt; , ]* &lt;family-name&gt;<br>
    <em>Value:</em> <<uri>>? &lt;color&gt; [ / &lt;color&gt; ]?<br>
    <em>Value:</em> <<uri>> || &lt;color&gt;<br>
    <em>Value:</em> inset? &amp;&amp; [ <<length>>{2,4} &amp;&amp; &lt;color&gt;? ]
</blockquote>

<p>Component values are specified in terms of tokens, as described in <a href="#scanner">Appendix G.2</a>. As the grammar allows spaces
between tokens in the components of the <code>expr</code> production,
spaces may appear between tokens in property values.

<p class="note">Note: In many cases, spaces will in fact be
<em>required</em> between tokens in order to distinguish them from
each other. For example, the value ''1em2em'' would be parsed as a
single <code>DIMEN</code> token with the number ''1'' and the identifier
''em2em'', which is an invalid unit. In this case, a space would be
required before the ''2'' to get this parsed as the two lengths ''1em''
and ''2em''.


<h5 id="initial-value">Initial</h5>

<p>This part specifies the property's initial value. Please consult
the section on <a href="#assigning">the cascade</a> for information
about the interaction between style sheet-specified, inherited, and
initial property values.


<h5 id="applies-to">Applies to</h5>

<p>This part lists the elements to which the property applies. All
elements are considered to have all properties, but some properties
have no rendering effect on some types of elements. For example, the 'clear' property only affects block-level elements.

<h5 id="inherited-prop">Inherited</h5>

<p>This part indicates whether the value of the property is inherited
from an ancestor element. Please consult the section on <a href="#assigning">the cascade</a> for information about the
interaction between style sheet-specified, inherited, and initial
property values.


<h5 id="percentage-wrt">Percentage values</h5>

<p>This part indicates how percentages should be interpreted, if they occur in
the value of the property. If "N/A" appears here, it means that the
property does not accept percentages in its values.

<h5 id="media-applies">Media groups</h5>

<p>This part indicates the <a href="#media-groups">media
groups</a> to which the property applies. Information about media
groups is non-normative.

<h5 id="computed-defs">Computed value</h5>

<p>This part describes the computed value for the property. See the
section on <a href="#computed-value">computed values</a>
for how this definition is used.


<h4 id="shorthand">Shorthand properties</h4>

<p>Some properties are <dfn>shorthand properties</dfn>, meaning that they allow
authors to specify the values of several properties with a single
property.

<p>For instance, the 'font' property
is a shorthand property for setting 'font-style', 'font-variant', 'font-weight', 'font-size', 'line-height', and 'font-family' all at once.</p>

<p>When values are omitted from a shorthand form, each
"missing" property is assigned
its initial value (see the section on <a href="#assigning">the
cascade</a>).

<div class="example"><p>
The multiple style rules of this example:</p>

<pre class="lang-css">
h1 {
  font-weight: bold;
  font-size: 12pt;
  line-height: 14pt;
  font-family: Helvetica;
  font-variant: normal;
  font-style: normal;
}
</pre>

<p>may be rewritten with a single shorthand property:</p>

<pre class="lang-css">
h1 { font: bold 12pt/14pt Helvetica }
</pre>

<p>In this example, 'font-variant', and 'font-style'
take their initial values.</p>
</div>

<h4 id="notes-and-examples">Notes and examples</h4>

<p>All examples that illustrate illegal usage are clearly
marked as "ILLEGAL EXAMPLE".

<p>HTML examples lacking DOCTYPE declarations are SGML Text Entities
conforming to the HTML 4.01 Strict DTD [[!HTML401]]. Other HTML examples
conform to the DTDs given in the examples.

<p>All notes are informative only.

<p>Examples and notes are <a href="#defs">marked within
the source HTML</a> for the specification and CSS user agents will
render them specially.

<h4 id="images-and-longdesc">Images and long descriptions</h4>

<p>Most images in the electronic version of this specification are
accompanied by "long descriptions" of what they represent.  A link to
the long description is denoted by a "\[D]" after the image.

<p>Images and long descriptions are informative only.

<section class="non-normative">
<h3 id="acknowledgements">Acknowledgments</h3>

<p>This section is non-normative.

<p>CSS&nbsp;2.2 is based on CSS2&nbsp;(1998) and CSS&nbsp;2.1. See the <a href="https://www.w3.org/TR/2008/REC-CSS2-20080411/about.html#q15">acknowledgments section of CSS2</a> and the <a href="https://www.w3.org/TR/2011/REC-CSS2-20110607/about.html#acknowledgements">acknowledgments section of CSS&nbsp;2.1</a> for the people that
contributed to CSS2 and CSS&nbsp;2.1.

<p>We would like to thank the following people who, through their
input and feedback on the www-style mailing list, have helped us with
the creation of this specification:
  <span class="vcard"><span class="fn">Andrew Clover</span></span>,
  <span class="vcard"><span class="fn">Bernd Mielke</span></span>,
  <span class="vcard"><span class="fn">C. Bottelier</span></span>,
  <span class="vcard"><span class="fn">Christian Roth</span></span>,
  <span class="vcard"><span class="fn">Christoph P&auml;per</span></span>,
  <span class="vcard"><span class="fn">Claus F&auml;rber</span></span>,
  <span class="vcard"><span class="fn">Coises</span></span>,
  <span class="vcard"><span class="fn">Craig Saila</span></span>,
  <span class="vcard"><span class="fn">Darren Ferguson</span></span>,
  <span class="vcard"><span class="fn">Dylan Schiemann</span></span>,
  <span class="vcard"><span class="fn">Etan Wexler</span></span>,
  <span class="vcard"><span class="fn">George Lund</span></span>,
  <span class="vcard"><span class="fn">James Craig</span></span>,
  <span class="vcard"><span class="fn n"><span class="given-name">Jan</span>
   <span class="additional-name">Eirik</span>
   <span class="family-name">Olufsen</span></span></span>,
  <span class="vcard"><span class="fn"><span class="given-name">Jan</span>
   <span class="additional-name">Roland</span>
   <span class="family-name">Eriksson</span></span></span>,
  <span class="vcard"><span class="fn">Joris Huizer</span></span>,
  <span class="vcard"><span class="fn">Joshua Prowse</span></span>,
  <span class="vcard"><span class="fn">Kai Lahmann</span></span>,
  <span class="vcard"><span class="fn">Kevin Smith</span></span>,
  <span class="vcard"><span class="fn">Lachlan Cannon</span></span>,
  <span class="vcard"><span class="fn">Lars Knoll</span></span>,
  <span class="vcard"><span class="fn">Lauri Raittila</span></span>,
  <span class="vcard"><span class="fn">Mark Gallagher</span></span>,
  <span class="vcard"><span class="fn">Michael Day</span></span>,
  <span class="vcard"><span class="fn">Peter Sheerin</span></span>,
  <span class="vcard"><span class="fn n"><span class="given-name">Rijk</span>
   <span class="family-name">van Geijtenbeek</span></span></span>,
  <span class="vcard"><span class="fn">Robin Berjon</span></span>,
  <span class="vcard"><span class="fn">Scott Montgomery</span></span>,
  <span class="vcard"><span class="fn">Shelby Moore</span></span>,
  <span class="vcard"><span class="fn">Stuart Ballard</span></span>,
  <span class="vcard"><span class="fn">Tom Gilder</span></span>,
  <span class="vcard"><span class="fn">Vadim Plessky</span></span>,
  <span class="vcard"><span class="fn">Peter Moulder</span></span>,
  <span class="vcard"><span class="fn">Anton Prowse</span></span>,
  <span class="vcard"><span class="fn">G&eacute;rard Talbot</span></span>,
  <span class="vcard"><span class="fn">Ingo Chao</span></span>,
  <span class="vcard"><span class="fn">Bruno Fassino</span></span>,
  <span class="vcard"><span class="fn">Justin Rogers</span></span>,
  <span class="vcard"><span class="fn">Boris Zbarsky</span></span>,
  <span class="vcard"><span class="fn">Garrett Smith</span></span>,
  <span class="vcard"><span class="fn">Zack Weinberg</span></span>,
  <span class="vcard"><span class="fn">Bjoern Hoehrmann</span></span>,
  and the
  <span class="vcard"><span class="fn org">Open eBook Publication Structure Working Group</span></span>
  Editors. We would also like to thank
  <span class="vcard"><span class="fn">Gary Schnabl</span></span>,
  <span class="vcard"><span class="fn">Glenn Adams</span></span> and
  <span class="vcard"><span class="fn">Susan Lesch</span></span>
  who helped proofread earlier versions of this document.</p>

 <p>In addition, we would like to extend special thanks to
  <span class="vcard"><span class="fn">Elika J. Etemad</span></span>,
  <span class="vcard"><span class="fn">Ada Chan</span></span> and
  <span class="vcard"><span class="fn">Boris Zbarsky</span></span>
  who have contributed significant time to CSS&nbsp;2.1, and to
  <span class="vcard"><span class="fn">Kimberly Blessing</span></span>
  for help with the editing.</p>

 <p>Many thanks also to the following people for their help
 with the test suite:

  <span class="vcard"><span class="fn">Robert Stam</span></span>,
  <span class="vcard"><span class="fn">Aharon Lanin</span></span>,
  <span class="vcard"><span class="fn">Alan Gresley</span></span>,
  <span class="vcard"><span class="fn">Alan Harder</span></span>,
  <span class="vcard"><span class="fn">Alexander Dawson</span></span>,
  <span class="vcard"><span class="fn">Arron Eicholz</span></span>,
  <span class="vcard"><span class="fn">Bernd Mielke</span></span>,
  <span class="vcard"><span class="fn">Bert Bos</span></span>,
  <span class="vcard"><span class="fn">Boris Zbarsky</span></span>,
  <span class="vcard"><span class="fn">Bruno Fassino</span></span>,
  <span class="vcard"><span class="fn">Daniel Schattenkirchner</span></span>,
  <span class="vcard"><span class="fn">David Hammond</span></span>,
  <span class="vcard"><span class="fn">David Hyatt</span></span>,
  <span class="vcard"><span class="fn">Eira Monstad</span></span>,
  <span class="vcard"><span class="fn">Elika J. Etemad</span></span>,
  <span class="vcard"><span class="fn">G&eacute;rard Talbot</span></span>,
  <span class="vcard"><span class="fn">Gabriele Romanato</span></span>,
  <span class="vcard"><span class="fn">Germain Garand</span></span>,
  <span class="vcard"><span class="fn">Hilbrand Edskes</span></span>,
  <span class="vcard"><span class="fn">Ian Hickson</span></span>,
  <span class="vcard"><span class="fn">James Hopkins</span></span>,
  <span class="vcard"><span class="fn">Justin Boss</span></span>,
  <span class="vcard"><span class="fn">L. David Baron</span></span>,
  <span class="vcard"><span class="fn">Lachlan Hunt</span></span>,
  <span class="vcard"><span class="fn">Magne Andersson</span></span>,
  <span class="vcard"><span class="fn">Marc Pacheco</span></span>,
  <span class="vcard"><span class="fn">Mark McKenzie-Bell</span></span>,
  <span class="vcard"><span class="fn">Matt Bradley</span></span>,
  <span class="vcard"><span class="fn">Melinda Grant</span></span>,
  <span class="vcard"><span class="fn">Michael Turnwall</span></span>,
  <span class="vcard"><span class="fn">Ray Kiddy</span></span>,
  <span class="vcard"><span class="fn">Richard Ishida</span></span>,
  <span class="vcard"><span class="fn">Robert O'Callahan</span></span>,
  <span class="vcard"><span class="fn">Simon Montagu</span></span>,
  <span class="vcard"><span class="fn">Tom Clancy</span></span>,
  <span class="vcard"><span class="fn">Vasil Dinkov</span></span>,
  &mldr; and all the contributors to the CSS1 test suite.

  <p>Working Group members active during the development of this
  specification:

  <span class="vcard"><span class="fn">C&eacute;sar Acebal</span> (<span class="org">Universidad de Oviedo</span>)</span>,
  <span class="vcard"><span class="fn">Tab Atkins Jr.</span> (<span class="org">Google, Inc.</span>)</span>,
  <span class="vcard"><span class="fn">L. David Baron</span> (<span class="org">Mozilla Foundation</span>)</span>,
  <span class="vcard"><span class="fn">Bert Bos</span> (<span class="org">W3C/ERCIM</span>)</span>,
  <span class="vcard"><span class="fn">Tantek &Ccedil;elik</span> (<span class="org">W3C Invited Experts</span>)</span>,
  <span class="vcard"><span class="fn">Cathy Chan</span> (<span class="org">Nokia</span>)</span>,
  <span class="vcard"><span class="fn">Giorgi Chavchanidze</span> (<span class="org">Opera Software</span>)</span>,
  <span class="vcard"><span class="fn">John Daggett</span> (<span class="org">Mozilla Foundation</span>)</span>,
  <span class="vcard"><span class="fn">Beth Dakin</span> (<span class="org">Apple, Inc.</span>)</span>,
  <span class="vcard"><span class="fn">Arron Eicholz</span> (<span class="org">Microsoft Corp.</span>)</span>,
  <span class="vcard"><span class="fn">Elika J. Etemad</span> (<span class="org">W3C Invited Experts</span>)</span>,
  <span class="vcard"><span class="fn">Simon Fraser</span> (<span class="org">Apple, Inc.</span>)</span>,
  <span class="vcard"><span class="fn">Sylvain Galineau</span> (<span class="org">Microsoft Corp.</span>)</span>,
  <span class="vcard"><span class="fn">Daniel Glazman</span> (<span class="org">Disruptive Innovations</span>)</span>,
  <span class="vcard"><span class="fn">Molly Holzschlag</span> (<span class="org">Opera Software</span>)</span>,
  <span class="vcard"><span class="fn">David Hyatt</span> (<span class="org">Apple, Inc.</span>)</span>,
  <span class="vcard"><span class="fn">Richard Ishida</span> (<span class="org">W3C/ERCIM</span>)</span>,
  <span class="vcard"><span class="fn">John Jansen</span> (<span class="org">Microsoft Corp.</span>)</span>,
  <span class="vcard"><span class="fn">Brad Kemper</span> (<span class="org">W3C Invited Experts</span>)</span>,
  <span class="vcard"><span class="fn">H&aring;kon Wium Lie</span> (<span class="org">Opera Software</span>)</span>,
  <span class="vcard"><span class="fn">Chris Lilley</span> (<span class="org">W3C/ERCIM</span>)</span>,
  <span class="vcard"><span class="fn">Peter Linss</span> (<span class="org">HP</span>)</span>,
  <span class="vcard"><span class="fn">Markus Mielke</span> (<span class="org">Microsoft Corp.</span>)</span>,
  <span class="vcard"><span class="fn">Alex Mogilevsky</span> (<span class="org">Microsoft Corp.</span>)</span>,
  <span class="vcard"><span class="fn">David Singer</span> (<span class="org">Apple Inc.</span>)</span>,
  <span class="vcard"><span class="fn">Anne van Kesteren</span> (<span class="org">Opera Software</span>)</span>,
  <span class="vcard"><span class="fn">Steve Zilles</span> (<span class="org">Adobe Systems Inc.</span>)</span>,
  <span class="vcard"><span class="fn">Ian Hickson</span> (<span class="org">Google, Inc.</span>)</span>,
  <span class="vcard"><span class="fn">Melinda Grant</span> (<span class="org">HP</span>)</span>,
  <span class="vcard"><span class="fn">&Oslash;yvind Stenhaug</span> (<span class="org">Opera Software</span>)</span>,
  and
  <span class="vcard"><span class="fn">Paul Nelson</span> (<span class="org">Microsoft Corp.</span>)</span>.
</section>





<h2 id="intro"><span id="q2.0">Introduction to CSS&nbsp;2</span> </h2>

<section class="non-normative">
<h3 id="html-tutorial">A brief CSS&nbsp;2 tutorial for HTML</h3>

<p>This section is non-normative.

<p> In this tutorial, we show how easy it can be to design simple
style sheets. For this tutorial, you will need to know a little HTML
(see [[HTML401]]) and some basic desktop publishing terminology.

<p>We begin with a small HTML document:</p>

<pre class="lang-html example">
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
  &lt;HEAD&gt;
  &lt;TITLE&gt;Bach's home page&lt;/TITLE&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
    &lt;H1&gt;Bach's home page&lt;/H1&gt;
    &lt;P&gt;Johann Sebastian Bach was a prolific composer.
  &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>

<p>To set the text color of the H1 elements to red, you can write the
following CSS rules:</p>

<pre class="example lang-css">
  h1 { color: red }
</pre>

<p>A CSS rule consists of two main parts: <a href="#selector">selector</a> (''h1'') and declaration
('color:&nbsp;red'). In HTML, element names are case-insensitive so
''h1'' works just as well as ''H1''. The declaration has two parts:
property name ('color') and property value (''red''). While the example above tries to
influence only one of the properties needed for rendering an HTML
document, it qualifies as a style sheet on its own. Combined with
other style sheets (one fundamental feature of CSS is that style
sheets are combined), the rule will determine the final presentation of the
document.

<p> The HTML 4 specification defines how style sheet rules may be
specified for HTML documents: either within the HTML document, or via
an external style sheet. To put the style sheet into the document, use
the STYLE element:</p>

<pre class="lang-html example">
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
  &lt;HEAD&gt;
  &lt;TITLE&gt;Bach's home page&lt;/TITLE&gt;
  &lt;STYLE type="text/css"&gt;
    h1 { color: red }
  &lt;/STYLE&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
    &lt;H1&gt;Bach's home page&lt;/H1&gt;
    &lt;P&gt;Johann Sebastian Bach was a prolific composer.
  &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>

<p> For maximum flexibility, we recommend that authors specify
external style sheets; they may be changed without modifying the
source HTML document, and they may be shared among several
documents. To link to an external style sheet, you can use the LINK
element:</p>

<pre class="lang-html example">
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
  &lt;HEAD&gt;
  &lt;TITLE&gt;Bach's home page&lt;/TITLE&gt;
  &lt;LINK rel="stylesheet" href="bach.css" type="text/css"&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
    &lt;H1&gt;Bach's home page&lt;/H1&gt;
    &lt;P&gt;Johann Sebastian Bach was a prolific composer.
  &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>

<p>The LINK element specifies:</p>

<ul>
<li>the type of link: to a "stylesheet".
<li>the location of the style sheet via the "href" attribute.
<li>the type of style sheet being linked: "text/css".
</ul>

<p>To show the close relationship between a style sheet and the
structured markup, we continue to use the STYLE element in this
tutorial. Let's add more colors:

<pre class="lang-html example">
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
  &lt;HEAD&gt;
  &lt;TITLE&gt;Bach's home page&lt;/TITLE&gt;
  &lt;STYLE type="text/css"&gt;
    body { color: black; background: white }
    h1 { color: red; background: white }
  &lt;/STYLE&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
    &lt;H1&gt;Bach's home page&lt;/H1&gt;
    &lt;P&gt;Johann Sebastian Bach was a prolific composer.
  &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>

<p>The style sheet now contains four rules: the first two set the
color and background of the BODY element (it's a good idea to set the
text color and background color together), while the last two
set the color and the background of the H1 element. Since no color
has been specified for the P element, it will inherit the color
from its parent element, namely BODY. The H1 element is also a child
element of BODY but the second rule overrides the inherited value. In
CSS there are often such conflicts between different values, and this
specification describes how to resolve them.

<p>CSS&nbsp;2 has more than 90 properties, including 'color'. Let's look at some of the
others:

<pre class="example">
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
  &lt;HEAD&gt;
  &lt;TITLE&gt;Bach's home page&lt;/TITLE&gt;
  &lt;STYLE type="text/css"&gt;
    body {
      font-family: "Gill Sans", sans-serif;
      font-size: 12pt;
      margin: 3em;
    }
  &lt;/STYLE&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
    &lt;H1&gt;Bach's home page&lt;/H1&gt;
    &lt;P&gt;Johann Sebastian Bach was a prolific composer.
  &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>

<p>The first thing to notice is that several declarations are grouped
within a block enclosed by curly braces ({...}), and separated by
semicolons, though the last declaration may also be followed by a
semicolon.

<p>The first declaration on the BODY element sets the font family to
"Gill Sans". If that font is not available, the user agent (often
referred to as a "browser") will use the ''sans-serif'' font family
which is one of five generic font families which all users agents
know. Child elements of BODY will inherit the value of the 'font-family' property.

<p>The second declaration sets the font size of the BODY element to
12 points. The "point" unit is commonly used in print-based typography
to indicate font sizes and other length values. It's an example of an
absolute unit which does not scale relative to the environment.

<p>The third declaration uses a relative unit which scales with regard
to its surroundings. The "em" unit refers to the font size of the
element. In this case the result is that the margins around the BODY
element are three times wider than the font size.
</section>

<section class="non-normative">
<h3 id="xml-tutorial">A brief CSS&nbsp;2 tutorial for XML</h3>

<p>This section is non-normative.

<p>CSS can be used with any structured document format, for example
with applications of the eXtensible Markup Language [[XML10]]. In
fact, XML depends more on style sheets than HTML, since authors can
make up their own elements that user agents do not know how to
display.

<p>Here is a simple XML fragment:

<pre class="lang-xml example">
&lt;ARTICLE&gt;
  &lt;HEADLINE&gt;Fredrick the Great meets Bach&lt;/HEADLINE&gt;
  &lt;AUTHOR&gt;Johann Nikolaus Forkel&lt;/AUTHOR&gt;
  &lt;PARA&gt;
    One evening, just as he was getting his
    &lt;INSTRUMENT&gt;flute&lt;/INSTRUMENT&gt; ready and his
    musicians were assembled, an officer brought him a list of
    the strangers who had arrived.
  &lt;/PARA&gt;
&lt;/ARTICLE&gt;
</pre>

<p>To display this fragment in a document-like fashion, we must first
declare which elements are inline-level (i.e., do not cause line breaks) and
which are block-level (i.e., cause line breaks).

<pre class="example lang-css">
INSTRUMENT { display: inline }
ARTICLE, HEADLINE, AUTHOR, PARA { display: block }
</pre>

<p>The first rule declares INSTRUMENT to be inline and the second
rule, with its comma-separated list of selectors, declares all the
other elements to be block-level. Element names in XML are
case-sensitive, so a selector written in lowercase (e.g., ''instrument'')
is different from uppercase (e.g., ''INSTRUMENT'').

<p>One way of linking a style sheet to an XML document is to use
a processing instruction:

<pre class="lang-xml example">
&lt;?xml-stylesheet type="text/css" href="bach.css"?&gt;
&lt;ARTICLE&gt;
  &lt;HEADLINE&gt;Fredrick the Great meets Bach&lt;/HEADLINE&gt;
  &lt;AUTHOR&gt;Johann Nikolaus Forkel&lt;/AUTHOR&gt;
  &lt;PARA&gt;
    One evening, just as he was getting his
    &lt;INSTRUMENT&gt;flute&lt;/INSTRUMENT&gt; ready and his
    musicians were assembled, an officer brought him a list of
    the strangers who had arrived.
  &lt;/PARA&gt;
&lt;/ARTICLE&gt;
</pre>

<p>A visual user agent could format the above example as:

<div class="figure">
<p><img src="images/bach1.png" alt="Example rendering" id="img-bach1">
</div>

<p>Notice that the word "flute" remains within the paragraph since it
is the content of the inline element INSTRUMENT.

<p>Still, the text is not formatted the way you would expect. For
example, the headline font size should be larger than then the rest of
the text, and you may want to display the author's name in italic:</p>

<pre class="example lang-css">
INSTRUMENT { display: inline }
ARTICLE, HEADLINE, AUTHOR, PARA { display: block }
HEADLINE { font-size: 1.3em }
AUTHOR { font-style: italic }
ARTICLE, HEADLINE, AUTHOR, PARA { margin: 0.5em }
</pre>

<p>A visual user agent could format the above example as:

<div class="figure">
<p><img src="images/bach2.png" alt="Example rendering" id="img-bach2">
</div>

<p>Adding more rules to the style sheet will allow you to further
describe the presentation of the document.
</section>

<h3 id="processing-model">The CSS&nbsp;2 processing model</h3>

<p>This section up to but not including its subsections is
non-normative.

<div class="non-normative">

<p>This section presents one possible model of how user
agents that support CSS work. This is only a conceptual model; real
implementations may vary.

<p>In this model, a user agent processes a source
by going through the following steps:</p>

<ol>
<li>Parse the source document and create a <a href="#doctree">document tree</a>.</li>

<li>Identify the target <a href="#media">media type</a>.

<li>Retrieve all style sheets associated with the document that are
specified for the target <a href="#media">media type</a>.

<li>Annotate every element of the document tree by assigning a single
value to every <a href="#properties">property</a> that is
applicable to the target <a href="#media">media type</a>.
Properties are assigned values according to the mechanisms described
in the section on <a href="#assigning">cascading and
inheritance</a>.

<p>Part of the calculation of values depends on the formatting
algorithm appropriate for the target <a href="#media">media
type</a>. For example, if the target medium is the screen, user agents
apply the <a href="#visuren">visual formatting model</a>.

<li>From the annotated document tree, generate a
<dfn id="formatting-structure">
formatting
structure</dfn>.  Often, the formatting structure closely
resembles the document tree, but it may also differ significantly,
notably when authors make use of pseudo-elements and generated content.
First, the formatting structure need not be "tree-shaped" at all -- the
nature of the structure depends on the implementation.  Second, the
formatting structure may contain more or less information than the
document tree. For instance, if an element in the document tree has a
value of ''display/none'' for the 'display' property, that element will
generate nothing in the formatting structure.  A list element, on the
other hand, may generate more information in the formatting structure:
the list element's content and list style information (e.g., a bullet
image).

<p>Note that the CSS user agent does not alter the document tree
during this phase. In particular, content generated due to style
sheets is not fed back to the document language processor (e.g., for
reparsing).

<li>Transfer the formatting structure to the target medium (e.g., print
the results, display them on the screen, render them as speech,
etc.).
</ol>
</div>

<h4 id="the-canvas">The canvas</h4>

<p>For all media, the term <dfn id="canvas"> canvas</dfn> describes "the space where
the formatting structure is rendered."  The canvas is infinite for each
dimension of the space, but rendering generally occurs within
a finite region of the canvas, established by the user agent
according to the target medium. For instance, user agents rendering
to a screen generally impose a minimum width and choose an initial
width based on the dimensions of the <a href="#viewport">
viewport</a>. User agents rendering to a page generally impose
width and height constraints. Aural user agents may impose limits
in audio space, but not in time.

<h4 id="addressing">CSS&nbsp;2 addressing model</h4>

<p> CSS&nbsp;2 <a href="#selector">selectors</a> and properties allow
style sheets to refer to the following parts of a document
or user agent:</p>

<ul>
<li>Elements in the document tree and certain relationships between
them (see the section on <a href="#selector">selectors</a>).

<li>Attributes of elements in the document tree, and values of those
attributes (see the section on <a href="#attribute-selectors">attribute selectors</a>).

<li>Some parts of element content (see the <a href="#first-line">:first-line</a> and <a href="#first-letter">:first-letter</a> pseudo-elements).

<li>Elements of the document tree when they are in a certain state
(see the section on <a href="#pseudo-classes">pseudo-classes</a>).

<li>Some aspects of the <a href="#canvas">canvas</a> where
the document will be rendered.

<li>Some system information (see the section on <a href="#ui">user
interface</a>).
</ul>

<section class="non-normative">
<h3 id="design-principles">CSS design principles</h3>

<p>This section is non-normative.

<p>CSS&nbsp;2, as with earlier CSS specifications, is based on a set of design principles:</p>

<ul>

<li>
<p><strong>Forward and backward compatibility</strong>. CSS&nbsp;2 user
agents will be able to understand CSS1 style sheets. CSS1 user agents
will be able to read CSS&nbsp;2 style sheets and discard parts they do not
understand. Also, user agents with no CSS support will be able to
display style-enhanced documents. Of course, the stylistic
enhancements made possible by CSS will not be rendered, but all
content will be presented.</p>
</li>

<li>
<p><strong>Complementary to structured documents</strong>. Style
sheets complement structured documents (e.g., HTML and XML
applications), providing
stylistic information for the marked-up text. It should be easy to
change the style sheet with little or no impact on the markup.</p>
</li>

<li>
<p><strong>Vendor, platform, and device independence</strong>. Style
sheets enable documents to remain vendor, platform, and device
independent. Style sheets themselves are also vendor and platform
independent, but CSS&nbsp;2 allows you to target a style sheet for a group of
devices (e.g., printers).</p>
</li>

<li>
<p><strong>Maintainability</strong>. By pointing to style sheets from
documents, webmasters can simplify site maintenance and retain
consistent look and feel throughout the site. For example, if
the organization's background color changes, only one file needs to be
changed.</p>
</li>

<li>
<p><strong>Simplicity</strong>. CSS is a simple style language which
is human readable and writable. The CSS properties are kept
independent of each other to the largest extent possible and there is
generally only one way to achieve a certain effect.</p>
</li>

<li>
<p><strong>Network performance</strong>. CSS provides for compact
encodings of how to present content. Compared to images or audio
files, which are often used by authors to achieve certain rendering
effects, style sheets most often decrease the content size. Also,
fewer network connections have to be opened which further increases
network performance.</p> </li>

<li>
<p><strong>Flexibility</strong>. CSS can be applied to content in
several ways. The key feature is the ability to cascade style
information specified in the default (user agent) style sheet, user
style sheets, linked style sheets, the document head, and in
attributes for the elements forming the document body.</p>
</li>

<li>
<p><strong>Richness</strong>. Providing authors with a rich set of
rendering effects increases the richness of the Web as a medium of
expression. Designers have been longing for functionality commonly
found in desktop publishing and slide-show applications. Some of
the requested rendering effects conflict with device independence, but
CSS&nbsp;2 goes a long way toward granting designers their requests.</p>
</li>

<li>
<p><strong>Alternative language bindings</strong>. The set of CSS
properties described in this specification form a consistent
formatting model for visual presentations. This formatting
model can be accessed through the CSS language, but bindings to other
languages are also possible. For example, a JavaScript program may
dynamically change the value of a certain element's 'color' property.</p>
</li>

<li>
<p><strong>Accessibility</strong>. Several CSS
features will make the Web more accessible
to users with disabilities:</p>

<ul>

<li>Properties to control font appearance allow authors
to eliminate inaccessible bit-mapped text images.

<li>Positioning properties allow authors to eliminate
mark-up tricks (e.g., invisible images) to force layout.

<li>The semantics of
<code>!important</code> rules mean that users with
particular presentation requirements
can override the author's style sheets.

<li>The ''inherit'' value for all properties
improves cascading generality and allows for
easier and more consistent style tuning.

<li>Improved media support, including media groups and the
braille, embossed, and tty media types, will allow users and
authors to tailor pages to those devices.

</ul>

<div class="note"><p> <em><strong>Note.</strong> For more information
about designing accessible documents using CSS and HTML, see [[WCAG20]].</em>
</div>
</ul>
</section>





<h2 id="conform"><span id="q3.0">Conformance: Requirements and Recommendations</span></h2>

<h3 id="defs">Definitions</h3>

<p>The key words <dfn data-lt="MUST">"MUST"</dfn>,
<dfn data-lt="MUST NOT">"MUST NOT"</dfn>, <dfn data-lt="REQUIRED">"REQUIRED"</dfn>, <dfn data-lt="SHALL">"SHALL"</dfn>, <dfn data-lt="SHALL NOT">"SHALL NOT"</dfn>, <dfn data-lt="SHOULD">"SHOULD"</dfn>, <dfn data-lt="SHOULD NOT">"SHOULD NOT"</dfn>, <dfn data-lt="RECOMMENDED">"RECOMMENDED"</dfn>, <dfn data-lt="MAY">"MAY"</dfn>, and <dfn data-lt="OPTIONAL">"OPTIONAL"</dfn> in this document
are to be interpreted as described in RFC&nbsp;2119 (see [[!RFC2119]]).
However, for readability, these words do not appear in all uppercase
letters in this specification.

<p>At times, this specification recommends good practice
for authors and user agents. These recommendations are not normative
and conformance with this specification does not depend on their
realization. These recommendations contain the expression "We
recommend ...", "This specification recommends ...", or some similar
wording.</p>

<p>The fact that a feature is marked as deprecated or going to
be deprecated in CSS3 (namely the <a href="#system-colors">system colors</a>) also has no influence
on conformance. (For example, the system colors are a normative part of the specification, so UAs
must support them.)

<p>All sections of this specification, including appendices, are
normative unless otherwise noted.

<p><a href="#notes-and-examples">Examples and notes</a>
are not normative.

<div class="example"><p>Examples usually have the word "example" near
their start ("Example:", "The following example&mldr;," "For
example," etc.) and are shown in the color maroon, like this
paragraph.</div>

<div class="note"><p>Notes start with the word "Note," are indented and
shown in green, like this paragraph.</div>

<p>Figures are for illustration only. They are not reference
renderings, unless explicitly stated.

<dl>



<dt><dfn id="style-sheet">Style sheet</dfn>

<dd>A set of statements that specify presentation of a document.

<p>Style sheets may have three different origins: <a href="#author">author</a>, <a href="#user">user</a>, and <a href="#user-agent">user agent</a>. The interaction of these sources is
described in the section on <a href="#assigning">cascading and
inheritance</a>.

<dt><dfn data-lt="valid style sheet|validity" id="valid-style-sheet">Valid style
sheet</dfn>

<dd>The validity of a style sheet depends on the level of CSS
used for the style sheet. All valid CSS1 style sheets are valid CSS&nbsp;2
style sheets, but some changes from CSS1 mean that
a few CSS1 style sheets will have slightly different semantics in
CSS&nbsp;2. Some features in CSS2&nbsp;(1998) are not part of CSS&nbsp;2, so not all CSS2&nbsp;(1998)
style sheets are valid CSS&nbsp;2 style sheets.

<p>A valid CSS&nbsp;2 style sheet must be written according to the <a href="#app-grammar">grammar of CSS&nbsp;2</a>. Furthermore, it must contain
only at-rules, property names, and property values defined in this
specification.
An <dfn id="illegal">illegal</dfn> (invalid) at-rule,
property name, or property value is one that is not valid.

<dt><dfn id="source-document">Source
document</dfn>

<dd>The document to which one or more style sheets apply. This is
encoded in some language that represents the document as a tree of <a href="#element">elements</a>. Each element consists of a name that
identifies the type of element, optionally a number of <a href="#attribute">attributes</a>, and a (possibly empty) <a href="#content">content</a>. For example, the source document could be
an XML or SGML instance.</dd>

<dt><dfn id="doclanguage">Document language</dfn>

<dd>The encoding language of the source document (e.g., HTML, XHTML, or
SVG). CSS is used to describe the presentation of document languages
and CSS does not change the underlying semantics of the document
languages.

<dt><dfn id="element">Element</dfn>

<dd>(An SGML term, see [[!ISO8879]].) The primary syntactic constructs
of the document language. Most CSS style sheet rules use the names of
these elements (such as P, TABLE, and OL in HTML) to specify
how the elements should be rendered.

<dt><dfn id="replaced-element">
Replaced
element</dfn>

<dd><p>An element whose content is outside the scope of the CSS
formatting model, such as an image, embedded document, or applet. For
example, the content of the HTML IMG element is often replaced by the
image that its "src" attribute designates. Replaced elements often
have intrinsic dimensions: an intrinsic width, an intrinsic height,
and an intrinsic ratio. For example, a bitmap image has an intrinsic
width and an intrinsic height specified in absolute units (from which
the intrinsic ratio can obviously be determined). On the other hand,
other documents may not have any intrinsic dimensions (for example, a
blank HTML document).

<p>User agents may consider a replaced element to not have any
intrinsic dimensions if it is believed that those dimensions could
leak sensitive information to a third party. For example, if an HTML
document changed intrinsic size depending on the user's bank balance,
then the UA might want to act as if that resource had no intrinsic
dimensions.

<p>The content of replaced elements is not considered in the CSS
rendering model.

<dt><dfn id="intrinsic">Intrinsic dimensions</dfn>

<dd>The width and height as defined by the element itself, not imposed
by the surroundings. CSS does not define how the intrinsic dimensions
are found. In CSS&nbsp;2 only replaced elements can come with
intrinsic dimensions.
For raster images without reliable resolution information, a size of
1&nbsp;px unit per image source pixel must be assumed.

<dt><dfn id="attribute">Attribute</dfn>

<dd>A value associated with an element, consisting of a name, and an
associated (textual) value.

<dt><dfn id="content">Content</dfn>

<dd>The content associated with an element in the source document.
Some elements have no content, in which case they are
called <dfn id="empty">empty</dfn>. The content
of an element may include text, and it may include a number of
sub-elements, in which case the element is called
the <dfn id="parent">parent</dfn> of those
sub-elements.

<dt><css id="ignore">Ignore</css>

<dd>This term has two slightly different meanings in this
specification. First, a CSS parser must follow certain rules when it
discovers unknown or illegal syntax in a style sheet. The parser must
then <dfn data-lt="ignore unknown">ignore certain parts of the style sheets</dfn>. The exact rules for
which parts must be ignored are described in these sections (<a href="#declaration">Declarations and properties,</a> <a href="#parsing-errors">Rules for handling parsing
errors,</a> <a href="#unsupported-values">Unsupported
Values</a>) or may be explained in the text where the term "ignore"
appears. Second, a user agent may (and, in some cases must) <dfn data-lt="ignore valid">disregard
certain properties or values in the style sheet</dfn>, even if the syntax is
legal. For example, table-column elements cannot affect the font of the
column, so the font properties must be ignored.


<dt><dfn id="rendered-content">Rendered
content</dfn>

<dd>The content of an element after the rendering that applies to it
according to the relevant style sheets has been applied. How a
replaced element's content is rendered is not defined by this
specification. Rendered content may also be
alternate text for an element (e.g., the value of the XHTML "alt"
attribute), and may include items inserted implicitly or explicitly by
the style sheet, such as bullets, numbering, etc.

<dt><dfn id="doctree">
Document
tree</dfn>

<dd>The tree of elements encoded in the source document. Each element
in this tree has exactly one parent, with the exception of the
<dfn id="root">root</dfn> element, which has none.

<dt><dfn id="child">Child</dfn>

<dd>An element A is called the child of element B if and only if B is
the parent of A.

<dt><dfn id="descendant">Descendant</dfn>

<dd>An element A is called a descendant of an element B, if either (1)
A is a child of B, or (2) A is the child of some element C that is a
descendant of B.

<dt><dfn id="ancestor">Ancestor</dfn>

<dd>An element A is called an ancestor of an element B, if and only if
B is a descendant of A.

<dt><dfn id="sibling">Sibling</dfn>

<dd>An element A is called a sibling of an element B, if and only if B
and A share the same parent element. Element A is a preceding sibling
if it comes before B in the document tree. Element B is a following
sibling if it comes after A in the document tree.

<dt><dfn id="preceding">Preceding element</dfn>

<dd>An element A is called a preceding element of an element B, if and
only if (1) A is an ancestor of B or (2) A is a preceding sibling of
B.

<dt><dfn id="following">Following
element</dfn>

<dd>An element A is called a following element of an element B, if and
only if B is a preceding element of A.

<dt><dfn id="author">Author</dfn>

<dd>An author is a person who writes documents and associated style
sheets.
An <dfn id="authoring">authoring
tool</dfn> is a <a href="#user-agent">user agent</a>
that generates style sheets.</dd>

<dt><dfn id="user">User</dfn>

<dd> A user is a person who interacts with a user agent to view, hear, or
otherwise use a document and its associated style sheet. The user
may provide a personal style sheet that encodes personal
preferences.
</dd>

<dt><dfn id="user-agent">User agent
(UA)</dfn>

<dd>A <dfn data-lt="user agent|UA" id="ua">user
agent</dfn> is any program that interprets a document written in
the document language and applies associated style sheets according
to the terms of this specification. A user agent may display a
document, read it aloud, cause it to be printed, convert it
to another format, etc.</dd>

<dd>An HTML user agent is one that supports one or more of the HTML
specifications. A user agent that supports XHTML [[XHTML1]], but not
HTML is not considered an
HTML user agent for the purpose of conformance with this
specification.

<dt><dfn id="property">Property</dfn>

<dd>CSS defines a finite set of parameters, called properties, that
direct the rendering of a document. Each property has a name (e.g.,
'color', 'font', or border') and a value (e.g., ''red'', '12pt Times', or
''<border-style>/dotted''). Properties are attached to various parts of the document
and to the page on which the document is to be displayed by the
mechanisms of specificity, cascading, and inheritance (see the chapter
on <a href="#assigning">Assigning property values, Cascading, and
Inheritance</a>).

</dl>

<div class="lang-html example">
<p>Here is an example of a source document written in HTML:

<pre>
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
  &lt;TITLE&gt;My home page&lt;/TITLE&gt;
  &lt;BODY&gt;
    &lt;H1&gt;My home page&lt;/H1&gt;
    &lt;P&gt;Welcome to my home page! Let me tell you about my favorite
      composers:
    &lt;UL&gt;
      &lt;LI&gt; Elvis Costello
      &lt;LI&gt; Johannes Brahms
      &lt;LI&gt; Georges Brassens
    &lt;/UL&gt;
  &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>

<p>This results in the following tree:</p>

<div class="figure">
<p><img src="images/doctree.png" alt="Sample document tree" id="img-doctree"></p>
</div>

<p>According to the definition of HTML 4, HEAD elements will be
inferred during parsing and become part of the document tree even if
the "head" tags are not in the document source. Similarly, the parser
knows where the P and LI elements end, even though there are no
&lt;/p&gt; and &lt;/li&gt; tags in the source.

<p>Documents written in XHTML (and other XML-based languages) behave
differently: there are no inferred elements and all elements must have
end tags.

</div>



<h3 id="conformance">UA Conformance</h3>

<p>This section defines <dfn id="conformance-term">conformance</dfn> with
the CSS&nbsp;2
specification only. There may be other levels of CSS in the future
that may require a user agent to implement a different set of features
in order to conform.

<p>In general, the following points must be observed by a user agent
claiming conformance to this specification:</p>

<ol>

<li>It must recognize one or more of the CSS&nbsp;2 <a href="#media">media types</a>.

<li>For each source document, it must attempt to retrieve all
associated style sheets that are appropriate for the recognized media
types. If it cannot retrieve all associated style sheets (for instance,
because of network errors), it must display the document using those
it can retrieve.

<li>It must parse the style sheets according to this specification.
In particular, it must recognize all at-rules, blocks, declarations,
and selectors (see the <a href="#app-grammar">grammar of CSS&nbsp;2</a>).
If a user agent encounters a property that applies for a supported
media type, the user agent must parse the value according to the property
definition. This means that the user agent must accept all valid
values and must
<a data-lt="ignore">ignore</a> declarations with
invalid values. User
agents must <a data-lt="ignore">ignore</a>
rules that apply to unsupported <a href="#media">media
types</a>.

<!-- Define "accept"? Include statement that conforming user
agents may only allow one value for certain properties (for
backwards compatibility, see CSS1 for list of these properties),
i.e., the default style sheet value -IJ -->

<li>For each element in a <a href="#doctree">document tree</a>, it
must assign a value for every property according to the
property's definition and the rules of <a href="#assigning">cascading and inheritance</a>.

<li>If the source document comes with alternate style sheet sets (such as
with the "alternate" keyword in HTML 4 [[HTML401]]), the UA must
allow the user to select which style sheet set the UA should apply.

<li>The UA must allow the user to turn off the influence of author style sheets.

</ol>

<p>Not every user agent must observe every point, however:</p>

<ul>

<li>An application that reads style sheets without rendering any
content (e.g., a CSS&nbsp;2 validator) must respect points 1-3.

<li>An authoring tool is only required to output <a href="#valid-style-sheet">valid style sheets</a>

<li>A user agent that <em>renders</em> a document with associated style
sheets must respect points 1-6 and render the document
according to the media-specific requirements set forth in this
specification. <a href="#actual-value">Values</a>
may be approximated when required by the user agent.

</ul>

<p>The inability of a user agent to implement part of this
specification due to the limitations of a particular device (e.g., a
user agent cannot render colors on a monochrome monitor or page) does
not imply non-conformance. </p>

<p>UAs must allow users to specify a file that contains the user style
sheet. UAs that run on devices without any means of writing or
specifying files are exempted from this requirement. Additionally, UAs
may offer other means to specify user preferences, for example, through
a GUI.

<p>CSS&nbsp;2 does not define which properties apply to form controls and
frames, or how CSS can be used to style them. User agents may apply CSS
properties to these elements. Authors are recommended to treat such
support as experimental. A future level of CSS may specify this further.


<h3 id="errors">Error conditions</h3>

<p>In general, this document specifies error handling behavior
throughout the specification. For example, see the <a href="#parsing-errors">rules for handling parsing errors</a>.

<h3 id="text-css">The text/css content type</h3>

<span id="message-entity"></span>

The <i>media type</i> (commonly <i>MIME type</i>)
of <code>text/css</code>
has been registered by [[!RFC2318]].




<h2 id="syndata"><span id="q4.0">Syntax and basic data types</span></h2>
<h3 id="syntax">Syntax</h3>

<p>This section describes a grammar (and <dfn>forward-compatible
parsing</dfn> rules) common to any level of CSS (including
CSS&nbsp;2). Future updates of CSS will adhere to this core syntax,
although they may add additional syntactic constraints.
</p>
<p>These descriptions are normative. They are also
complemented by the normative grammar rules presented in <a href="#app-grammar">Appendix G</a>.
</p>
<p>In this specification, the expressions "immediately before" or
"immediately after" mean with no intervening white space or comments.

<h4 id="tokenization">Tokenization</h4>

<p>All levels of CSS &mdash; level 1, level 2, and any future levels &mdash; use
the same core syntax. This allows UAs to parse (though not completely
understand) style sheets written in levels of CSS that did not exist at
the time the UAs were created. Designers can use this feature to
create style sheets that work with older user agents, while also
exercising the possibilities of the latest levels of CSS.
</p>
<p>At the lexical level, CSS style sheets consist of a sequence of tokens.
The list of tokens for CSS is as follows. The definitions use Lex-style
regular expressions. Octal codes refer to ISO 10646 ([[!ISO10646]]). As in
Lex, in case of multiple matches, the longest match determines the token.
</p>
<table>
<thead>
<tr><th>Token		<th>Definition</tr>
</thead>
<tr><td colspan="2"><hr></tr>
<tr><td>IDENT		<td><code><var>{ident}</var></code></tr>
<tr><td>ATKEYWORD	<td><code>@<var>{ident}</var></code></tr>
<tr><td>STRING		<td><code><var>{string}</var></code></tr>
<tr><td>BAD_STRING      <td><code><var>{badstring}</var></code></tr>
<tr><td>BAD_URI         <td><code><var>{baduri}</var></code></tr>
<tr><td>BAD_COMMENT     <td><code><var>{badcomment}</var></code></tr>
<tr><td>HASH		<td><code>#<var>{name}</var></code></tr>
<tr><td>NUMBER		<td><code><var>{num}</var></code></tr>
<tr><td>PERCENTAGE	<td><code><var>{num}</var>%</code></tr>
<tr><td>DIMENSION	<td><code><var>{num}{ident}</var></code></tr>
<tr><td>URI		<td><code>url\(<var>{w}{string}{w}</var>\)<br>
		|url\(<var>{w}</var>([!#$%&amp;*-\[\]-~]|<var>{nonascii}</var>|<var>{escape}</var>)*<var>{w}</var>\)</code></tr>
<tr><td>UNICODE-RANGE	<td><code>u\+[0-9a-f?]{1,6}(-[0-9a-f]{1,6})?</code></tr>
<tr><td>CDO		<td><code>&lt;!--</code></tr>
<tr><td>CDC		<td><code>--&gt;</code></tr>
<tr><td>:		<td><code>:</code></tr>
<tr><td>;		<td><code>;</code></tr>
<tr><td>{		<td><code>\{</code></tr>
<tr><td>}		<td><code>\}</code></tr>
<tr><td>(		<td><code>\(</code></tr>
<tr><td>)		<td><code>\)</code></tr>
<tr><td>[		<td><code>\[</code></tr>
<tr><td>]		<td><code>\]</code></tr>
<tr><td>S		<td><code>[ \t\r\n\f]+</code></tr>
<tr><td>COMMENT		<td><code>\/\*[^*]*\*+([^/*][^*]*\*+)*\/</code></tr>
<tr><td>FUNCTION	<td><code><var>{ident}</var>\(</code></tr>
<tr><td>INCLUDES	<td><code>~=</code></tr>
<tr><td>DASHMATCH	<td><code>|=</code></tr>
<tr><td>DELIM		<td><var>any other character not matched by
the above rules, and neither a single nor a double quote</var>
</table>

<p>The macros in curly braces ({}) above are defined as follows:
</p>
<table>
<thead>
<tr><th>Macro	<th>Definition</tr>
</thead>
<tr><td colspan="2"><hr></tr>
<tr><td>ident	<td><code>[-]?<var>{nmstart}</var><var>{nmchar}*</var></code></tr>
<tr><td>name	<td><code><var>{nmchar}+</var></code></tr>
<tr><td>nmstart	<td><code>[_a-z]|<var>{nonascii}</var>|<var>{escape}</var></code></tr>
<tr><td>nonascii<td><code>[^\0-\237]</code></tr>
<tr><td>unicode	<td><code>\\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])?</code></tr>
<tr><td>escape	<td><code><var>{unicode}</var>|\\[^\n\r\f0-9a-f]</code></tr>
<tr><td>nmchar	<td><code>[_a-z0-9-]|<var>{nonascii}</var>|<var>{escape}</var></code></tr>
<tr><td>num	<td><code>[0-9]+|[0-9]*\.[0-9]+</code></tr>
<tr><td>string	<td><code><var>{string1}</var>|<var>{string2}</var></code></tr>
<tr><td>string1	<td><code>\"([^\n\r\f\\"]|\\{nl}|<var>{escape}</var>)*\"</code></tr>
<tr><td>string2	<td><code>\'([^\n\r\f\\']|\\{nl}|<var>{escape}</var>)*\'</code></tr>
<tr><td>badstring   <td><code><var>{badstring1}</var>|<var>{badstring2}</var></code></tr>
<tr><td>badstring1  <td><code>\"([^\n\r\f\\"]|\\{nl}|<var>{escape}</var>)*\\?</code></tr>
<tr><td>badstring2  <td><code>\'([^\n\r\f\\']|\\{nl}|<var>{escape}</var>)*\\?</code></tr>
<tr><td>badcomment  <td><code><var>{badcomment1}</var>|<var>{badcomment2}</var></code></tr>
<tr><td>badcomment1 <td><code>\/\*[^*]*\*+([^/*][^*]*\*+)*</code></tr>
<tr><td>badcomment2 <td><code>\/\*[^*]*(\*+[^/*][^*]*)*</code></tr>
<tr><td>baduri      <td><code><var>{baduri1}</var>|<var>{baduri2}</var>|<var>{baduri3}</var></code></tr>
<tr><td>baduri1     <td><code>url\(<var>{w}</var>([!#$%&amp;*-~]|<var>{nonascii}</var>|<var>{escape}</var>)*<var>{w}</var></code></tr>
<tr><td>baduri2     <td><code>url\(<var>{w}</var><var>{string}</var><var>{w}</var></code></tr>
<tr><td>baduri3     <td><code>url\(<var>{w}</var><var>{badstring}</var></code></tr>
<tr><td>nl	<td><code>\n|\r\n|\r|\f</code></tr>
<tr><td>w	<td><code>[ \t\r\n\f]*</code></tr>
</table>

<div class="example">
<p>For example, the rule of the longest match means that
"<code>red--&gt;</code>" is tokenized as the IDENT "<code>red--</code>"
followed by the DELIM "<code>&gt;</code>", rather than as an IDENT
followed by a CDC.
</div>

<p>Below is the core syntax for CSS. The sections that follow describe
how to use it. <a href="#app-grammar">Appendix G</a> describes a
more restrictive grammar that is closer to the CSS level 2 language.
Parts of style sheets that can be parsed according to this grammar but
not according to the grammar in Appendix G are among the parts that
will be ignored according to the <a href="#parsing-errors">rules for
handling parsing errors</a>.
</p>
<pre>
stylesheet  : [ CDO | CDC | S | statement ]*;
statement   : ruleset | at-rule;
at-rule     : ATKEYWORD S* any* [ block | ';' S* ];
block       : '{' S* [ any | block | ATKEYWORD S* | ';' S* ]* '}' S*;
ruleset     : selector? '{' S* declaration? [ ';' S* declaration? ]* '}' S*;
selector    : any+;
declaration : property S* ':' S* value;
property    : IDENT;
value       : [ any | block | ATKEYWORD S* ]+;
any         : [ IDENT | NUMBER | PERCENTAGE | DIMENSION | STRING
              | DELIM | URI | HASH | UNICODE-RANGE | INCLUDES
              | DASHMATCH | ':' | FUNCTION S* [any|unused]* ')'
              | '(' S* [any|unused]* ')' | '[' S* [any|unused]* ']'
              ] S*;
unused      : block | ATKEYWORD S* | ';' S* | CDO S* | CDC S*;
</pre>

<p>The "unused" production is not used in CSS and will not be used by
any future extension. It is included here only to help with error
handling. (See <a href="#parsing-errors">4.2 "Rules for handling
parsing errors."</a>)

<p><span id="comment">COMMENT</span> tokens do not occur
in the grammar (to keep it readable), but any number of these tokens
may appear anywhere outside other tokens. (Note, however, that a
comment before or within the @charset rule disables the @charset.)</p>

<p>The token S in the grammar above stands for <span id="whitespace">white space</span>. Only the characters "space" (<!--Unicode
code 32-->U+0020), "tab" (U+0009), "line feed" (<!--10-->U+000A), "carriage return" (<!--13-->U+000D), and
"form feed" (<!--12-->U+000C) can occur in white space. Other space-like characters,
such as "em-space" (<!--8195-->U+2003) and "ideographic space" (<!--12288-->U+3000), are never part of white space.
</p>
<p>The meaning of input that cannot be tokenized or parsed is
undefined in CSS&nbsp;2.
</p>

<h4 id="keywords">Keywords</h4>

<!-- provide better explanation of where keywords appear:
media types, at-rules, etc. -IJ -->

<p>Keywords have the form of <a href="#value-def-identifier">identifiers.</a> Keywords must not be
placed between quotes ("..." or ''...''). Thus,
</p>
<pre>
red
</pre>

<p>is a keyword, but
</p>
<pre>
"red"
</pre>

<p>is not. (It is a <a href="#strings">string</a>.) Other illegal examples:

<div class="illegal example">
<pre><code>
width: "auto";
border: "none";
background: "red";
</code></pre>
</div>

<h5 id="vendor-keywords">Vendor-specific extensions</h5>

<p>In CSS, identifiers may begin with '<code>-</code>' (dash) or '<code>_</code>' (underscore). Keywords
and <a href="#properties">property names</a> beginning
with <code>-</code>' or '<code>_</code>' are reserved for vendor-specific extensions. Such vendor-specific extensions should have one of the following formats:
</p>
<pre>
'-' + vendor identifier + '-' + meaningful name
'_' + vendor identifier + '-' + meaningful name
</pre>
<div class="example">
<p>For example, if XYZ organization added a property to describe the color of the
border on the East side of the display, they might call it <span class="css">-xyz-border-east-color</span>.
</p>
<p>Other known examples:</p>
<pre>
-moz-box-sizing
-moz-border-radius
-wap-accesskey
</pre>
</div>
<p>An initial dash or underscore is guaranteed never to be used in a property or keyword by any current or future level of CSS. Thus typical CSS implementations may not
recognize such properties and may ignore them according to the <a href="#parsing-errors">rules for handling parsing errors</a>. However, because the initial dash or underscore is part of the grammar, CSS&nbsp;2 implementers should always be able to use a CSS-conforming parser, whether or not they support any vendor-specific extensions.
</p>

<p>Authors should avoid vendor-specific extensions</p>

<section class="non-normative">
<h5 id="vendor-keyword-history">Informative Historical Notes</h5>
<p>This section is informative.</p>
<p>At the time of writing, the following prefixes are known to exist:</p>

<table>
<thead><tr><th>prefix<th>organization</thead>
<tbody>
<tr><td><code>-ms-</code>, <code>mso-</code><td>Microsoft</tr>
<tr><td><code>-moz-</code><td>Mozilla</tr>
<tr><td><code>-o-</code>, <code>-xv-</code><td>Opera Software</tr>
<tr><td><code>-atsc-</code><td>Advanced Television Standards Committee</tr>
<tr><td><code>-wap-</code><td>The WAP Forum</tr>
<tr><td><code>-khtml-</code><td>KDE</tr>
<tr><td><code>-webkit-</code><td>Apple</tr>
<tr><td><code>prince-</code><td>YesLogic</tr>
<tr><td><code>-ah-</code><td>Antenna House</tr>
<tr><td><code>-hp-</code><td>Hewlett Packard</tr>
<tr><td><code>-ro-</code><td>Real Objects</tr>
<tr><td><code>-rim-</code><td>Research In Motion</tr>
<tr><td><code>-tc-</code><td>TallComponents</tr>
</tbody>
</table>
</section>

<h4 id="characters">Characters and case</h4>
<p>  The following rules always hold:</p>

<ul>
    <li> All CSS syntax is case-insensitive within the ASCII
    range (i.e., [a-z] and \[A-Z] are equivalent), except for parts that are
    not under the control of CSS. For example, the case-sensitivity of
    values of the HTML attributes "id" and "class", of font names, and
    of URIs lies outside the scope of this specification. Note in
    particular that element names are case-insensitive in HTML, but
    case-sensitive in XML.
    </li>

    <li> In CSS, <dfn id="value-def-identifier" dfn-type="type" data-lt="identifiers|&lt;identifier&gt;">identifiers</dfn>
    (including element names, classes, and IDs in <a href="#selector">selectors</a>) can contain only the
    characters [a-zA-Z0-9] and ISO 10646 characters  U+00A0 and higher,
    plus the hyphen (-) and the underscore (_); they cannot start with
    a digit, two hyphens, or a hyphen followed by a digit.
    Identifiers can also contain escaped characters and any ISO 10646
    character as a numeric code (see next item).
    <span class="example">For instance, the identifier "B&amp;W?" may
    be written as "B\&amp;W\?" or "B\26 W\3F".</span>
    <p>Note that Unicode is code-by-code equivalent to ISO 10646 (see
    [[!UNICODE]] and [[!ISO10646]]).
    </p>
    </li>
    <li> In CSS&nbsp;2, a backslash (\) character can indicate one
    of three types of <dfn data-lt="backslash escapes" id="escaped-characters"> character
    escape.</dfn> Inside a CSS comment, a backslash stands for
    itself, and if a backslash is immediately followed by the end of
    the style sheet, it also stands for itself (i.e., a DELIM token).

    <p>First, inside a <a href="#strings">string</a>, a backslash
    followed by a newline is ignored (i.e., the string is deemed not
    to contain either the backslash or the newline).
    Outside a string, a backslash followed by a newline stands for
    itself (i.e., a DELIM followed by a newline).

    <p>Second, it cancels the meaning of special CSS characters.
        Any character (except a
        hexadecimal digit, linefeed, carriage return, or form feed)
        can be escaped
        with a backslash to remove its special meaning.
        For example, <samp>"\""</samp> is a string consisting of one
        double quote. Style sheet preprocessors must not remove
       these backslashes from a style sheet since that would
       change the style sheet's meaning.
    </p>
    <p>Third, backslash escapes allow authors to refer to characters
    they cannot easily put in a document. In this case, the backslash
    is followed by at most six hexadecimal digits (0..9A..F), which
    stand for the ISO 10646 ([[!ISO10646]])
    character with that number, which must not be zero.
    (It is undefined in CSS&nbsp;2 what happens if a style sheet
    <em>does</em> contain a character with Unicode codepoint zero.)
    If a character in the range [0-9a-fA-F] follows the hexadecimal number,
    the end of the number needs to be made clear. There are two ways
    to do that:
    </p>
    <ol>
    <li>with a space (or other white space character): "\26 B" ("&amp;B").
        In this case, user agents should treat a "CR/LF" pair
        (<!--13/10-->U+000D/U+000A) as a single white space character.</li>
    <li>by providing exactly 6 hexadecimal digits: "\000026B" ("&amp;B")</li>
    </ol>

    <p>In fact, these two methods may be combined. Only one white space
    character is ignored after a hexadecimal escape. Note that this means
    that a "real" space after the escape sequence must be
    doubled.
    </p>
    <p>If the number is outside the range allowed by Unicode (e.g.,
    "\110000" is above the maximum 10FFFF allowed in current Unicode),
    the UA may replace the escape with the "replacement character"
    (U+FFFD). If the character is to be displayed, the UA should show
    a visible symbol, such as a "missing character" glyph (cf. <a href="#algorithm">15.2,</a> point 5).
    </li>
    <li class="note">Note: Backslash escapes are always
    considered to be part of an <a href="#value-def-identifier">identifier</a> or a string (i.e.,
    "\7B" is not punctuation, even though "{" is, and "\32" is allowed
    at the start of a class name, even though "2" is not).

    <p>The identifier "te\st" is exactly the same identifier as "test".
    </li>
  </ul>


<h4 id="statements">Statements</h4>

<p> A CSS style sheet, for any level of CSS, consists of a list of
<em>statements</em>
(see the <a href="#tokenization">grammar</a> above). There are two
kinds of statements: <a data-lt="at-rules"><em>at-rules</em></a>
and <a data-lt="rule sets"><em>rule
sets.</em></a> There may be <a href="#whitespace">white space</a>
around the statements.
</p>

<h4 id="at-rules"><dfn id="at-rules-dfn">
At-rules</dfn></h4>

<p> At-rules start with an <dfn>at-keyword</dfn>, an ''@'' character
followed immediately by an <a href="#value-def-identifier">identifier</a> (for example, ''@import'',
''@page'').
</p>
<p> An at-rule consists of everything up to and including the next
semicolon (;) or the next <a href="#block">block,</a> whichever comes
first.
</p>

<p>CSS&nbsp;2 user agents must <a data-lt="ignore" href="#ignore">ignore</a> any ''@import'' rule that occurs inside a <a href="#block">block</a> or after any non-ignored statement other than an <a data-lt="">@charset</a> or an @import rule.
</p>

<div class="illegal example"><p>
Assume, for example, that a CSS&nbsp;2 parser encounters this style sheet:
</p>
<pre class="lang-css"><code>
@import "subs.css";
h1 { color: blue }
@import "list.css";
</code></pre>

<p> The second ''@import'' is illegal according to CSS&nbsp;2. The CSS&nbsp;2 parser
<a data-lt="ignore" href="#ignore">ignores</a>
the whole at-rule, effectively reducing the style sheet to:
</p>
<pre class="lang-css">
@import "subs.css";
h1 { color: blue }
</pre>
</div>

<div class="illegal example"><p>
In the following example, the second ''@import'' rule is invalid,
since it occurs inside a ''@media'' <a href="#block">block</a>.
</p>
<pre class="lang-css"><code>
@import "subs.css";
@media print {
  @import "print-main.css";
  body { font-size: 10pt }
}
h1 {color: blue }
</code></pre>
<p>Instead, to achieve the effect of only importing a style sheet
for ''print'' media, use the @import rule with media syntax, e.g.:
</p>
<pre class="lang-css">
@import "subs.css";
@import "print-main.css" print;
@media print {
  body { font-size: 10pt }
}
h1 {color: blue }
</pre>

</div>

<h4 id="block">Blocks</h4>

<p> A <a data-lt="block"><em>block</em></a>
starts with a left curly brace ({) and ends with the matching right
curly brace (}). In between there may be any tokens, except that
parentheses ((&nbsp;)), brackets ([&nbsp;]), and braces ({&nbsp;}) must
always occur in
matching pairs and may be nested. Single (') and double quotes (")
<!-- " --> must also occur in matching pairs, and characters between them
are parsed as a <a data-lt="string">string</a>.
See <a href="#tokenization">Tokenization</a> above for the definition
of a string.
</p>

<div class="illegal example">
<p> Here is an example of a block. Note that the right brace between
the double quotes does not match the opening brace of the block, and that the
second single quote is an <a href="#escaped-characters">escaped
character</a>, and thus does not match the first single quote:
</p>
<pre class="lang-css"><code>
{ causta: "}" + ({7} * '\'') }
</code></pre>

<p>Note that the above rule is not valid CSS&nbsp;2, but it is still
a block as defined above.
</p>
</div>

<h4 id="rule-sets">Rule sets, declaration blocks, and selectors</h4>

<p> A <dfn id="rule-sets-dfn">rule set</dfn> (also called "rule") consists of a selector followed by
a declaration block.
</p>
<p> A <dfn>declaration block</dfn>
starts with a left curly
brace ({) and ends with the matching right curly brace (}). In between
there must be a list of zero or more semicolon-separated (;)
declarations.
</p>
<p>The <a>selector</a> consists of everything up to (but
not including) the first left curly brace ({).  A selector always goes
together with a declaration block. When a user agent cannot parse the selector (i.e., it
is not valid CSS&nbsp;2), it must <a data-lt="ignore" href="#ignore">ignore</a> the selector and the following
declaration block (if any) as well.
</p>
<p>CSS&nbsp;2 gives a special meaning to the comma (,) in
selectors. However, since it is not known if the comma may acquire
other meanings in future updates of CSS, the whole statement should
be <a data-lt="ignore" href="#ignore">ignored</a> if there is an error anywhere in the
selector, even though the rest of the selector may look reasonable in
CSS&nbsp;2.
</p>
<div class="illegal example">
<p>For example, since the "&amp;" is not a valid token in a CSS&nbsp;2
selector, a CSS&nbsp;2 user agent must
<a data-lt="ignore" href="#ignore">ignore</a>
the whole second line, and not set the color of H3 to red:
</p>
<pre class="lang-css"><code>
h1, h2 {color: green }
h3, h4 &amp; h5 {color: red }
h6 {color: black }
</code></pre>
</div>

<div class="example">
<p>Here is a more complex example. The first two pairs of curly braces
are inside a string, and do not mark the end of the selector. This is
a valid CSS&nbsp;2 rule.
</p>
<pre class="lang-css">
p[example="public class foo\
{\
    private int x;\
\
    foo(int x) {\
        this.x = x;\
    }\
\
}"] { color: red }
</pre>
</div>

<h4 id="declaration">Declarations and <span id="properties">properties</span></h4>

<p> A <dfn>declaration</dfn> is either empty or
consists of a <a data-lt="property">property name</a>, followed by a colon (:), followed by
a property value. Around each of these there may be <a href="#whitespace">white space</a>.
</p>
<p>Because of the way selectors work, multiple declarations for the
same selector may be organized into semicolon (;) separated
groups.</p>

<div class="example"><p>
Thus, the following rules:</p>
<pre class="lang-css">
h1 { font-weight: bold }
h1 { font-size: 12px }
h1 { line-height: 14px }
h1 { font-family: Helvetica }
h1 { font-variant: normal }
h1 { font-style: normal }
</pre>

<p>are equivalent to:</p>

<pre class="lang-css">
h1 {
  font-weight: bold;
  font-size: 12px;
  line-height: 14px;
  font-family: Helvetica;
  font-variant: normal;
  font-style: normal
}
</pre>
</div>

<p>A property name is an <a href="#value-def-identifier">identifier</a>. Any token may occur
in the property value.  Parentheses ("(&nbsp;)"), brackets ("[&nbsp;]"),
braces ("{&nbsp;}"), single
quotes ('), and double quotes (") <!-- " --> must come in matching
pairs, and semicolons not in strings must be <a href="#escaped-characters">escaped</a>. Parentheses, brackets, and
braces may be nested. Inside the quotes, characters are parsed as a
string.
</p>
<p>The syntax of <dfn>values</dfn>
is specified separately for each property, but in any case, values are
built from identifiers, strings, numbers, lengths, percentages, URIs,
colors, etc.
</p>
<p>A user agent must <a data-lt="ignore" href="#ignore">ignore</a> a declaration with an invalid property
name or an invalid value. Every CSS property has its own syntactic
and semantic restrictions on the values it accepts.
</p>
<div class="illegal example"><p>
For example, assume a CSS&nbsp;2 parser encounters this style sheet:
</p>
<pre class="lang-css"><code>
h1 { color: red; font-style: 12pt }  /* Invalid value: 12pt */
p { color: blue;  font-vendor: any;  /* Invalid prop.: font-vendor */
    font-variant: small-caps }
em em { font-style: normal }
</code></pre>

<p> The second declaration on the first line has an invalid value
''12pt''. The second declaration on the second line contains an
undefined property ''font-vendor''. The CSS&nbsp;2 parser will <a data-lt="ignore" href="#ignore">ignore</a> these
declarations, effectively reducing the style sheet to:
</p>
<pre class="example lang-css"><code>
h1 { color: red; }
p { color: blue;  font-variant: small-caps }
em em { font-style: normal }
</code></pre>
</div>

<h4 id="comments">Comments</h4>

<p><dfn>Comments</dfn> begin
with the characters "/*" and end with the characters "*/". They may
occur anywhere outside other tokens,
and their contents have no influence on the rendering.  Comments may
not be nested.
</p>
<p>CSS also allows the SGML comment delimiters ("&lt;!--" and
"--&gt;") in certain places defined by the grammar, but they do not
delimit CSS
comments. They are permitted so that style rules appearing in an HTML
source document (in the STYLE element) may be hidden from pre-HTML 3.2
user agents. See the HTML 4 specification ([[HTML401]]) for more information.
</p>

<h3 id="parsing-errors">Rules for handling parsing
errors</h3>

<p>In some cases, user agents must ignore part of an illegal style
sheet. This specification defines <dfn id="ignore">ignore</dfn> to mean
that the user agent parses the illegal part (in order to find its
beginning and end), but otherwise acts as if it had not been there.
CSS&nbsp;2 reserves for future updates of CSS all property:value combinations
and @-keywords that do not contain an identifier beginning with dash or
underscore. Implementations must ignore such combinations (other than those
introduced by future updates of CSS).
</p>
<!-- How are "beginning" and "end" defined? -IJ -->

<p>To ensure that new properties and new values for existing
properties can be added in the future, user agents are required to
obey the following rules when they encounter the following
scenarios:</p>

<ul>
<li><strong>Unknown properties.</strong> User agents must <a data-lt="ignore" href="#ignore">ignore</a> a <a href="#declaration">declaration</a> with an unknown
property. For example, if the style sheet is:

<pre class="illegal example lang-css">
h1 { color: red; rotation: 70minutes }
</pre>

<p> the user agent will treat this as if the style sheet had been
</p>
<pre class="example lang-css"><code>
h1 { color: red }
</code></pre>
</li>
<li id="illegalvalues"><strong>Illegal values.</strong> User agents must ignore a
declaration with an illegal value. For example:

<pre class="illegal example lang-css"><code>
img { float: left }       /* correct CSS&nbsp;2 */
img { float: left here }  /* "here" is not a value of 'float' */
img { background: "red" } /* keywords cannot be quoted */
img { border-width: 3 }   /* a unit must be specified for length values */
</code></pre>

A CSS&nbsp;2 parser would honor the first rule and
<a data-lt="ignore" href="#ignore">ignore</a>
the rest, as if the style sheet had been:

<pre class="example lang-css"><code>
img { float: left }
img { }
img { }
img { }
</code></pre>

<p>A user agent conforming to a future CSS specification may accept one or
more of the other rules as well.</p>
</li>
<li><strong>Malformed declarations.</strong> User agents must handle
unexpected tokens encountered while parsing a declaration by reading
until the end of the declaration, while observing the rules for matching
pairs of (), [], {}, "", and &apos;&apos;, and correctly handling escapes. For
example, a malformed declaration may be missing a property name, colon (:), or
property value. The following are all equivalent:


<pre class="example lang-css"><code>
p { color:green }
p { color:green; color }  /* malformed declaration missing ':', value */
p { color:red;   color; color:green }  /* same with expected recovery */
p { color:green; color: } /* malformed declaration missing value */
p { color:red;   color:; color:green } /* same with expected recovery */
p { color:green; color{;color:maroon} } /* unexpected tokens { } */
p { color:red;   color{;color:maroon}; color:green } /* same with recovery */
</code></pre>

</li>


<li><strong>Malformed statements.</strong> User agents must handle
unexpected tokens encountered while parsing a statement by reading
until the end of the statement, while observing the rules for matching
pairs of (), [], {}, "", and &apos;&apos;, and correctly handling escapes. For
example, a malformed statement may contain an unexpected closing brace
or at-keyword. E.g., the following lines are all ignored:

<!-- An unexpected token when parsing the stylesheet production is
considered to be the start of a (malformed) ruleset, which ends at
the next balanced {} pair at top level. -->

<pre class="lang-css">
p @here {color: red}     /* ruleset with unexpected at-keyword "@here" */
@foo @bar;               /* at-rule with unexpected at-keyword "@bar" */
}} {{ - }}               /* ruleset with unexpected right brace */
) ( {} ) p {color: red } /* ruleset with unexpected right parenthesis */
</pre>

<!-- Note that the ") (" in the last line do not count as a balanced
pair. -->

<li><strong>At-rules with unknown at-keywords.</strong> User agents must <a data-lt="ignore" href="#ignore">ignore</a>
an invalid at-keyword together with everything following it, up to the
end of the block that contains the invalid at-keyword, or up to and
including the next semicolon (;), or up to and including the next
block ({...}), whichever comes first. For example, consider the
following:

<pre class="illegal example lang-css"><code>
@three-dee {
  @background-lighting {
    azimuth: 30deg;
    elevation: 190deg;
  }
  h1 { color: red }
}
h1 { color: blue }
</code></pre>

<p> The ''@three-dee'' at-rule is not part of CSS&nbsp;2. Therefore, the whole
at-rule (up to, and including, the third right curly brace) is <a data-lt="ignore" href="#ignore">ignored.</a> A
CSS&nbsp;2 user agent <a data-lt="ignore" href="#ignore">ignores</a> it, effectively reducing the style sheet
to:</p>

<pre class="example lang-css"><code>
h1 { color: blue }
</code></pre>

<p>Something inside an at-rule that is ignored because it is invalid,
such as an invalid declaration within an @media-rule, does not make
the entire at-rule invalid.
</p>

</li>

<li id="unexpected-eof"><strong>Unexpected end of style sheet.</strong>
<p>
User agents must close all open constructs (for example: blocks, parentheses, brackets, rules, strings, and comments) at the end of the
style sheet. For example:
</p>
<pre class="illegal example lang-css"><code>
  @media screen {
    p:before { content: 'Hello
</code></pre>
<p>
would be treated the same as:
</p>
<pre class="example lang-css"><code>
  @media screen {
    p:before { content: 'Hello'; }
  }
</code></pre>
<p>
in a conformant UA.
</p>
</li>
<li><strong>Unexpected end of string.</strong>
<p>
   User agents must close strings upon reaching the end of a line
   (i.e., before an unescaped line feed, carriage return or form
   feed character), but
   then drop the construct (declaration or rule) in which the string
   was found. For example:
</p>
<pre class="lang-css"><code>
      p {
        color: green;
        font-family: 'Courier New Times
        color: red;
        color: green;
      }
</code></pre>
<p>
   ...would be treated the same as:
</p>
<pre class="lang-css">
      p { color: green; color: green; }
</pre>
<p>
   ...because the second declaration (from 'font-family' to the
   semicolon after 'color: red') is invalid and is dropped.
</p>
</li>
<li>See also <a href="#rule-sets">Rule sets, declaration blocks, and
selectors</a> for parsing rules for declaration blocks.
</li>
</ul>

<!--
<p>How to handle unparseable and untokenizable style sheets is
undefined in CSS&nbsp;2
</p>
-->

<h3 id="values">Values</h3>

<h4 id="numbers">Integers and real numbers</h4>

<p>Some value types may have integer values (denoted by <dfn id="value-def-integer">&lt;integer&gt;</dfn>)
or real number values (denoted by <dfn id="value-def-number">&lt;number&gt;</dfn>).  Real numbers and
integers are specified in decimal notation only. An &lt;integer&gt;
consists of one or more digits "0" to "9". A &lt;number&gt; can either
be an &lt;integer&gt;, 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.
\-0 is equivalent to 0 and is not a negative number.</p>

<p>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.
</p>

<h4 id="length-units">Lengths</h4>

<p>Lengths refer to distance measurements.</p>

<p> The format of a length value (denoted by <dfn id="value-def-length">&lt;length&gt;</dfn> in this specification) is
a <span class="value-inst-number">&lt;number&gt;</span> (with or without a
decimal point) immediately followed by a unit identifier (e.g., px,
em, etc.). After a zero length, the unit identifier is optional.
</p>
<p> Some properties allow negative length values, but this may
complicate the formatting model and there may be
implementation-specific limits. If a negative length value cannot be
supported, it should be converted to the nearest value that can be
supported.
</p>
<p>If a negative length value is set on a property that does not allow
   negative length values, the declaration is ignored.
</p>

<p>In cases where the <a href="#usedValue">used</a>
length cannot be supported, user agents must approximate it in the
<a href="#actual-value">actual value.</a>

<p><span id="absrel-units">There are two types of length units:
relative and absolute.</span> <dfn data-lt="relative units"><em>Relative length</em></dfn> units specify a length relative

to another length property. Style sheets that use relative units
can more easily scale from one output environment
to another.
</p>
<p>Relative units are:</p>
<ul>
<li><strong>em</strong>: the 'font-size' of the relevant font</li>
<li><strong>ex</strong>: the <span class="descinst">''x-height''</span> of the relevant font</li>

</ul>

<div class="example">
<pre class="lang-css">
h1 { margin: 0.5em }      /* em */
h1 { margin: 1ex }        /* ex */
</pre>
</div>

<p>The <dfn dfn-for="<length>" dfn-type="value" id="em-width">em</dfn> unit is equal to the computed value of
the 'font-size' property of
the element on which it is used. The exception is when ''em'' occurs in
the value of the 'font-size' property itself, in which case it refers
to the font size of the parent element. It may be used for vertical or
horizontal measurement. (This unit is also sometimes called the
quad-width in typographic texts.)
</p>
<p>The <dfn dfn-for="<length>" dfn-type="value" id="ex">ex</dfn> unit is defined by the element's first available
font.
The exception is when ''ex'' occurs in the value of the 'font-size' property, in which case
it refers to the ''ex'' of the parent element.

<p>The <span class="descinst-x-height">''x-height''</span> is so called
because it is often equal to the height of the lowercase "x". However,
an ''ex'' is defined even for fonts that do not contain an "x".</p>
<p>The x-height of a font can be found in different ways. Some fonts
contain reliable metrics for the x-height. If reliable font metrics are
not available, UAs may determine the x-height from the height of a
lowercase glyph. One possible heuristic is to look at how far the glyph
for the lowercase "o" extends below the baseline, and subtract that value
from the top of its bounding box. In the cases where it is impossible or
impractical to determine the x-height, a value of 0.5em should be used.</p>
<div class="example">
<p>The rule:
</p>
<pre class="lang-css">
h1 { line-height: 1.2em }
</pre>

<p>means that the line height of "h1" elements will be 20% greater
than the font size of the "h1" elements. On the other hand:
</p>
<pre class="lang-css">
h1 { font-size: 1.2em }
</pre>

<p>means that the font-size of "h1" elements will be 20% greater than
the font size inherited by "h1" elements.</p>
</div>

<p>When specified for the root of the <a href="#doctree">
document tree</a> (e.g., "HTML" in HTML), ''em'' and ''ex'' refer to
the property's <a href="#initial-value">initial value</a>.
</p>

<p>Child elements do not inherit the relative values specified for
their parent; they inherit the <a href="#computed-value">computed values</a>.</p>

<div class="example"><p>
In the following rules, the computed 'text-indent' value of "h1" elements
will be 36px, not 45px, if "h1" is a child of the "body" element.
</p>
<pre class="lang-css">
body {
  font-size: 12px;
  text-indent: 3em;  /* i.e., 36px */
}
h1 { font-size: 15px }
</pre>
</div>

<p><dfn><em> Absolute
length</em></dfn>

units are fixed in relation to each other.
They are mainly useful
when the output
environment is known. The absolute units consist of the physical units
(in, cm, mm, pt, pc) and the px unit:

</p>
<ul dfn-for="<length>" dfn-type="value">
<li><dfn id="valdef-length-in">in</dfn>: inches &mdash; 1in is equal
                         to 2.54cm.</li>
<li><dfn id="valdef-length-cm">cm</dfn>: centimeters</li>
<li><dfn id="valdef-length-mm">mm</dfn>: millimeters</li>
<li><dfn id="valdef-length-pt">pt</dfn>: points &mdash; the points used by CSS are equal to
                         1/72nd of 1in. </li>
<li><dfn id="valdef-length-pc">pc</dfn>: picas &mdash; 1pc is equal
                         to 12pt.</li>
<li><dfn id="valdef-length-px">px</dfn>: pixel units &mdash; 1px is equal to 0.75pt.</li>
</ul>


<p>For a CSS device, these dimensions are either anchored (i) by
relating the physical units to their physical measurements, or
(ii) by relating the pixel unit to the <i>reference pixel</i>.
For print media and similar high-resolution devices, the anchor unit
should be one of the standard physical units (inches, centimeters, etc).
For lower-resolution devices, and devices with unusual viewing distances,
it is recommended instead that the anchor unit be the pixel unit. For
such devices it is recommended that the pixel unit refer to the whole
number of device pixels that best approximates the reference pixel.

<p class="note">Note that if the anchor unit is the pixel unit,
the physical units might not match their physical measurements.
Alternatively if the anchor unit is a physical unit, the pixel
unit might not map to a whole number of device pixels.</p>

<p class="note">Note that this definition of the pixel unit and
the physical units differs from previous versions of CSS. In
particular, in previous versions of CSS the pixel unit and the
physical units were not related by a fixed ratio: the physical
units were always tied to their physical measurements while the
pixel unit would vary to most closely match the reference pixel.
(This change was made because too much existing content relies
on the assumption of 96dpi, and breaking that assumption breaks
the content.)

<p>The <dfn data-lt="reference pixel|pixel"><em>reference pixel</em></dfn> is the
visual angle of one pixel on a device with a pixel density of 96dpi
and a distance from the reader of an arm's length. For a nominal arm's
length of 28 inches, the visual angle is therefore about 0.0213
degrees. For reading at arm's length, 1px thus corresponds to about
0.26&nbsp;mm (1/96&nbsp;inch).
</p>

<p>The image below illustrates the effect of viewing distance on
the size of a reference pixel: a reading distance of 71&nbsp;cm
(28&nbsp;inches) results in a reference pixel of 0.26&nbsp;mm,
while a reading distance of 3.5&nbsp;m (12&nbsp;feet) results in
a reference pixel of 1.3&nbsp;mm.
</p>

<div class="figure">
<p><img src="images/pixel1.png" alt="Showing that pixels must become larger if the viewing distance increases" id="img-pixel1"></p>
</div>

<p>This second image illustrates the effect of a device's resolution
on the pixel unit: an area of 1px by 1px is covered by a single dot
in a low-resolution device (e.g. a typical computer display), while
the same area is covered by 16 dots in a higher resolution device
(such as a printer).
</p>

<div class="figure">
<p><img src="images/pixel2.png" alt="Showing that more device pixels (dots) are needed to cover a 1px by 1px area on a high-resolution device than on a low-res one" id="img-pixel2"></p>
</div>


<div class="example">
<pre class="lang-css">
h1 { margin: 0.5in }      /* inches  */
h2 { line-height: 3cm }   /* centimeters */
h3 { word-spacing: 4mm }  /* millimeters */
h4 { font-size: 12pt }    /* points */
h4 { font-size: 1pc }     /* picas */
p  { font-size: 12px }    /* px */
</pre>
</div>

<h4 id="percentage-units"> Percentages</h4>

<p> The format of a percentage value (denoted by <dfn id="value-def-percentage">&lt;percentage&gt;</dfn> in this specification)
is a <<number>> immediately
followed by <css>%</css>.
</p>
<p> 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 <a href="#containing-block">containing block</a>). When a
percentage value is set for a property of the <a href="#root">root</a> element and the percentage is
defined as referring to the inherited value of some property, the
resultant value is the percentage times the <a href="#initial-value">initial value</a> of that property.
</p>
<div class="example"><p>
Since child elements (generally) inherit the <a href="#computed-value">computed values</a> of their parent, in
the following example, the children of the P element will inherit a
value of 12px for 'line-height', not the percentage
value (120%):
</p>
<pre class="lang-css">
p { font-size: 10px }
p { line-height: 120% }  /* 120% of 'font-size' */
</pre>
</div>

<h4 id="uri">URLs and URIs</h4>

<p>URI values (Uniform Resource Identifiers, see [[!RFC3986]], which
includes URLs, URNs, etc) in this specification are denoted by <dfn id="value-def-uri">&lt;uri></dfn>.  The
functional notation used to designate URIs in property values is
"url()", as in:
</p>
<div class="example">
<pre class="lang-css">
body { background: url("http://www.example.com/pinkish.png") }
</pre>
</div>

<p> The format of a URI value is ''url('' followed by optional <a href="#whitespace">white space</a> followed by an optional single quote
(') or double quote (") character followed by the URI
itself, followed by an optional single quote (') or double quote (")
character followed by optional white space followed by
'')''. The two quote characters must be the same.
</p>
<div class="example"><p>An example without quotes:
</p>
<pre class="lang-css"><code>
li { list-style: url(http://www.example.com/redball.png) disc }
</code></pre>
</div>

<p>
Some characters appearing in an unquoted URI, such as parentheses,
white space characters, single quotes (') and double quotes
("), must be escaped with a backslash so that the resulting URI value
is a URI token: ''\('', ''\)''.
</p>
<p>Depending on the type of URI, it might also be possible to write
the above characters as URI-escapes (where "(" = %28, ")" = %29, etc.)
as described in [[!RFC3986]].
</p>
<div class="note">
<p><em>Note that COMMENT tokens cannot occur within other tokens:
thus, "url(/*x*/pic.png)" denotes the URI "/*x*/pic.png", not
"pic.png".</em>
</div>

<p> In order to create modular style sheets that are not dependent on
the absolute location of a resource, authors may use relative URIs.
Relative URIs (as defined in [[!RFC3986]]) are resolved to full URIs
using a base URI. RFC&nbsp;3986, section&nbsp;5, defines the normative
algorithm for this process. For CSS style sheets, the base URI is that
of the style sheet, not that of the source document.
</p>
<div class="example">
<p>For example, suppose the following rule:</p>

<pre class="lang-css">
body { background: url("yellow") }
</pre>

<p>is located in a style sheet designated by the URI:</p>

<pre>
http://www.example.org/style/basic.css
</pre>

<p>The background of the source document's BODY will be tiled with
whatever image is described by the resource designated
by the URI
</p>
<pre>
http://www.example.org/style/yellow
</pre>
</div>

<p>User agents may vary in how they handle invalid URIs or URIs that
designate
unavailable or inapplicable resources.
</p>
<h4 id="counter">Counters</h4>

<p><dfn data-lt="&lt;counter&gt;" id="value-def-counter" dfn-type="type">Counters</dfn> are denoted by
case-sensitive identifiers (see the 'counter-increment' and
'counter-reset'
properties). To refer to the value of a counter, the notation
<dfn data-lt="counter()" dfn-type="function">
counter(&lt;identifier&gt;)</dfn> or 'counter(&lt;identifier&gt;,
&lt;'list-style-type'&gt;)', with optional white space separating the tokens,
is used. The default style is ''list-style-type/decimal''.
</p>
<p>To refer to a sequence of nested counters of the same name, the
notation is <dfn data-lt="counters()" dfn-type="function">counters(&lt;identifier&gt;, &lt;string&gt;)</dfn> or
'counters(&lt;identifier&gt;, &lt;string&gt;, &lt;'list-style-type'&gt;)'
with optional white space separating the tokens.
</p>
<p>See <a href="#scope">"Nested counters and scope"</a>
in the chapter on <a href="#generated-text">generated content</a> for
how user agents must determine the value or values of the counter. See
the definition of counter values of the 'content' property for how it must
convert these values to a string.
</p>
<p>In CSS&nbsp;2, the values of counters can
only be referred to from the 'content' property. Note that <css>none</css>
is a possible &lt;'list-style-type'&gt;: 'counter(x,
none)' yields an empty string.
</p>
<div class="example">
<p>Here is a style sheet that numbers paragraphs (p) for each chapter
(h1). The paragraphs are numbered with roman numerals, followed by a
period and a space:
</p>
<pre class="lang-css">
p {counter-increment: par-num}
h1 {counter-reset: par-num}
p:before {content: counter(par-num, upper-roman) ". "}
</pre>
</div>

<h4 id="color-units">Colors</h4>
<p>
A <dfn id="value-def-color">&lt;color&gt;</dfn>
is either a keyword or a numerical RGB specification.
</p>
<p dfn-for="<color>" dfn-type="value"> The list of color keywords is:
  <dfn id="valdef-color-aqua">aqua</dfn>,
  <dfn id="valdef-color-black">black</dfn>,
  <dfn id="valdef-color-blue">blue</dfn>,
  <dfn id="valdef-color-fuchsia">fuchsia</dfn>,
  <dfn id="valdef-color-gray">gray</dfn>,
  <dfn id="valdef-color-green">green</dfn>,
  <dfn id="valdef-color-lime">lime</dfn>,
  <dfn id="valdef-color-maroon">maroon</dfn>,
  <dfn id="valdef-color-navy">navy</dfn>,
  <dfn id="valdef-color-olive">olive</dfn>,
  <dfn id="valdef-color-orange">orange</dfn>,
  <dfn id="valdef-color-purple">purple</dfn>,
  <dfn id="valdef-color-red">red</dfn>,
  <dfn id="valdef-color-silver">silver</dfn>,
  <dfn id="valdef-color-teal">teal</dfn>,
  <dfn id="valdef-color-white">white</dfn>,
  and
  <dfn id="valdef-color-yellow">yellow</dfn>.
  These 17 colors have the following values:
</p>

<div class="colordiagram" id="TanteksColorDiagram20020613">
<div class="diagramrow">
<span class="colorsquare" style="background:maroon;color:white"><span class="colorname">maroon</span> #800000
</span><span class="colorsquare" style="background:red"><span class="colorname">red</span> #ff0000
</span><span class="colorsquare" style="background:orange"><span class="colorname">orange</span> #ffA500
</span><span class="colorsquare" style="background:yellow"><span class="colorname">yellow</span> #ffff00
</span><span class="colorsquare" style="background:olive;color:white"><span class="colorname">olive</span> #808000</span>
</div>
<div class="diagramrow">
<span class="colorsquare" style="background:purple;color:white"><span class="colorname">purple</span> #800080</span>
<span class="colorsquare" style="background:fuchsia"><span class="colorname">fuchsia</span> #ff00ff</span>
<span class="colorsquare" style="background:white"><span class="colorname">white</span> #ffffff</span>
<span class="colorsquare" style="background:lime"><span class="colorname">lime</span> #00ff00</span>
<span class="colorsquare" style="background:green;color:white"><span class="colorname">green</span> #008000</span>
</div>
<div class="diagramrow" style="padding:0 2.5em">
<span class="colorsquare" style="background:navy;color:white"><span class="colorname">navy</span> #000080</span>
<span class="colorsquare" style="background:blue"><span class="colorname">blue</span> #0000ff</span>
<span class="colorsquare" style="background:aqua"><span class="colorname">aqua</span> #00ffff</span>
<span class="colorsquare" style="background:teal;color:white"><span class="colorname">teal</span> #008080</span>
</div>
<div class="diagramrow" style="padding:0 5em">
<span class="colorsquare" style="background:black;color:white"><span class="colorname">black</span> #000000</span>
<span class="colorsquare" style="background:silver"><span class="colorname">silver</span> #c0c0c0</span>
<span class="colorsquare" style="background:gray;color:white"><span class="colorname">gray</span> #808080</span>
</div>
</div>

<p>
In addition to these color keywords, users may specify
keywords that correspond to the colors used by certain objects in the
user's environment. Please consult the section on <a href="#system-colors">system colors</a> for more information.
</p>

<div class="example">
<pre class="lang-css">
body {color: black; background: white }
h1 { color: maroon }
h2 { color: olive }
</pre>
</div>

<p>The RGB color model is used in numerical color
specifications. These examples all specify the same color:
</p>
<div class="example">
<pre class="lang-css">
em { color: #f00 }              /* #rgb */
em { color: #ff0000 }           /* #rrggbb */
em { color: rgb(255,0,0) }
em { color: rgb(100%, 0%, 0%) }
</pre>
</div>

<p> The format of an RGB value in hexadecimal notation is a ''#''
immediately followed by either three or six hexadecimal
characters. The three-digit RGB notation (#rgb) is converted into
six-digit form (#rrggbb) by replicating digits, not by adding
zeros. For example, #fb0 expands to #ffbb00. This ensures that
white (#ffffff) can be specified with the short notation (#fff) and
removes any dependencies on the color depth of the display.
</p>
<p> The format of an RGB value in the functional notation is ''rgb(''
followed by a comma-separated list of three numerical values (either
three integer values or three percentage values) followed by '')''.
The integer value 255 corresponds to 100%, and to F or FF in the
hexadecimal notation: rgb(255,255,255) = rgb(100%,100%,100%) =
#FFF. <a href="#whitespace">White space</a> characters are allowed
around the numerical values.
</p>
<p>All RGB colors are specified in the sRGB color space (see
[[!SRGB]]).  User agents may vary in the fidelity with which they
represent these colors, but using sRGB provides an unambiguous and
objectively measurable definition of what the color should be, which
can be related to international standards (see [[!COLORIMETRY]]).
</p>
<p><a href="#conformance">Conforming user agents</a> may
limit their color-displaying efforts to performing a gamma-correction
on them. sRGB specifies a display gamma of 2.2 under specified viewing
conditions. User agents should adjust the colors given in CSS such that,
in combination with an output device's "natural" display gamma, an
effective display gamma of 2.2 is produced. <!--See the section on <a href="colors.html#gamma-correction">gamma correction</a> for further
details.--> Note that only colors specified in CSS are affected; e.g.,
images are expected to carry their own color information.
</p>
<p>Values outside the device gamut should be clipped or
mapped into the gamut when the gamut is known: the red, green,
and blue values must be changed to fall within the range supported by
the device. User agents may perform higher quality mapping of colors
from one gamut to another. For a typical CRT monitor, whose device
gamut is the same as sRGB, the four rules below are equivalent:
</p>
<div class="example">
<pre class="lang-css">
em { color: rgb(255,0,0) }       /* integer range 0 - 255 */
em { color: rgb(300,0,0) }       /* clipped to rgb(255,0,0) */
em { color: rgb(255,-10,0) }     /* clipped to rgb(255,0,0) */
em { color: rgb(110%, 0%, 0%) }  /* clipped to rgb(100%,0%,0%) */
</pre>
</div>

<p>Other devices, such as printers, have different gamuts than sRGB;
some colors outside the 0..255 sRGB range will be representable
(inside the device gamut), while other colors inside the 0..255 sRGB
range will be outside the device gamut and will thus be mapped.
</p>
<div class="note"><p><em><strong>Note.</strong> Mapping or clipping of
color values should be done to the actual device gamut if known (which
may be larger or smaller than 0..255).</em>
</div>

<h4 id="strings">Strings</h4>

<p><dfn data-lt="&lt;string&gt;" id="value-def-string" dfn-type="type">Strings</dfn> can either be written
with double quotes or with single quotes. Double quotes cannot occur
inside double quotes, unless escaped (e.g., as ''\"'' or as
''\22''). Analogously for single quotes (e.g., "\'" or "\27").
</p>
<div class="example">
<pre>
"this is a 'string'"
"this is a \"string\""
'this is a "string"'
'this is a \'string\'&apos;
</pre>
</div>

<p>A string cannot directly contain a <a data-lt="newline">newline</a>.
To include a newline in a string, use an escape representing the line feed
character in ISO-10646 (U+000A), such as "\A" or "\00000a".
This character represents the generic notion of "newline" in CSS.
See the 'content' property for an example.
</p>
<p>It is possible to break strings over several lines, for aesthetic
or other reasons, but in such a case the newline itself has to be
escaped with a backslash (\). For instance, the following two
selectors are exactly the same:
</p>
<div class="example">
<pre class="lang-css">
a[title="a not s\
o very long title"] {/*...*/}
a[title="a not so very long title"] {/*...*/}
</pre>
</div>

<h4 id="unsupported-values">Unsupported Values</h4>

<p>If a UA does not support a particular value, it should <em>ignore</em> that
  value when parsing style sheets, as if that value was an
  <a href="#illegalvalues">illegal value</a>.  For example:
</p>
<div class="example">
<pre class="lang-css">
  h3 {
    display: inline;
    display: run-in;
  }
</pre>
</div>
<p>
A UA that supports the ''run-in'' value for the 'display' property will
accept the first display declaration and then "write over" that value with
the second display declaration. A UA that does not support the ''run-in''
value will process the first display declaration and ignore the second
display declaration.
</p>


<h3 id="charset">CSS style sheet representation</h3>

<p>A CSS style sheet is a sequence of characters from the Universal
Character Set (see [[!ISO10646]]). For transmission and
storage, these characters must be <dfn data-lt="character encoding">encoded</dfn> by a character encoding that
supports the set of characters available in US-ASCII (e.g., UTF-8, ISO
8859-x, SHIFT JIS, etc.).  For a good introduction to character sets
and character encodings, please consult the HTML 4
specification ([[HTML401]], chapter 5). See also the XML 1.0
specification ([[XML10]], sections 2.2 and 4.3.3, and Appendix F).
</p>
<p>When a style sheet is embedded in another document, such as in the
STYLE element or "style" attribute of HTML, the style sheet shares the
character encoding of the whole document.
</p>
<p>When a style sheet resides in a separate file, user agents must
observe the following priorities when
determining a style sheet's character
encoding (from highest priority to lowest):
</p>
<ol>
<li>An HTTP "charset" parameter in a "Content-Type" field
(or similar parameters in other protocols)</li>
<li><a data-lt="">BOM</a> and/or <a data-lt="">@charset</a> (see below)</li>
<li><code>&lt;link charset=""&gt;</code> or other metadata from the linking mechanism (if any)</li>
<li>charset of referring style sheet or document (if any)</li>
<li>Assume UTF-8</li>
</ol>

<p>Authors using an <a data-lt="">@charset</a> rule must
place the rule at the very beginning of the style sheet, preceded by
no characters. (If a byte order mark is appropriate for the encoding
used, it may precede the @charset rule.)
</p>

<p>After <dfn>"@charset"</dfn>, authors specify
the name of a character encoding (in quotes). For example:
</p>

<pre class="example lang-css"><code>
@charset "ISO-8859-1";
</code></pre>

<p>@charset must be written literally, i.e., the 10 characters
'@charset "' (lowercase, no backslash escapes), followed by the
encoding name, followed by ''";''.
</p>

<p>The name must be a charset name as described in the IANA registry.
See [[CHARSETS]] for a complete list of charsets. Authors should use
the charset names marked as "preferred MIME name" in the IANA
registry.
</p>

<p>User agents must support at least the <a data-lt="">UTF-8</a> encoding.
</p>
<p>User agents must ignore any @charset rule not at the beginning of the
style sheet. When user agents detect the character encoding using the
BOM and/or the @charset rule, they should follow the following rules:
</p>

<ul>

<li>Except as specified in these rules, all @charset rules are ignored.</li>

<li>The encoding is detected based on the stream of bytes that begins
the style sheet.  The following table gives a set of possibilities for
initial byte sequences (written in hexadecimal).  The first row that
matches the beginning of the style sheet gives the result of encoding
detection based on the BOM and/or @charset rule.  If no rows match, the
encoding cannot be detected based on the BOM and/or @charset rule.  The
notation (...)* refers to repetition for which the best match is the one
that repeats as few times as possible.  The bytes marked "XX" are those
used to determine the name of the encoding, by treating them, in the
order given, as a sequence of ASCII characters.  Bytes marked "YY" are
similar, but need to be transcoded into ASCII as noted.  User agents may
ignore entries in the table if they do not support any encodings
relevant to the entry.

<table>
<caption>Relationship between initial bytes of sheet and chosen encoding</caption>
<tr><th scope="col">Initial Bytes<th scope="col">Result</tr>
<tr><td>EF BB BF 40 63 68 61 72 73 65 74 20 22 (XX)* 22 3B<td>as specified</tr>
<tr><td>EF BB BF<td>UTF-8</tr>
<tr><td>40 63 68 61 72 73 65 74 20 22 (XX)* 22 3B<td>as specified</tr>
<tr><td>FE FF 00 40 00 63 00 68 00 61 00 72 00 73 00 65 00 74 00 20 00 22 (00 XX)* 00 22 00 3B<td>as specified (with BE endianness if not specified)</tr>
<tr><td>00 40 00 63 00 68 00 61 00 72 00 73 00 65 00 74 00 20 00 22 (00 XX)* 00 22 00 3B<td>as specified (with BE endianness if not specified)</tr>
<tr><td>FF FE 40 00 63 00 68 00 61 00 72 00 73 00 65 00 74 00 20 00 22 00 (XX 00)* 22 00 3B 00<td>as specified (with LE endianness if not specified)</tr>
<tr><td>40 00 63 00 68 00 61 00 72 00 73 00 65 00 74 00 20 00 22 00 (XX 00)* 22 00 3B 00<td>as specified (with LE endianness if not specified)</tr>
<tr><td>00 00 FE FF 00 00 00 40 00 00 00 63 00 00 00 68 00 00 00 61 00 00 00 72 00 00 00 73 00 00 00 65 00 00 00 74 00 00 00 20 00 00 00 22 (00 00 00 XX)* 00 00 00 22 00 00 00 3B<td>as specified (with BE endianness if not specified)</tr>
<tr><td>00 00 00 40 00 00 00 63 00 00 00 68 00 00 00 61 00 00 00 72 00 00 00 73 00 00 00 65 00 00 00 74 00 00 00 20 00 00 00 22 (00 00 00 XX)* 00 00 00 22 00 00 00 3B<td>as specified (with BE endianness if not specified)</tr>
<tr><td>00 00 FF FE 00 00 40 00 00 00 63 00 00 00 68 00 00 00 61 00 00 00 72 00 00 00 73 00 00 00 65 00 00 00 74 00 00 00 20 00 00 00 22 00 (00 00 XX 00)* 00 00 22 00 00 00 3B 00<td>as specified (with 2143 endianness if not specified)</tr>
<tr><td>00 00 40 00 00 00 63 00 00 00 68 00 00 00 61 00 00 00 72 00 00 00 73 00 00 00 65 00 00 00 74 00 00 00 20 00 00 00 22 00 (00 00 XX 00)* 00 00 22 00 00 00 3B 00<td>as specified (with 2143 endianness if not specified)</tr>
<tr><td>FE FF 00 00 00 40 00 00 00 63 00 00 00 68 00 00 00 61 00 00 00 72 00 00 00 73 00 00 00 65 00 00 00 74 00 00 00 20 00 00 00 22 00 00 (00 XX 00 00)* 00 22 00 00 00 3B 00 00<td>as specified (with 3412 endianness if not specified)</tr>
<tr><td>00 40 00 00 00 63 00 00 00 68 00 00 00 61 00 00 00 72 00 00 00 73 00 00 00 65 00 00 00 74 00 00 00 20 00 00 00 22 00 00 (00 XX 00 00)* 00 22 00 00 00 3B 00 00<td>as specified (with 3412 endianness if not specified)</tr>
<tr><td>FF FE 00 00 40 00 00 00 63 00 00 00 68 00 00 00 61 00 00 00 72 00 00 00 73 00 00 00 65 00 00 00 74 00 00 00 20 00 00 00 22 00 00 00 (XX 00 00 00)* 22 00 00 00 3B 00 00 00<td>as specified (with LE endianness if not specified)</tr>
<tr><td>40 00 00 00 63 00 00 00 68 00 00 00 61 00 00 00 72 00 00 00 73 00 00 00 65 00 00 00 74 00 00 00 20 00 00 00 22 00 00 00 (XX 00 00 00)* 22 00 00 00 3B 00 00 00<td>as specified (with LE endianness if not specified)</tr>
<tr><td>00 00 FE FF<td>UTF-32-BE</tr>
<tr><td>FF FE 00 00<td>UTF-32-LE</tr>
<tr><td>00 00 FF FE<td>UTF-32-2143</tr>
<tr><td>FE FF 00 00<td>UTF-32-3412</tr>
<tr><td>FE FF<td>UTF-16-BE</tr>
<tr><td>FF FE<td>UTF-16-LE</tr>
<tr><td>7C 83 88 81 99 A2 85 A3 40 7F (YY)* 7F 5E<td>as specified, transcoded from EBCDIC to ASCII</tr>
<tr><td>AE 83 88 81 99 A2 85 A3 40 FC (YY)* FC 5E<td>as specified, transcoded from IBM1026 to ASCII</tr>
<tr><td>00 63 68 61 72 73 65 74 20 22 (YY)* 22 3B<td>as specified, transcoded from GSM 03.38 to ASCII</tr>
<tr><td>analogous patterns<td>User agents may
    support additional, analogous, patterns if they support encodings
    that are not handled by the patterns here</tr>
</table>

</li>

<li>If the encoding is detected based on one of the entries in the table
above marked "as specified", the user agent ignores the style sheet if it
does not parse an appropriate @charset rule at the beginning of the
stream of characters resulting from decoding in the chosen @charset.
This ensures that:
  <ul>
    <li>@charset rules should only function if they are in the
    encoding of the style sheet,</li>
    <li>byte order marks are ignored only
    in encodings that support a byte order mark, and</li>
    <li>encoding names cannot contain newlines.</li>
  </ul>
</li>

</ul>

<p>User agents must ignore style sheets in unknown encodings.</p>

<h4 id="escaping">Referring to characters not represented in a character encoding</h4>

<p>A style sheet may have to refer to characters that cannot be
represented in the current character encoding.  These characters must
be written as <a href="#escaped-characters">escaped</a> references to
ISO 10646 characters. These escapes serve the same purpose as numeric
character references in HTML or XML documents (see [[!HTML401]],
chapters 5 and 25).
</p>
<p>The character escape mechanism should be used when only a few
characters must be represented this way. If most of a style sheet
requires escaping, authors should encode it with a more appropriate
encoding (e.g., if the style sheet contains a lot of Greek characters,
authors might use "ISO-8859-7" or "UTF-8").
</p>
<p>Intermediate processors using a different character encoding may
translate these escaped sequences into byte sequences of that
encoding. Intermediate processors must not, on
the other hand, alter escape sequences that cancel the special meaning
of an ASCII character.
</p>
<p><a href="#conformance">Conforming user agents</a> must
correctly map to ISO-10646 all characters in any character encodings
that they recognize (or they must behave as if they did).
</p>
<p>For example, a style sheet transmitted as ISO-8859-1
(Latin-1) cannot contain Greek letters directly:
"&kappa;&omicron;&upsilon;&rho;&omicron;&varsigma;" (Greek: "kouros") has to be
written as "\3BA\3BF\3C5\3C1\3BF\3C2".
</p>
<div class="note"><p>
<em><strong>Note.</strong>
In HTML 4,
numeric character references are interpreted in "style" attribute
values but not in the content of the STYLE element. Because of this
asymmetry, we recommend that authors use the CSS character
escape mechanism rather than numeric character references
for both the "style" attribute and the STYLE element.
For example, we recommend:</em></p>

<pre class="lang-html example"><code class="html">
&lt;SPAN style="font-family: L\FC beck"&gt;...&lt;/SPAN&gt;
</code></pre>

<p><em>rather than:</em></p>

<pre class="lang-html example"><code class="html">
&lt;SPAN style="font-family: L&amp;#252;beck"&gt;...&lt;/SPAN&gt;
</code></pre>
</div>





<h2 id="selector"><span id="q5.0">Selectors</span></h2>

<h3 id="pattern-matching">Pattern matching</h3>

<p>In CSS, pattern matching rules determine which style rules apply to
elements in the <a href="#doctree">document
tree</a>. These patterns, called <a data-lt="selector">selectors,</a> may range from simple element names
to rich contextual patterns. If all conditions in the pattern are true
for a certain element, the <dfn>selector matches</dfn> the element.

<p>The case-sensitivity of document language element names in
selectors depends on the document language. For example, in HTML,
element names are case-insensitive, but in XML they are
case-sensitive.

<p>The following table summarizes CSS&nbsp;2 selector syntax:</p>

<table>
<tr><th>Pattern<th>Meaning<th>Described in section</tr>
<tr><td>*<td>Matches any element.<td><a href="#universal-selector">Universal
selector</a></tr>
<tr><td>E<td>Matches any E element (i.e., an element of type E).<td><a href="#type-selectors">Type
selectors</a></tr>
<tr><td>E F<td>Matches any F element that is a descendant of
an E element.<td><a href="#descendant-selectors">Descendant
selectors</a></tr>
<tr><td>E &gt; F<td>Matches any F element that is a child of
an element E.<td><a href="#child-selectors">Child selectors</a></tr>
<tr><td>E:first-child<td>Matches element E when E is the first
child of its parent.
<td><a href="#first-child">The :first-child pseudo-class</a></tr>

<tr><td>E:link<br>E:visited <td>Matches element E if E is the source
anchor of a hyperlink of which the target is not yet visited (:link)
or already visited (:visited).
<td><a href="#link-pseudo-classes">The link pseudo-classes</a></tr>
<tr><td>E:active<br>E:hover<br>E:focus <td>Matches E during certain
user actions.
<td><a href="#dynamic-pseudo-classes">The dynamic pseudo-classes</a>
<tr><td>E:lang(c) <td>Matches element of type E if it is in (human) language c
(the document language specifies how language is determined).
<td><a href="#lang">The :lang() pseudo-class</a>
<tr><td>E + F<td>Matches any F element immediately preceded by
a sibling element E.<td><a href="#adjacent-selectors">Adjacent selectors</a>
</tr>
<tr><td>E[foo]<td>Matches any E element with the
"foo" attribute set (whatever the value).
<td><a href="#attribute-selectors">Attribute selectors</a>
</tr>
<tr><td>E[foo="warning"]<td>Matches any E element whose
"foo" attribute value is exactly equal to "warning".
<td><a href="#attribute-selectors">Attribute selectors</a>
</tr>
<tr><td>E[foo~="warning"]<td>Matches any E element whose
"foo" attribute value is a list of space-separated  values, one of
which is exactly equal to "warning".
<td><a href="#attribute-selectors">Attribute selectors</a>
</tr>
<tr><td>E[lang|="en"]<td>Matches any E element whose
"lang" attribute has a hyphen-separated list of values
beginning (from the left) with "en".
<td><a href="#attribute-selectors">Attribute selectors</a>
</tr>
<tr><td>DIV.warning<td><em>Language specific.</em> (In HTML, the same
as DIV[class~="warning"].)
<td><a href="#class-html">Class selectors</a></tr>
<tr><td>E#myid<td>Matches any E element with ID
equal to "myid".<td><a href="#id-selectors">ID selectors</a></tr>
</table>


<h3 id="selector-syntax">Selector syntax</h3>

<p>A <dfn id="simple-selector">simple selector</dfn> is either
a <a href="#type-selectors">type selector</a> or <a href="#universal-selector">universal selector</a> followed immediately
by zero or more <a href="#attribute-selectors">attribute
selectors</a>, <a href="#id-selectors">ID selectors</a>, or <a href="#pseudo-classes">pseudo-classes</a>, in any order.  The simple
selector matches if all of its components match.

<p class="note">Note: the terminology used here in CSS&nbsp;2 is
different from what is used in CSS3. For example, a "simple selector"
refers to a smaller part of a selector in CSS3 than in CSS&nbsp;2.
See the CSS3 Selectors module [[SELECTORS-3]].

<p>A <dfn>selector</dfn> is a chain of one or more
simple selectors separated by combinators.  <dfn id="combinator">Combinators</dfn> are: white space,
"&gt;", and "+". White space may appear between a combinator and the
simple selectors around it.

<p>The elements of the document tree that match a selector are called
<dfn data-lt="subject (of selector)|subjects" id="subject">subjects</dfn> of the selector.
A selector consisting of a single simple selector matches any element
satisfying its requirements.  Prepending a simple selector and
combinator to a chain imposes additional matching constraints, so the
subjects of a selector are always a subset of the elements matching
the last simple selector.

<p>One <a href="#pseudo-elements">pseudo-element</a> may be appended
to the last simple selector in a chain, in which case the style
information applies to a subpart of each subject.

<h4 id="grouping">Grouping</h4>

<p>When several selectors share the same declarations, they may be
grouped into a comma-separated list.</p>

<div class="example">
<p>In this example, we condense three rules with identical declarations
into one. Thus,

<pre class="lang-css">
h1 { font-family: sans-serif }
h2 { font-family: sans-serif }
h3 { font-family: sans-serif }
</pre>

<p>is equivalent to:</p>

<pre class="lang-css">
h1, h2, h3 { font-family: sans-serif }
</pre>
</div>

<p>CSS offers other "shorthand" mechanisms as well, including
<dfn>
<a href="#declaration">multiple declarations</a></dfn>
and <a data-lt="shorthand property" href="#shorthand">shorthand properties</a>.

<h3 id="universal-selector">Universal selector</h3>

<p>The <dfn>universal
selector</dfn>, written "*", matches the name of any element
type. It matches any single element in the <a href="#doctree">document tree.</a>


<p>If the universal selector is not the only component of a <a href="#simple-selector">simple selector</a>, the "*" may be
omitted. For example:</p>

<ul>
<li><code>*[lang=fr] </code> and <code>[lang=fr]</code> are equivalent.
<li><code>*.warning</code> and <code>.warning</code> are equivalent.
<li><code>*#myid</code> and <code>#myid</code> are equivalent.
</ul>

<h3 id="type-selectors">Type selectors</h3>

<p>A <dfn><em>type
selector</em></dfn> matches the name of a document language element
type. A type selector matches every instance of the element type in
the document tree.

<div class="example">
<p>The following rule matches all H1 elements in the
document tree:</p>

<pre class="lang-css">
h1 { font-family: sans-serif }
</pre>
</div>

<h3 id="descendant-selectors">Descendant selectors</h3>

<p>At times, authors may want selectors to match an element that is
the descendant of another element in the document tree (e.g., "Match
those EM elements that are contained by an H1 element").  <dfn data-lt="descendant-selectors">Descendant
selectors</dfn> express such a relationship in a pattern. A
descendant selector is made up of two or more selectors separated by
<a href="#whitespace">white space</a>. A descendant
selector of the form "<code>A B</code>" matches when an element
<code>B</code> is an arbitrary descendant of some <a href="#doctree">ancestor</a> element <code>A</code>.

<div class="example"><p>
For example, consider the following rules:</p>

<pre class="lang-css">
h1 { color: red }
em { color: red }
</pre>

<p>Although the intention of these rules is to add emphasis to text by
changing its color, the effect will be lost in a case such as:</p>

<pre class="lang-html example">
&lt;H1&gt;This headline is &lt;EM&gt;very&lt;/EM&gt; important&lt;/H1&gt;
</pre>

<p>We address this case by supplementing the previous rules with a
rule that sets the text color to blue whenever an EM occurs anywhere
within an H1:</p>

<pre class="lang-css">
h1 { color: red }
em { color: red }
h1 em { color: blue }
</pre>

<p>The third rule will match the EM in the following fragment:</p>

<pre class="lang-html example">
&lt;H1&gt;This &lt;SPAN class="myclass"&gt;headline
is &lt;EM&gt;very&lt;/EM&gt; important&lt;/SPAN&gt;&lt;/H1&gt;
</pre>
</div>

<div class="example"><p>
The following selector:</p>

<pre>
div * p
</pre>

<p>matches a P element that is a grandchild or later descendant of a
DIV element. Note the white space on either side of the "*" is not part
of the universal selector; the white space is a combinator
indicating
that the DIV must be the ancestor of some element, and that that
element must be an ancestor of the P.
</div>

<div class="example"><p>
The selector in the following rule, which combines
descendant and <a href="#attribute-selectors">attribute selectors</a>,
matches any element that (1) has the "href" attribute set and
(2) is inside a P that is itself inside a DIV:</p>

<pre>
div p *[href]
</pre>
</div>

<h3 id="child-selectors">Child selectors</h3>

<p>A <dfn><em>child
selector</em></dfn> matches when an element is the <a href="#doctree">child</a> of some element. A child
selector is made up of two or more selectors separated by "&gt;".

<div class="example"><p>
The following rule sets the style of all P elements that
are children of BODY:</p>

<pre class="lang-css">
body &gt; P { line-height: 1.3 }
</pre>
</div>

<div class="example"><p>
The following example combines descendant selectors and child selectors:</p>
<pre>
div ol&gt;li p
</pre>

<p>It matches a P element that is a descendant of an LI; the LI element
must be the child of an OL element; the OL element must be a
descendant of a DIV. Notice that the optional white space around
the "&gt;" combinator has been left out.
</div>

<p>For information on selecting the first child of an element, please
see the section on the <a href="#first-child">:first-child</a>
pseudo-class below.

<h3 id="adjacent-selectors">Adjacent sibling selectors</h3>

<p>Adjacent sibling selectors have the following syntax: E1 + E2,
where E2 is the subject of the selector. The selector matches if E1
and E2 share the same parent in the document tree and E1 immediately
precedes E2,
ignoring non-element nodes (such as text nodes and comments).

<div class="example"><p>
Thus, the following rule states that when a P element immediately
follows a MATH element, it should not be indented:</p>

<pre class="lang-css">
math + p { text-indent: 0 }
</pre>

<p>The next example reduces the vertical space separating
an H1 and an H2 that immediately follows it:</p>

<pre class="lang-css">
h1 + h2 { margin-top: -5mm }
</pre>
</div>

<div class="example"><p>
The following rule is similar to the one in the previous example,
except that it adds a class selector. Thus, special formatting only
occurs when H1 has <samp>class="opener"</samp>:</p>

<pre class="lang-css">
h1.opener + h2 { margin-top: -5mm }
</pre>
</div>

<h3 id="attribute-selectors">Attribute selectors</h3>

<p>CSS&nbsp;2 allows authors to specify rules that match elements
which have certain attributes defined
in the source document.

<h4 id="matching-attrs">Matching attributes and attribute values</h4>

<p>Attribute selectors may match in four ways:</p>

<dl>
<dt><code>[att]</code>
<dd>Match when the element sets the "att" attribute, whatever
the value of the attribute.
<dt><dfn data-lt="exact matching"><code>[att=val]</code></dfn>
<dd>Match when the element's "att" attribute value is exactly "val".
<dt><dfn data-lt="space-separated matching"><code>[att~=val]</code></dfn>
<dd>Represents an element with the <code>att</code> attribute whose
value is a white space-separated list of words, one of which is exactly
"val". If "val" contains white space, it will never represent anything
(since the words are <em>separated</em> by spaces).
If "val" is the empty string, it will never represent anything either.
<dt><dfn data-lt="hyphen-separated matching"><code>[att|=val]</code></dfn>
<dd>Represents an element with the <code>att</code> attribute, its
value either being exactly "val" or beginning with "val" immediately
followed by "-" (U+002D). This is primarily intended to allow language subcode
matches (e.g., the <code>hreflang</code> attribute on the
<code>a</code> element in HTML) as described in BCP&nbsp;47
([[BCP47]]) or its successor. For <code>lang</code> (or
<code>xml:lang</code>) language subcode matching, please see <a href="#lang">the <code>:lang</code> pseudo-class</a>.
</dl>

<p>Attribute values must be identifiers or strings. The
case-sensitivity of attribute names and values in selectors depends on
the document language.

<div class="example"><p>
For example, the following attribute selector
matches all H1 elements that specify the "title" attribute,
whatever its value:</p>

<pre class="lang-css">
h1[title] { color: blue; }
</pre>
</div>

<div class="example"><p>
In the following example, the selector matches all SPAN elements whose
"class" attribute has exactly the value "example":</p>

<pre class="lang-css">
span[class=example] { color: blue; }
</pre>
</div>

<p>Multiple attribute selectors can be used to refer to several
attributes of an element, or even several times to the same attribute.

<div class="example"><p>
Here, the selector matches all SPAN elements whose
"hello" attribute has exactly the value "Cleveland" and whose
"goodbye" attribute has exactly the value "Columbus":</p>

<pre class="lang-css">
span[hello="Cleveland"][goodbye="Columbus"] { color: blue; }
</pre>
</div>

<div class="example"><p>
The following selectors illustrate the differences between "=" and "~=".
The first selector will match, for example, the value
"copyright copyleft copyeditor" for the "rel" attribute. The second
selector will only match when the "href" attribute has the value
"https://www.w3.org/".
</p>

<pre>
a[rel~="copyright"]
a[href="https://www.w3.org/"]
</pre>
</div>

<div class="example"><p>
The following rule hides all elements for which the value of the
"lang" attribute is "fr" (i.e., the language is French).

<pre class="lang-css">
*[lang=fr] { display : none }
</pre>
</div>

<div class="example"><p>
The following rule will match for values of the "lang" attribute
that begin with "en", including "en", "en-US", and "en-cockney":</p>

<pre class="lang-css">
*[lang|="en"] { color : red }
</pre>
</div>

<h4 id="default-attrs">Default attribute values in DTDs</h4>

<p>Matching takes place on attribute values in the document tree.
Default attribute values may be defined in a DTD or elsewhere, but cannot always be selected by
attribute selectors. Style sheets should be designed so that they work
even if the default values are not included in the document tree.

<p>More precisely, a UA may, but is <em>not</em> required to, read an "external
subset" of the DTD but <em>is</em> required to look for default
attribute values in the document's "internal subset." (See [[!XML10]]
for definitions of these subsets.)
Depending on the UA, a default attribute value defined in the external
subset of the DTD might or might not appear in the document tree.

<p>A UA that recognizes an XML namespace [[XML-NAMES]] may, but is not
required to, use its knowledge of that namespace to treat default
attribute values as if they were present in the document. (E.g., an
XHTML UA is not required to use its built-in knowledge of the XHTML
DTD.)

<p class="note">Note that, typically, implementations choose to ignore
external subsets.

<div class="example">
<p style="display:none">Example:</p>
<p>For example, consider an element EXAMPLE with an attribute "notation"
that has a default value of "decimal". The DTD fragment might be

<pre class="lang-dtd example">
&lt;!ATTLIST EXAMPLE notation (decimal,octal) "decimal"&gt;
</pre>

<p>If the style sheet contains the rules

<pre class="example lang-css">
EXAMPLE[notation=decimal] { /*... default property settings ...*/ }
EXAMPLE[notation=octal]   { /*... other settings...*/ }
</pre>

<p>the first rule might not match elements whose "notation" attribute
is set by default, i.e., not set explicitly. To catch all cases, the
attribute selector for the default value must be dropped:</p>

<pre class="example lang-css">
EXAMPLE                   { /*... default property settings ...*/ }
EXAMPLE[notation=octal]   { /*... other settings...*/ }
</pre>

<p>Here, because the selector <code>EXAMPLE[notation=octal]</code> is
more <a href="#specificity">specific</a> than the type
selector alone, the style declarations in the second rule will override
those in the first for elements that have a "notation" attribute value
of "octal". Care has to be taken that all property declarations that
are to apply only to the default case are overridden in the non-default
cases' style rules.
</div>


<h4 id="class-html">Class selectors</h4>

<p>Working with HTML, authors may use the period (<code>.</code>)
notation as an alternative to the <code>~=</code> notation when
representing the <code>class</code> attribute. Thus, for HTML,
<code>div.value</code> and <code>div[class~=value]</code> have the
same meaning. The attribute value must immediately follow the
"period" (<code>.</code>). UAs may apply selectors using the
period (.) notation in XML documents if the UA has namespace specific
knowledge that allows it to determine which attribute is the
"class" attribute for the respective namespace. One such
example of namespace specific knowledge is the prose in the
specification for a particular namespace (e.g., SVG 1.1 [[SVG11]]
describes the <a href="https://www.w3.org/TR/2003/REC-SVG11-20030114/styling.html#ClassAttribute">SVG
"class" attribute</a> and how a UA should interpret it, and
similarly MathML 3.0 [[MATHML3]] describes the <a href="https://www.w3.org/TR/MathML2/chapter2.html#fund.globatt">MathML
"class" attribute</a>.)

<div class="example"><p>
For example, we can assign style information to all elements with
<samp>class~="pastoral"</samp> as follows:</p>

<pre class="lang-css">
*.pastoral { color: green }  /* all elements with class~=pastoral */
</pre>

or just

<pre class="lang-css">
.pastoral { color: green }  /* all elements with class~=pastoral */
</pre>

<p>The following assigns style only to H1 elements with
<samp>class~="pastoral"</samp>:</p>

<pre class="lang-css">
H1.pastoral { color: green }  /* H1 elements with class~=pastoral */
</pre>

<p>Given these rules, the first H1 instance below would not have green
text, while the second would:</p>

<pre>
&lt;H1&gt;Not green&lt;/H1&gt;
&lt;H1 class="pastoral"&gt;Very green&lt;/H1&gt;
</pre>
</div>

<p>To match a subset of "class" values, each value must be preceded
by a ".".</p>

<div class="example"><p>
For example, the following rule matches any P element whose "class" attribute
has been assigned a list of space-separated values that includes "pastoral"
and "marine":</p>

<pre class="lang-css">
p.marine.pastoral { color: green }
</pre>

<p>This rule matches when <samp>class="pastoral blue aqua
marine"</samp> but does not match for <samp>class="pastoral
blue"</samp>.
</div>

<div class="note"><p> <em><strong>Note.</strong> CSS gives so much
power to the "class" attribute, that authors could conceivably design
their own "document language" based on elements with almost no
associated presentation (such as DIV and SPAN in HTML) and assigning
style information through the "class" attribute.  Authors should avoid
this practice since the structural elements of a document language
often have recognized and accepted meanings and author-defined classes may
not.</em>
</div>

<div class="note"><p><em><strong>Note:</strong> If an element has
multiple class attributes, their values must be concatenated with
spaces between the values before searching for the class. As of this
time the working group is not aware of any manner in which this
situation can be reached, however, so this behavior is explicitly
non-normative in this specification.</em>
</div>

<h3 id="id-selectors">ID selectors</h3>

<p>Document languages may contain attributes that are declared to be
of type ID.  What makes attributes of type ID special is that no two
such attributes can have the same value; whatever the document
language, an ID attribute can be used to uniquely identify its
element. In HTML all ID attributes are named "id"; XML
applications may name ID attributes differently, but the
same restriction applies.

<p>The ID attribute of a document language allows authors to assign an
identifier to one element instance in the document tree.  CSS ID
selectors match an element instance based on its identifier.  A CSS
ID selector contains a "#" immediately followed by the ID
value, which must be an identifier.</p>

<p class="note">Note that CSS does not specify how a UA knows the ID
attribute of an element. The UA may, e.g., read a document's DTD, have
the information hard-coded or ask the user.

<div class="example"><p>
The following ID selector matches the H1 element whose ID
attribute has the value "chapter1":</p>

<pre class="lang-css">
h1#chapter1 { text-align: center }
</pre>
</div>

<div class="lang-html example"><p>
In the following example, the style rule matches
the element that has the ID value "z98y".
The rule will thus match for the P element:</p>

<pre>
&lt;HEAD&gt;
  &lt;TITLE&gt;Match P&lt;/TITLE&gt;
  &lt;STYLE type="text/css"&gt;
    *#z98y { letter-spacing: 0.3em }
  &lt;/STYLE&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;
   &lt;P id=z98y&gt;Wide text&lt;/P&gt;
&lt;/BODY&gt;
</pre>

<p>In the next example, however, the style rule will only match an H1
element that has an ID value of "z98y". The rule will not match the
P element in this example:</p>

<pre>
&lt;HEAD&gt;
  &lt;TITLE&gt;Match H1 only&lt;/TITLE&gt;
  &lt;STYLE type="text/css"&gt;
    H1#z98y { letter-spacing: 0.5em }
  &lt;/STYLE&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;
   &lt;P id=z98y&gt;Wide text&lt;/P&gt;
&lt;/BODY&gt;
</pre>
</div>

<p>ID selectors have a higher specificity than attribute selectors.
For example, in HTML, the selector <samp>#p123</samp> is more specific
than <samp>[id=p123]</samp> in terms of the <a href="#assigning">cascade</a>.

<div class="note">
<p><em><strong>Note.</strong> In XML 1.0 [[XML10]], the information about which
attribute contains an element's IDs is contained in a DTD. When
parsing XML, UAs do not always read the DTD, and thus may not know
what the ID of an element is. If a style sheet designer knows or
suspects that this will be the case, they should use normal attribute
selectors instead: <code>[name=p371]</code> instead of
<code>#p371</code>. However, the cascading order of normal attribute
selectors is different from ID selectors. It may be necessary to add
an "!important" priority to the declarations: <code>[name=p371]
{color: red ! important}</code>.</em>
</div>

<p>If an element has multiple ID attributes, all of them must be
treated as IDs for that element for the purposes of the ID
selector. Such a situation could be reached using mixtures of xml:id
[[XML-ID]], DOM3 Core [[DOM-LEVEL-3-CORE]], XML DTDs [[XML10]] and
namespace-specific knowledge.

<h3 id="pseudo-elements">Pseudo-elements and <span id="pseudo-classes">pseudo-classes</span></h3>

<p>In CSS&nbsp;2, style is normally attached to an element based on its
position in the <a href="#doctree">document tree</a>. This
simple model is sufficient for many cases, but some common publishing
scenarios may not be possible due to the structure of the <a href="#doctree">document tree</a>. For instance, in HTML
4 (see [[!HTML401]]), no element refers to the first line of a
paragraph, and therefore no simple CSS selector may refer to it.</p>

<p>CSS introduces the concepts of <dfn>pseudo-elements</dfn> and <dfn>pseudo-classes</dfn> to permit
formatting based on information that lies outside the document
tree. </p>

<ul>
<li>Pseudo-elements create abstractions about the document tree beyond
those specified by the document language. For instance, document
languages do not offer mechanisms to access the first letter or first
line of an element's content. CSS pseudo-elements allow style sheet
designers to refer to this otherwise inaccessible
information. Pseudo-elements may also provide style sheet designers a
way to assign style to content that does not exist in the source
document (e.g., the <a href="#before-after-content">:before and :after</a>
pseudo-elements give access to generated content).

<li>Pseudo-classes classify elements on characteristics other than
their name, attributes or content; in principle characteristics that
cannot be deduced from the document tree. Pseudo-classes may be
dynamic, in the sense that an element may acquire or lose a
pseudo-class while a user interacts with the document. The exceptions
are '':first-child'', which <em>can</em> be
deduced from the document tree, and
'':lang()'', which can be
deduced from the document tree in some cases.
</ul>

<p>Neither pseudo-elements nor pseudo-classes appear in the document
source or document tree.

<p>Pseudo-classes are allowed anywhere in selectors while
pseudo-elements may only be appended after the last simple selector of
the selector.
</p>


<p>Pseudo-element and pseudo-class names are case-insensitive.</p>

<p>Some pseudo-classes are mutually exclusive, while others can be
applied simultaneously to the same element. In case of conflicting
rules, the normal <a href="#cascading-order">cascading
order</a> determines the outcome.

<h3 id="pseudo-class-selectors">Pseudo-classes</h3>

<h4 id="first-child">:first-child pseudo-class</h4>

<p>The <dfn data-lt="first-child|:first-child">:first-child</dfn> pseudo-class
matches an element that is the first child element of some other element.

<div class="example"><p>
In the following example, the selector matches any P element
that is the first child of a DIV element. The rule
suppresses indentation for the first paragraph of a DIV:</p>

<pre class="lang-css">
div &gt; p:first-child { text-indent: 0 }
</pre>

This selector would match the P inside the DIV of the
following fragment:

<pre class="lang-html example">
&lt;P&gt; The last P before the note.
&lt;DIV class="note"&gt;
   &lt;P&gt; The first P inside the note.
&lt;/DIV&gt;
</pre>

but would not match the second P in the following
fragment:

<pre class="lang-html example">
&lt;P&gt; The last P before the note.
&lt;DIV class="note"&gt;
   &lt;H2&gt;Note&lt;/H2&gt;
   &lt;P&gt; The first P inside the note.
&lt;/DIV&gt;
</pre>
</div>

<div class="example">
<p>The following rule sets the font weight to ''bold'' for any EM
element that is some descendant of a P element that is a first
child:</p>

<pre class="lang-css">
p:first-child em { font-weight : bold }
</pre>
</div>

<p>Note that since <a href="#anonymous">anonymous</a>
boxes are not part of the document tree, they are not counted when
calculating the first child.</p>

<div class="lang-html example"><p>
For example, the EM in:</p>

<pre>
&lt;P&gt;abc &lt;EM&gt;default&lt;/EM&gt;
</pre>

is the first child of the P.
</div>

<p>The following two selectors are equivalent:</p>

<pre>
* &gt; a:first-child   /* A is first child of any element */
a:first-child       /* Same */
</pre>


<h4 id="link-pseudo-classes">The link pseudo-classes: <dfn>:link</dfn> and <dfn>:visited</dfn></h4>

<p>User agents commonly display unvisited links differently from
previously visited ones. CSS provides the pseudo-classes '':link'' and
'':visited'' to distinguish them:</p>

<ul>
<li> The :link pseudo-class applies for links that have
not yet been visited.

<li> The :visited pseudo-class applies once the link has been
visited by the user.
</ul>

<p>UAs may return a visited link to the (unvisited) '':link'' state at
some point.

<p>The two states are mutually exclusive.

<p>The document language determines which elements are hyperlink
source anchors. For example, in HTML4, the link pseudo-classes
apply to A elements with an "href" attribute. Thus, the following
two CSS&nbsp;2 declarations have similar effect:</p>

<pre class="lang-css">
a:link { color: red }
:link  { color: red }
</pre>

<div class="example"><p>
If the following link:</p>

<pre class="lang-html example">
&lt;A class="external" href="http://out.side/"&gt;external link&lt;/A&gt;
</pre>

has been visited, this rule:

<pre class="lang-css">
a.external:visited { color: blue }
</pre>

will cause it to be blue.
</div>

<p class="note">Note. It is possible for style sheet authors to abuse the
:link and :visited pseudo-classes to determine which sites a user has
visited without the user's consent.

<p>UAs may therefore treat all links as unvisited links, or implement
other measures to preserve the user's privacy while rendering visited
and unvisited links differently. See [[P3P]] for more information
about handling privacy.

<h4 id="dynamic-pseudo-classes">The dynamic pseudo-classes:
<dfn>:hover</dfn>, <dfn>:active</dfn>, and <dfn>:focus</dfn></h4>

<p>Interactive user agents sometimes change the rendering in response
to user actions. CSS provides three pseudo-classes for common cases:</p>

<ul>
<li> The :hover pseudo-class applies while the user designates an
element (with some pointing device), but does not activate it. For
example, a visual user agent could apply this pseudo-class when the
cursor (mouse pointer) hovers over a box generated by the element.
User agents not supporting
<a href="#interactive-media-group">interactive media</a>
do not have to support this pseudo-class.
Some conforming user agents supporting
<a href="#interactive-media-group">interactive media</a>
may not be able to support this pseudo-class (e.g., a pen device).

<li> The :active pseudo-class applies while an element is being
activated by the user. For example, between the times the user presses
the mouse button and releases it.

<li> The :focus pseudo-class applies while an element has the
focus (accepts keyboard events or other forms of text input).
</ul>

<p>An element may match several pseudo-classes at the same time.

<p>CSS does not define which elements may be in the above states, or
how the states are entered and left. Scripting may change whether
elements react to user events or not, and different devices and UAs
may have different ways of pointing to, or activating elements.

<p>CSS&nbsp;2 does not define if the parent of an element that is
'':active'' or '':hover'' is also in that state.

<p>User agents are not required to reflow a currently displayed
document due to pseudo-class transitions. For instance, a style sheet
may specify that the 'font-size' of an :active link
should be larger than that of an inactive link, but since this may
cause letters to change position when the reader selects the link, a
UA may ignore the corresponding style rule.</p>

<div class="example"><p>

<pre class="lang-css">
a:link    { color: red }    /* unvisited links */
a:visited { color: blue }   /* visited links   */
a:hover   { color: yellow } /* user hovers     */
a:active  { color: lime }   /* active links    */
</pre>

<p>Note that the A:hover must be placed after the A:link and A:visited
rules, since otherwise the cascading rules will hide the 'color' property of the A:hover
rule. Similarly, because A:active is placed after A:hover, the active
color (lime) will apply when the user both activates and hovers over
the A element.
</div>

<div class="example">
<p>An example of combining dynamic pseudo-classes:

<pre class="lang-css">
a:focus { background: yellow }
a:focus:hover { background: white }
</pre>

<p>The last selector matches A elements that are in pseudo-class
:focus and in pseudo-class :hover.

</div>

<!--In order to support the :focus pseudo-class, user agents are
expected to be able to reformat a document dynamically. [this
conflicts with the statement above, HWL] -->

<p>For information about the presentation of focus outlines, please
consult the section on <a href="#dynamic-outlines">dynamic
focus outlines</a>.

<div class="note"><p>
<em><strong>Note.</strong>
In CSS1, the '':active'' pseudo-class was mutually
exclusive with '':link'' and '':visited''. That is no longer the case. An
element can be both '':visited'' and '':active'' (or '':link'' and
'':active'') and the normal cascading rules determine which style
declarations
apply.
</em>
</div>

<div class="note"><p>
<em><strong>Note.</strong>
Also note that in CSS1, the '':active'' pseudo-class only applied to
links.</em>
</div>

<h4 id="lang">The language pseudo-class: <dfn data-lt=":lang|:lang()">:lang</dfn></h4>

<p>If the document language specifies how the human language of an element is
determined, it is possible to write selectors in CSS that match an
element based on its language. For example, in HTML [[!HTML401]], the
language is determined by a combination of the "lang" attribute, the
META element, and possibly by information from the protocol (such as
HTTP headers). XML uses an attribute called xml:lang, and there may be
other document language-specific methods for determining the language.

<p>The pseudo-class '':lang(C)'' matches if the element is in language
C. Whether there is a match is based solely on the identifier C
being either equal to, or a hyphen-separated substring of, the
element's language value, in the same way as if performed by the <a href="#attribute-selectors">''|=''</a> operator. The matching of C
against the element's language value is performed case-insensitively
for characters within the ASCII range.
The identifier C does not have to be a valid language name.</p>

<p>C must not be empty.

<p class="note">Note: It is recommended that documents and
protocols indicate language using codes from BCP&nbsp;47 [[BCP47]] or
its successor, and by means of "xml:lang" attributes in the case of
XML-based documents [[!XML10]]. See <a href="https://www.w3.org/International/questions/qa-lang-2or3">
"FAQ: Two-letter or three-letter language codes."</a></p>

<div class="example">
<p>The following rules set the quotation marks for an HTML document
that is either in Canadian French or German:</p>

<pre class="lang-css">
html:lang(fr-ca) { quotes: '&laquo; ' ' &raquo;' }
html:lang(de) { quotes: '&raquo;' '&laquo;' '\2039' '\203A' }
:lang(fr) &gt; Q { quotes: '&laquo; ' ' &raquo;' }
:lang(de) &gt; Q { quotes: '&raquo;' '&laquo;' '\2039' '\203A' }
</pre>

<p>The second pair of rules actually set the 'quotes' property on Q elements
according to the language of its parent. This is done because the
choice of quote marks is typically based on the language of the
element around the quote, not the quote itself: like this piece of
French &ldquo;&agrave; l'improviste&rdquor; in the middle of an English
text uses the English quotation marks.  </div>

<div class="note">
  <p><strong>Note</strong> the difference between [lang|=xx] and
  :lang(xx). In this HTML example, only the BODY matches [lang|=fr]
  (because it has a LANG attribute) but both the BODY and the P match
  :lang(fr) (because both are in French).

  <pre>
&lt;body lang=fr&gt;
  &lt;p&gt;Je suis Fran&ccedil;ais.&lt;/p&gt;
&lt;/body&gt;
</pre>
</div>

<h3 id="pseudo-element-selectors">Pseudo-elements</h3>

<p>Pseudo-elements behave just like real elements in CSS with the
exceptions described below and <a href="#before-after-content">elsewhere.</a>

<p class="note"><em>Note that the sections below do not define the
exact rendering of '':first-line'' and '':first-letter'' in all cases. A
future level of CSS may define them more precisely.</em>

<h4 id="first-line-pseudo">The <dfn>:first-line</dfn> pseudo-element</h4>

<p>The :first-line pseudo-element applies special styles to the
contents of the first formatted line of a paragraph. For
instance:</p>

<pre class="example lang-css">
p:first-line { text-transform: uppercase }
</pre>

<p>The above rule means "change the letters of the first line of
every paragraph to uppercase". However, the selector "P:first-line"
does not match any real HTML element. It does match a pseudo-element
that <a href="#conformance">conforming user agents</a>
will insert at the beginning of every paragraph.</p>

<p>Note that the length of the first line depends on a number of
factors, including the width of the page, the font size, etc.  Thus,
an ordinary HTML paragraph such as:</p>

<pre class="lang-html example">
&lt;P&gt;This is a somewhat long HTML
paragraph that will be broken into several
lines. The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.&lt;/P&gt;
</pre>

<p>the lines of which happen to be broken as follows:

<pre class="lang-html example">
THIS IS A SOMEWHAT LONG HTML PARAGRAPH THAT
will be broken into several lines. The first
line will be identified by a fictional tag
sequence. The other lines will be treated as
ordinary lines in the paragraph.
</pre>

<p>might be "rewritten" by user agents to include the <em><dfn>fictional tag
sequence</dfn></em> for :first-line. This fictional tag sequence helps
to show how properties are inherited.

<pre>
&lt;P&gt;<b>&lt;P:first-line&gt;</b> This is a somewhat long HTML
paragraph that <b>&lt;/P:first-line&gt;</b> will be broken into several
lines. The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.&lt;/P&gt;
</pre>

<p>If a pseudo-element breaks up a real element, the desired effect
can often be described by a fictional tag sequence that closes and
then re-opens the element. Thus, if we mark up the previous paragraph
with a SPAN element:</p>

<pre class="lang-xml">
&lt;P&gt;<b>&lt;SPAN class="test"&gt;</b> This is a somewhat long HTML
paragraph that will be broken into several
lines.<b>&lt;/SPAN&gt;</b> The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.&lt;/P&gt;
</pre>

<p>the user agent could simulate start and end tags for
SPAN when inserting the fictional tag sequence for :first-line.

<pre>
&lt;P&gt;&lt;P:first-line&gt;<b>&lt;SPAN class="test"&gt;</b> This is a
somewhat long HTML
paragraph that will <b>&lt;/SPAN&gt;</b>&lt;/P:first-line&gt;<b>&lt;SPAN class="test"&gt;</b> be
broken into several
lines.<b>&lt;/SPAN&gt;</b> The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.&lt;/P&gt;
</pre>

<p> The <a>:first-line</a> pseudo-element
can only be attached to a <a href="#block-boxes">block
container element.</a>

<p id="first-formatted-line">The "first formatted line" of an
element may occur inside a
block-level descendant in the same flow (i.e., a block-level
descendant that is not positioned and not a float). E.g., the first
line of the DIV in <code class="lang-xml">&lt;DIV&gt;&lt;P&gt;This
line...&lt;/P&gt;&lt;/DIV&gt;</code> is the first line of the P (assuming
that both P and DIV are block-level).

<p>The first line of a table-cell or inline-block cannot be the first
formatted line of an ancestor element. Thus, in <code>&lt;DIV&gt;&lt;P
STYLE="display: inline-block"&gt;Hello&lt;BR&gt;Goodbye&lt;/P&gt;
etcetera&lt;/DIV&gt;</code> the first formatted line of the DIV is not
the line "Hello".

<p class="note">Note that the first line of the P in this fragment:
<code>&lt;p&gt;&lt;br&gt;First...</code> does not contain any letters
(assuming the default style for BR in HTML 4). The word "First" is
not on the first formatted line.

<p>A UA should act as if the fictional start tags of the first-line
pseudo-elements were nested just inside the innermost enclosing
block-level element. (Since CSS1 and CSS2&nbsp;(1998) were silent on this case,
authors should not rely on this behavior.) Here is an example. The
fictional tag sequence for

<pre class="lang-xml">
&lt;DIV&gt;
  &lt;P&gt;First paragraph&lt;/P&gt;
  &lt;P&gt;Second paragraph&lt;/P&gt;
&lt;/DIV&gt;
</pre>

<p>is

<pre>
&lt;DIV&gt;
  &lt;P&gt;&lt;DIV:first-line&gt;&lt;P:first-line&gt;First paragraph&lt;/P:first-line&gt;&lt;/DIV:first-line&gt;&lt;/P&gt;
  &lt;P&gt;&lt;P:first-line&gt;Second paragraph&lt;/P:first-line&gt;&lt;/P&gt;
&lt;/DIV&gt;
</pre>


<p>The <span id="first-line">:first-line</span> pseudo-element is similar
to an inline-level element, but with certain restrictions. The
following properties apply to a :first-line pseudo-element: <a href="#fonts">font properties,</a> <a href="#color-bg">color
property,</a> <a href="#background-properties">background
properties,</a> 'word-spacing', 'letter-spacing', 'text-decoration', 'text-transform', and 'line-height'. UAs may apply
other properties as well.</p>


<h4 id="first-letter">The <dfn>:first-letter</dfn> pseudo-element</h4>

<p>The :first-letter pseudo-element must select the first letter of
the first line of a block, if it is not preceded by any other content
(such as images or inline tables) on its line. The :first-letter
pseudo-element may be used for "initial caps" and "drop caps", which are common typographical effects. This
type of initial letter is similar to an inline-level element if its
'float' property is ''float/none'',
otherwise it is similar to a floated element.</p>

<p>These are the properties that apply to :first-letter pseudo-elements:
<a href="#fonts">font properties,</a>
'text-decoration',
'text-transform',
'letter-spacing',
'word-spacing' (when appropriate),
'line-height',
'float',
'vertical-align' (only if 'float' is ''float/none''),
<a href="#margin-properties">margin properties,</a>
<a href="#padding-properties">padding properties,</a>
<a href="#border-properties">border properties,</a>
<a href="#color-bg">color property,</a>
<a href="#background-properties">background properties.</a>
UAs may apply other properties as well.
To allow UAs to render a typographically correct drop cap or initial
cap, the UA may choose a line-height, width and height based on the
shape of the letter, unlike for normal elements. CSS3 is expected to
have specific properties that apply to first-letter.
</p>

<div class="lang-html example">
<p>This example shows a possible rendering of an initial cap. Note
that the 'line-height' that is inherited by the first-letter
pseudo-element is 1.1, but the UA in this example has computed the
height of the first letter differently, so that it does not cause any
unnecessary space between the first two lines. Also note that the
fictional start tag of the first letter is inside the SPAN, and thus
the font weight of the first letter is normal, not bold as the SPAN:
<pre>
p { line-height: 1.1 }
p:first-letter { font-size: 3em; font-weight: normal }
span { font-weight: bold }
...
&lt;p&gt;&lt;span&gt;Het hemelsche&lt;/span&gt; gerecht heeft zich ten lange lesten&lt;br&gt;
Erbarremt over my en mijn benaeuwde vesten&lt;br&gt;
En arme burgery, en op mijn volcx gebed&lt;br&gt;
En dagelix geschrey de bange stad ontzet.
</pre>
<div class="figure">
<p><img src="./images/initial-cap.png" alt="Image illustrating the :first-letter pseudo-element" id="img-initial-cap">
</div>
</div>

<div class="lang-html example">
<p>The following CSS&nbsp;2 will make a drop cap initial letter span about two lines:</p>

<pre>
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
 &lt;HEAD&gt;
  &lt;TITLE&gt;Drop cap initial letter&lt;/TITLE&gt;
  &lt;STYLE type="text/css"&gt;
   P              { font-size: 12pt; line-height: 1.2 }
   P:first-letter { font-size: 200%; font-style: italic;
                    font-weight: bold; float: left }
   SPAN           { text-transform: uppercase }
  &lt;/STYLE&gt;
 &lt;/HEAD&gt;
 &lt;BODY&gt;
  &lt;P&gt;&lt;SPAN&gt;The first&lt;/SPAN&gt; few words of an article
    in The Economist.&lt;/P&gt;
 &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>

<p>This example might be formatted as follows:</p>

<div class="figure">
<p><img src="./images/first-letter.png" alt="Image illustrating the combined effect of the :first-letter and :first-line pseudo-elements" id="img-first-letter"></p>
</div>

<p>The <a data-lt="fictional tag sequence">fictional tag sequence</a> is:</p>

<pre>
&lt;P&gt;
&lt;SPAN&gt;
&lt;P:first-letter&gt;
T
&lt;/P:first-letter&gt;he first
&lt;/SPAN&gt;
few words of an article in the Economist.
&lt;/P&gt;
</pre>

<p>Note that the :first-letter pseudo-element tags abut the content
(i.e., the initial character), while the :first-line pseudo-element
start tag is inserted right after the start tag of the block element.</p>
</div>

<p>In order to achieve traditional drop caps formatting, user agents
may approximate font sizes, for example to align baselines. Also, the
glyph outline may be taken into account when formatting.

<p>Punctuation (i.e, characters defined in Unicode [[!UNICODE]] in the
"open" (Ps), "close" (Pe), "initial" (Pi). "final" (Pf) and "other"
(Po) punctuation classes), that
precedes or follows the first letter should be included, as in:</p>

<div class="figure">
<p><img src="./images/first-letter2.png" alt="Quotes that precede the first letter should be included." id="img-first-letter2"></p>
</div>

<p>The '':first-letter'' also applies if the first letter is in fact a
digit, e.g., the "6" in "67 million dollars is a lot of money."

<p>The :first-letter pseudo-element applies
to <a href="#block-boxes">block container elements.</a>

<p>The :first-letter pseudo-element can be used with all such elements that
contain text, or that have a descendant in the same flow that contains
text. A UA should act as if the fictional start tag of the
first-letter pseudo-element is just before the first text of the
element, even if that first text is in a descendant.</p>

<div class="example">
<p>Here is an example. The fictional tag sequence for this HTML
fragment:
<pre>
&lt;div&gt;
&lt;p&gt;The first text.
</pre>
<p>is:
<pre>
&lt;div&gt;
&lt;p&gt;&lt;div:first-letter&gt;&lt;p:first-letter&gt;T&lt;/...&gt;&lt;/...&gt;he first text.
</pre>
</div>

<p>The first letter of a table-cell or inline-block cannot be the
first letter of an ancestor element. Thus, in <code>&lt;DIV&gt;&lt;P
STYLE="display: inline-block"&gt;Hello&lt;BR&gt;Goodbye&lt;/P&gt;
etcetera&lt;/DIV&gt;</code> the first letter of the DIV is not the
letter "H". In fact, the DIV does not have a first letter.

<p>The first letter must occur on the <a href="#first-formatted-line">first formatted line.</a> For example, in
this fragment: <code>&lt;p&gt;&lt;br&gt;First...</code> the first line
does not contain any letters and '':first-letter'' does not match anything
(assuming the default style for BR in HTML 4). In particular, it
does not match the "F" of "First."

<p>If an element is a <a href="#lists">list item</a>
('display: list-item'), the '':first-letter'' applies to the first
letter in the principal box after the marker. UAs may ignore
'':first-letter'' on list items with 'list-style-position: inside'. If
an element has '':before'' or '':after'' content, the ':first-letter
applies to the first letter of the element <em>including</em> that
content.

<p class="example">
E.g., after the rule 'p:before {content: "Note: "}', the selector
''p:first-letter'' matches the "N" of "Note".

<p>
Some languages may have specific rules about how to treat certain
letter combinations. In Dutch, for example, if the letter combination
"ij" appears at the beginning of a word, both letters should be
considered within the :first-letter pseudo-element.

<p>If the letters that would form the first-letter are not in the same
element, such as "'T" in <code>&lt;p&gt;'&lt;em&gt;T...</code>, the UA may
create a first-letter pseudo-element from one of the elements, both
elements, or simply not create a pseudo-element.

<p>Similarly, if the first letter(s) of the block are not at the start
of the line (for example due to bidirectional reordering), then the UA
need not create the pseudo-element(s).

<div class="example"><p>
<span id="overlapping-example">The following example</span> illustrates
how overlapping pseudo-elements may interact.  The first letter of
each P element will be green with a font size of ''24pt''. The rest of
the first formatted line will be ''blue'' while the rest of the
paragraph will be ''red''.</p>

<pre>
p { color: red; font-size: 12pt }
p:first-letter { color: green; font-size: 200% }
p:first-line { color: blue }

&lt;P&gt;Some text that ends up on two lines&lt;/P&gt;
</pre>

<p>Assuming that a line break will occur before the word "ends", the
<a data-lt="fictional tag sequence">fictional tag
sequence</a> for this fragment might be:</p>

<pre>
&lt;P&gt;
&lt;P:first-line&gt;
&lt;P:first-letter&gt;
S
&lt;/P:first-letter&gt;ome text that
&lt;/P:first-line&gt;
ends up on two lines
&lt;/P&gt;
</pre>

<p>Note that the :first-letter element is inside the :first-line
element.  Properties set on :first-line are inherited by
:first-letter, but are overridden if the same property is set on
:first-letter.</p>
</div>

<h4 id="before-and-after">The :before and :after
pseudo-elements</h4>

<p>The '':before'' and '':after'' pseudo-elements can be used to insert
generated content before or after an element's content. They are
explained in the section on <a href="#generated-text">generated
text.</a>

<div class="example"><p>

<pre class="lang-css">
h1:before {content: counter(chapno, upper-roman) ". "}
</pre>
</div>

<p>When the :first-letter and :first-line pseudo-elements are applied
to an element having content generated using :before and :after, they
apply to the first letter or line of the element including the
generated content.

<div class="example"><p>

<pre class="lang-css">
p.special:before {content: "Special! "}
p.special:first-letter {color: #ffd800}
</pre>

<p>This will render the "S" of "Special!" in gold.
</div>






<h2 id="assigning"><span id="q6.0">Assigning property values, Cascading, and Inheritance</span></h2>

<h3 id="value-stages">Specified, computed, and actual values</h3>

<p>Once a user agent has parsed a document and constructed a <a href="#doctree">document tree</a>, it must assign, for
every element in the tree, a value to every property that applies to the
target <a href="#media">media type</a>.

<p>The final value of a property is the result of a four-step
calculation: the value is determined through specification (the
"specified value"), then resolved into a value that is used for
inheritance (the "computed value"), then converted into an absolute
value if necessary (the "used value"), and finally transformed
according to the limitations of the local environment (the "actual
value").

<h4><dfn id="specified-value">
Specified values</dfn></h4>

<p>User agents must first assign a specified value to each property based
on the following mechanisms (in order of precedence):</p>

<ol>
<li>If the <a href="#cascade">cascade</a> results in a value, use it.
Except that, if the value is ''inherit'', the specified value is defined
in [[#value-def-inherit]] below.
<li>Otherwise, if the property is <a href="#inheritance">inherited</a> and the element is not the root of the <a>document tree</a>, use the computed value of the parent element.
<li>Otherwise use the property's <dfn>initial value</dfn>. The initial value of each property is indicated in the property's definition.
</ol>


<h4><dfn id="computed-value">
Computed values</dfn></h4>

<p>Specified values are resolved to computed values during the cascade;
for example URIs are made absolute and ''em'' and ''ex''
units are computed to pixel or absolute lengths. Computing a value
never requires the user agent to render the document.

<p>The computed value of URIs that the UA cannot resolve to absolute
URIs is the specified value.

<p>The computed value of a
property is determined as specified by the Computed Value line in the
definition of the
property. See the section on <a href="#inheritance">inheritance</a>
for the definition of computed values when the specified value is
''inherit''.

<p>The computed value exists even when the property does not apply, as
defined by the <a href="#applies-to">'Applies To'</a> line.
However, some
properties may define the computed value of a property for an element
to depend on whether the property applies to that element.


<h4><dfn id="used-value">
Used values</dfn></h4>

<p>Computed values are processed as far as possible without formatting
the document. Some values, however, can only be determined when the
document is being laid out. For example, if the width of an element is
set to be a certain percentage of its containing block, the width
cannot be determined until the width of the containing block has been
determined. The <dfn id="usedValue">used value</dfn> is the result of
taking the computed value and resolving any remaining dependencies
into an absolute value.

<h4><dfn id="actual-value">
Actual values</dfn></h4>

<p>A used value is in principle the value used for rendering, but a
user agent may not be able to make use of the value in a given
environment. For example, a user agent may only be able to render
borders with integer pixel widths and may therefore have to
approximate the computed width, or the user agent may be forced to
use only black and white shades instead of full color. The actual
value is the used value after any approximations have been applied.


<h3 id="inheritance">Inheritance</h3>

<p>Some values are inherited by the children of an element in the <a href="#doctree">document tree</a>, as described <a href="#specified-value">above</a>. Each property <a href="#property-defs">defines</a> whether it is inherited or
not.

<div class="lang-html example"><p>
Suppose there is an H1 element with an emphasizing element (EM)
inside:</p>

<pre class="lang-xml">
&lt;H1&gt;The headline &lt;EM&gt;is&lt;/EM&gt; important!&lt;/H1&gt;
</pre>

<p>If no color has been assigned to the EM element, the emphasized
"is" will inherit the color of the parent element, so if H1 has the
color blue, the EM element will likewise be in blue.
</div>

<p>When inheritance occurs, elements inherit computed values. The
computed value from the parent element becomes both the specified
value and the computed value on the child.

<div class="example"><p>
For example, given the following style sheet:</p>

<pre class="lang-css">
body { font-size: 10pt }
h1 { font-size: 130% }
</pre>

<p>and this document fragment:

<pre class="lang-html example">
&lt;BODY&gt;
  &lt;H1&gt;A &lt;EM&gt;large&lt;/EM&gt; heading&lt;/H1&gt;
&lt;/BODY&gt;
</pre>

<p>the <span class="prop-inst-font-size">'font-size'</span> property
for the H1 element will have the computed value ''13pt'' (130% times
10pt, the parent's value). Since the computed value of 'font-size' is inherited, the EM
element will have the computed value ''13pt'' as well.  If the
user agent does not have the 13pt font available, the
actual value of 'font-size'
for both H1 and EM might be, for example, ''12pt''.
</div>

<p class="note">Note that inheritance follows the document tree and is
not intercepted by <a data-lt="" href="#box-gen">anonymous boxes.</a>


<h4 id="value-def-inherit">The <dfn data-lt="inherit" dfn-type="value" dfn-for="all">inherit</dfn>
value</h4>

<p>Each property may also have a cascaded value of ''inherit'', which
means that, for a given element, the property takes as specified
value the computed value of the element's parent. The ''inherit'' value
can be used to enforce inheritance of values, and it can also be used on
properties that are not normally inherited.

<p>If the ''inherit'' value is set on the root element, the property is
assigned its initial value.

<div class="example"><p>In the example below, the 'color' and 'background' properties are set on
the BODY element. On all other elements, the 'color' value will be
inherited and the background will be transparent. If these rules are
part of the user's style sheet, black text on a white background will
be enforced throughout the document.

<pre class="lang-css">
body {
  color: black !important;
  background: white !important;
}

* {
  color: inherit !important;
  background: transparent !important;
}
</pre>

</div>


<!-- Add another example?. Check out:
https://lists.w3.org/Archives/Member/w3c-css-wg/1998JanMar/0054.html
-IJ, HWL -->

<h3 id="at-import">The @import rule</h3>

<p>The <dfn>@import</dfn> rule allows users to
import style rules from other style sheets. In CSS&nbsp;2, any
@import rules must precede all other rules (except the @charset rule,
if present). See the <a href="#at-rules">section on
parsing</a> for when user agents must ignore @import rules. The
''@import'' keyword must be followed by the URI of the style sheet to
include. A string is also allowed; it will be interpreted as if it had
url(...) around it.

<div class="example"><p>
The following lines are equivalent in meaning and illustrate both
''@import'' syntaxes (one with "url()" and one with a bare string):</p>

<pre class="lang-css">
@import "mystyle.css";
@import url("mystyle.css");
</pre>
</div>

<p>So that user agents can avoid retrieving resources for unsupported
<a href="#media">media types</a>, authors may specify
media-dependent <a data-lt="@import">@import</a> rules.  These <dfn data-lt="conditional import|media-dependent import">conditional
imports</dfn> specify comma-separated media types after the URI.

<div class="example">
<p>The following rules illustrate how @import rules can be made media-dependent:</p>

<pre class="lang-css">
@import url("fineprint.css") print;
@import url("bluish.css") projection, tv;
</pre>
</div>

<p>In the absence of any media types, the import is
unconditional. Specifying ''all'' for the medium has the same effect.
The import only takes effect if the target medium matches the media
list.

<p>A target medium matches a media list if one of the items in the
media list is the target medium or ''all''.

<p class="note">Note that Media Queries [[MEDIAQ]] extends the syntax of
media lists and the definition of matching.

<p>When the same style sheet is imported or linked to a document in
multiple places, user agents must process (or act as though they do)
each link as though the link were to a separate style sheet.

<h3 id="cascade">The cascade</h3>

<p>Style sheets may have three different origins: author, user, and
user agent.</p>

<ul>
<li><strong>Author</strong>. The author specifies style sheets
for a source document according to the conventions of the document
language. For instance, in HTML, style sheets may be included in the
document or linked externally.

<li><strong>User</strong>: The user may be able to specify style
information for a particular document. For example, the user may
specify a file that contains a style sheet or the user agent may
provide an interface that generates a user style sheet (or behaves as
if it did).

<li><strong>User agent</strong>: <a href="#conformance">Conforming user agents</a> must apply
a <dfn id="default-style-sheet">default style sheet</dfn>
(or behave as if they did). A user agent's default style sheet should
present the
elements of the document language in ways that satisfy general
presentation expectations for the document language (e.g., for visual
browsers, the EM element in HTML is presented using an italic
font). See <a href="#html-stylesheet">A sample style sheet for HTML
</a> for a recommended default style sheet for HTML documents.

<p class="note">Note that the user may modify system settings (e.g.,
system colors) that affect the default style sheet. However, some user
agent implementations make it impossible to change the values in the
default style sheet.
</ul>

<p>Style sheets from these three origins will overlap in scope, and
they interact according to the cascade.

<p>The CSS <dfn>cascade</dfn>
assigns a weight to each style rule. When several rules apply, the one
with the greatest weight takes precedence.

<p>By default, rules in author style sheets have more weight than
rules in user style sheets. Precedence is reversed, however, for
"!important" rules. All user and author rules have more weight
than rules in the UA's default style sheet.


<h4 id="cascading-order">Cascading order</h4>

<p>To find the value for an element/property combination, user agents
must apply the following sorting order:</p>

<ol>
    <li>
      Find all declarations that apply to the element and property in
      question, for the target <a href="#media">media type</a>.
      Declarations apply if the associated selector <a href="#selector">matches</a> the element in question and the
      target medium matches the media list on all @media rules
      containing the declaration and on all links on the path through
      which the style sheet was reached.

    <li>Sort  according to importance (normal or important)
and origin (author, user, or user agent). In ascending order of
precedence:

<ol>
<li>user agent declarations
<li>user normal declarations
<li>author normal declarations
<li>author important declarations
<li>user important declarations
</ol>

    <li>
      Sort rules with the same importance and origin by <a href="#specificity">specificity</a>
      of selector: more specific
      selectors will override more general ones.  Pseudo-elements and
      pseudo-classes are counted as normal elements and classes,
      respectively.

    <li>Finally, sort by order specified: if two declarations have the
    same weight, origin and specificity, the latter specified wins.
    Declarations in imported style sheets are considered to be before any
    declarations in the style sheet itself.

</ol>

<p>Apart from the "!important" setting on individual declarations,
this strategy gives author's style sheets higher weight than those of
the reader. User agents must give the user the ability to turn off the
influence of specific author style sheets, e.g., through a pull-down
menu. Conformance to UAAG 1.0 checkpoint 4.14 satisfies this condition [[!UAAG10]].

<h4 id="important-rules">!important rules</h4>

<p>CSS attempts to create a balance of power between author
and user style sheets. By default, rules in an author's style
sheet override those in a user's style sheet (see cascade
rule 3).

<p>However, for balance, an "!important" declaration (the delimiter token
"!" and keyword "important" follow the declaration) takes precedence over
a normal declaration.  Both author and user style sheets may contain
"!important" declarations, and user "!important" rules override author
"!important" rules. This CSS feature improves accessibility
of documents by giving users with special requirements (large
fonts, color combinations, etc.) control over presentation.

<p>Declaring a <a data-lt="shorthand property">shorthand property</a> (e.g., 'background') to be "!important" is
equivalent to declaring all of its sub-properties to be "!important".

<div class="example">
<p>The first rule in the user's style sheet in the following example
contains an "!important" declaration, which overrides the corresponding
declaration in the author's style sheet.  The second declaration
will also win due to being marked "!important". However, the third
rule in the user's style sheet is not "!important" and will therefore
lose to the second rule in the author's style sheet (which happens to
set style on a shorthand property). Also, the third author rule will
lose to the second author rule since the second rule is
"!important". This shows that "!important" declarations have a
function also within author style sheets.

<pre class="lang-css">
/* From the user's style sheet */
p { text-indent: 1em ! important }
p { font-style: italic ! important }
p { font-size: 18pt }

/* From the author's style sheet */
p { text-indent: 1.5em !important }
p { font: normal 12pt sans-serif !important }
p { font-size: 24pt }
</pre>
</div>


<h4 id="specificity">Calculating a selector's specificity</h4>

<p>A selector's specificity is calculated as follows:</p>

<ul>
<li>count 1 if the declaration is from is a style attribute ([[!css-style-attr]]) rather
than a rule with a
selector, 0 otherwise (= a) (In HTML, values of an element's "style"
attribute are style attributes ([[HTML#the-style-attribute]]). These rules have no selectors, so
a=1, b=0, c=0, and d=0.)

<li>count the number of ID attributes in the selector (= b)

<li>count the number of other attributes and pseudo-classes
in the selector (= c)

<li>count the number of element names and pseudo-elements in the selector (= d)
</ul>

<p>The specificity is based only on the form of the selector. In
particular, a selector of the form "[id=p33]" is counted as an
attribute selector (a=0, b=0, c=1, d=0), even if the id attribute is
defined as an "ID" in the source document's DTD.

<p>Concatenating the four numbers a-b-c-d (in a number system with a large
base) gives the specificity.

<div class="example"><p>
Some examples:

<pre>
 *             {}  /* a=0 b=0 c=0 d=0 -&gt; specificity = 0,0,0,0 */
 li            {}  /* a=0 b=0 c=0 d=1 -&gt; specificity = 0,0,0,1 */
 li:first-line {}  /* a=0 b=0 c=0 d=2 -&gt; specificity = 0,0,0,2 */
 ul li         {}  /* a=0 b=0 c=0 d=2 -&gt; specificity = 0,0,0,2 */
 ul ol+li      {}  /* a=0 b=0 c=0 d=3 -&gt; specificity = 0,0,0,3 */
 h1 + *[rel=up]{}  /* a=0 b=0 c=1 d=1 -&gt; specificity = 0,0,1,1 */
 ul ol li.red  {}  /* a=0 b=0 c=1 d=3 -&gt; specificity = 0,0,1,3 */
 li.red.level  {}  /* a=0 b=0 c=2 d=1 -&gt; specificity = 0,0,2,1 */
 #x34y         {}  /* a=0 b=1 c=0 d=0 -&gt; specificity = 0,1,0,0 */
 style=""          /* a=1 b=0 c=0 d=0 -&gt; specificity = 1,0,0,0 */
</pre>
</div>

<div class="lang-html example">

<pre>
&lt;HEAD&gt;
&lt;STYLE type="text/css"&gt;
  #x97z { color: red }
&lt;/STYLE&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;
&lt;P ID=x97z style="color: green"&gt;
&lt;/BODY&gt;
</pre>

<p>In the above example, the color of the P element would be
green. The declaration in the "style" attribute will override the one in
the STYLE element because of cascading rule 3, since it has a higher
specificity.
</div>


<h4 id="preshint">Precedence of non-CSS presentational hints</h4>

<p>The UA may choose to honor presentational attributes in an HTML source
document. If so, these attributes are translated to the corresponding
CSS rules with specificity equal to 0, and are treated as if they were
inserted at the start of the author style sheet. They may therefore be
overridden by subsequent style sheet rules. In a transition phase,
this policy will make it easier for stylistic attributes to coexist
with style sheets.

<p>For HTML, any attribute that is not in the following list should be
considered presentational: abbr, accept-charset, accept, accesskey,
action, alt, archive, axis, charset, checked, cite, class, classid,
code, codebase, codetype, colspan, coords, data, datetime, declare,
defer, dir, disabled, enctype, for, headers, href, hreflang,
http-equiv, id, ismap, label, lang, language, longdesc, maxlength,
media, method, multiple, name, nohref, object, onblur, onchange,
onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onload,
onload, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup,
onreset, onselect, onsubmit, onunload, onunload, profile, prompt,
readonly, rel, rev, rowspan, scheme, scope, selected, shape, span,
src, standby, start, style, summary, title, type (except on LI, OL and
UL elements), usemap, value, valuetype, version.

<p>For other languages, all document language-based styling must be
translated to the corresponding CSS and either enter the cascade at
the user agent level or, as with HTML presentational hints, be treated
as author level rules with a specificity of zero placed at the start
of the author style sheet.

<div class="example">

<p>The following user style sheet would override the font weight of
<{b}> elements in all documents, and the color of <{font}>
elements with color attributes in XML documents. It would not affect
the color of any <{font}> elements with color attributes in HTML
documents:

<pre class="lang-css">
b { font-weight: normal; }
font[color] { color: orange; }
</pre>

<p>The following, however, would override the color of font elements in all documents:

<pre class="lang-css">
font[color] { color: orange ! important; }
</pre>
</div>







<h2 id="media"><span id="q7.0">Media types</span></h2>

<h3 id="media-intro">Introduction to media types</h3>

<p>One of the most important features of style sheets is that they
specify how a document is to be presented on different media: on the
screen, on paper, with a speech synthesizer, with a braille device,
etc.

<p>Certain CSS properties are only designed for certain media (e.g.,
the 'page-break-before' property
only applies to paged media). On occasion, however, style sheets for
different media types may share a property, but require different
values for that property. For example, the 'font-size' property is useful both
for screen and print media. The two media types are different enough
to require different values for the common property; a document will
typically need a larger font on a computer screen than on paper.
Therefore, it is necessary to express that a style sheet, or a
section of a style sheet, applies to certain media types.

<h3 id="media-sheets">Specifying media-dependent style sheets</h3>
<p>There are currently two ways to specify media dependencies for
style sheets:</p>

<ul>

<li>Specify the target medium from a style sheet with the <a data-lt="@media">@media</a> or <a data-lt="@import">@import</a> at-rules.

<div class="example">
<pre class="lang-css">
@import url("fancyfonts.css") screen;
@media print {
  /* style sheet for print goes here */
}
</pre>
</div>

<li>Specify the target medium within the document language. For
example, in HTML 4 ([[HTML401]]), the "media" attribute on the LINK
element specifies the target media of an external style sheet:

<div class="lang-html example">

<pre>
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
   &lt;HEAD&gt;
      &lt;TITLE&gt;Link to a target medium&lt;/TITLE&gt;
      &lt;LINK REL="stylesheet" TYPE="text/css"
     MEDIA="print, handheld" HREF="foo.css"&gt;
   &lt;/HEAD&gt;
   &lt;BODY&gt;
      &lt;P&gt;The body...
   &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>
</div>
</ul>

<p>The <a href="#at-import">@import</a> rule is defined in
the <a href="#assigning">chapter on the cascade</a>.


<h4 id="at-media-rule">The <dfn id="at-ruledef-media" dfn-type="at-rule" data-export="">@media</dfn> rule</h4>

<p>An <a>@media</a> rule
specifies the target <a href="#media-types">media types</a> (separated
by commas) of a set of <a href="#tokenization">statements</a> (delimited by curly
braces). Invalid statements must be ignored per <a href="#rule-sets">4.1.7 "Rule sets, declaration blocks,
and selectors"</a> and <a href="#parsing-errors">4.2
"Rules for handling parsing errors."</a> The <a data-lt="@media">@media</a> construct allows style
sheet rules for various media in the same style sheet:</p>

<pre class="example lang-css">
  @media print {
    body { font-size: 10pt }
  }
  @media screen {
    body { font-size: 13px }
  }
  @media screen, print {
    body { line-height: 1.2 }
  }
</pre>

<p>Style rules outside of @media rules apply to all media types
that the style sheet applies to. At-rules inside @media are invalid in
CSS&nbsp;2.

<h3 id="media-types">Recognized media types</h3>

<!--
<p>[say that the media names are normative but the table of
media groups below is informative, i.e., cannot be tested. The "media"
line in each property is likewise informative. We expect profiles to
eventually define what properties apply where. Also explain this in
1.3.2.]

<p>A CSS <span class="index-def" data-term="media type"><dfn>media
type</dfn></span> names a set of CSS properties.  A user agent that
claims to support a media type by name must implement all of the
properties that apply to that media type.

-->

<p>The names chosen for CSS media types reflect target devices for
which the relevant properties make sense. In the following list of CSS
media types the names of media types are normative, but the
descriptions are informative. Likewise, the "Media" field in the
description of each property is informative.

<dl>
<dt><dfn class="css" dfn-for="@media" dfn-type="value" id="valdef-media-all">all</dfn>
<dd>Suitable for all devices.

<dt><dfn class="css" dfn-for="@media" dfn-type="value" id="valdef-media-braille">braille</dfn>
<dd>Intended for braille tactile feedback devices.

<dt><dfn class="css" dfn-for="@media" dfn-type="value" id="valdef-media-embossed">embossed</dfn>
<dd>Intended for paged braille printers.

<dt><dfn class="css" dfn-for="@media" dfn-type="value" id="valdef-media-handheld">handheld</dfn>
<dd>Intended for handheld devices (typically small
screen, limited bandwidth).

<dt><dfn class="css" dfn-for="@media" dfn-type="value" id="valdef-media-print">print</dfn>
<dd>Intended for paged material and for documents viewed on
screen in print preview mode.  Please consult the section on <a href="#the-page">paged media</a> for information about formatting
issues that are specific to paged media.

<dt><dfn class="css" dfn-for="@media" dfn-type="value" id="valdef-media-projection">projection</dfn>
<dd>Intended for projected presentations, for example projectors.
Please consult the section on <a href="#the-page">paged media</a> for
information about formatting issues that are specific to paged media.

<dt><dfn class="css" dfn-for="@media" dfn-type="value" id="valdef-media-screen">screen</dfn>
<dd>Intended primarily for color computer screens.

<dt><dfn class="css" dfn-for="@media" dfn-type="value" id="valdef-media-speech">speech</dfn>
<dd>Intended for speech synthesizers. Note: CSS2&nbsp;(1998) had a similar media type
called ''aural'' for this purpose.

<dt><dfn class="css" dfn-for="@media" dfn-type="value" id="valdef-media-tty">tty</dfn>
<dd>Intended for media using a fixed-pitch character grid (such as
teletypes, terminals, or portable devices with limited display
capabilities). Authors should not use <a href="#length-units">pixel units</a> with the "tty" media
type.

<dt><dfn class="css" dfn-for="@media" dfn-type="value" id="valdef-media-tv">tv</dfn>
<dd>Intended for television-type devices (low
resolution, color, limited-scrollability screens, sound available).
</dl>

<p>Media type names are case-insensitive.

<p>Media types are mutually exclusive in the sense that a user agent can
only support one media type when rendering a document. However, user
agents may use different media types on different canvases. For
example, a document may (simultaneously) be shown in ''screen'' mode on
one canvas and ''print'' mode on another canvas.

<p>Note that a multimodal media type is still only one media
type. The ''tv'' media type, for example, is a multimodal media
type that renders both visually and aurally to a single canvas.

<p>@media and @import rules with unknown media types (that are
nonetheless valid identifiers) are treated as if the unknown media
types are not present. If an @media/@import rule contains a malformed
media type (not an identifier) then the statement is invalid.

<p class="note"><em><strong>Note:</strong> Media Queries supersedes this
error handling.</em>

<div class="example">
<p>For example, in the following snippet, the rule on the P element applies
in ''screen'' mode (even though the ''3D'' media type is not known).

<pre class="lang-css">
@media screen, 3D {
  P { color: green; }
}
</pre>
</div>


<div class="note"><p>
<em><strong>Note.</strong>
Future updates of CSS may extend the list of media types. Authors
should not rely on media type names that are not yet defined
by a CSS specification.
</em>
</div>

<section class="non-normative">
<h4 id="media-groups">Media groups</h4>

<p><em>This section is informative, not normative.</em></p>

<p>Each CSS property definition specifies which media types the
property applies to. Since properties generally apply to several media
types, the "Applies to media" section of each property definition
lists <dfn>media groups</dfn>
rather than individual media types. Each property applies to all media
types in the media groups listed in its definition.

<p>CSS&nbsp;2 defines the following media groups: </p>
<ul>
<li>
<dfn data-lt="'continuous' media group" id="continuous-media-group">continuous</dfn>
or <dfn data-lt="'paged' media group" id="paged-media-group">paged</dfn>.

<li><dfn data-lt="'visual' media group"><span id="visual-media-group"> <strong>visual</strong></span>,</dfn>
<dfn data-lt="'audio' media group"><span id="audio-media-group"><strong>audio</strong></span>,</dfn>
<dfn data-lt="'speech' media group"><span id="speech-media-group"><strong>speech</strong></span>,</dfn>
or <dfn data-lt="'tactile' media group" id="tactile-media-group">tactile</dfn>.
<li><dfn data-lt="'grid' media group" id="grid-media-group">grid</dfn> (for
character grid devices), or
<dfn data-lt="'bitmap' media group" id="bitmap-media-group">bitmap</dfn>.

<li><dfn data-lt="'interactive media group" id="interactive-media-group">interactive</dfn> (for
devices that allow user interaction), or
<dfn data-lt="'static' media group" id="static-media-group">static</dfn> (for
those that do not).

<li><dfn data-lt="'all' media group" id="all-media-group"> all</dfn>
(includes all media types)
</ul>

<p>The following table shows the relationships
between media groups and media types:</p>

<table>
<caption>Relationship between media groups and media types</caption>
<tr><th>Media Types <th colspan="4">Media Groups
<tr><th>&nbsp;
    <th>continuous/paged
    <th>visual/audio/speech/tactile
    <th>grid/bitmap
    <th>interactive/static
<!--
<tr><th>audio<td>continuous<td>audio<td>N/A<td>both</tr>
<tr><th>aural<td>continuous<td>speech, audio<td>N/A<td>both</tr>
-->
<tr><th>braille<td>continuous<td>tactile<td>grid<td>both</tr>
<tr><th>embossed<td>paged<td>tactile<td>grid<td>static</tr>
<tr><th>handheld<td>both<td>visual, audio, speech<td>both<td>both</tr>
<tr><th>print<td>paged<td>visual<td>bitmap<td>static</tr>
<tr><th>projection<td>paged<td>visual<td>bitmap<td>interactive</tr>
<tr><th>screen<td>continuous<td>visual, audio<td>bitmap<td>both</tr>
<tr><th>speech<td>continuous<td>speech<td>N/A<td>both</tr>
<tr><th>tty<td>continuous<td>visual<td>grid<td>both</tr>
<tr><th>tv<td>both<td>visual, audio<td>bitmap<td>both</tr>
</table>
</section>





<h2 id="box-model">Box model</h2>

<p>The CSS box model describes the rectangular boxes that are
generated for elements in the <a href="#doctree">document
tree</a> and laid out according to the <a href="#visuren">visual formatting
model</a>.

<h3 id="box-dimensions">Box dimensions</h3>

<p>Each box has a
<dfn data-lt="content (of a box)|content area" id="box-content-area">
content area</dfn> (e.g.,
text, an image, etc.) and optional surrounding
<dfn data-lt="padding (of a box)|padding" id="box-padding-area">
padding</dfn>,
<dfn data-lt="border (of a box)|border" id="box-border-area">
border</dfn>, and
<dfn data-lt="margin (of a box)|margin" id="box-margin-area">
margin</dfn> areas; the size
of each area is specified by properties defined below.  The following
diagram shows how these areas relate and the terminology used to refer
to pieces of margin, border, and padding:</p>

<div class="figure">
<p><img src="./images/boxdim.png" alt="Image illustrating the relationship between content, padding, borders, and margins." id="img-boxdim"></p>
</div>

<p>The margin, border, and padding can be broken down into top, right,
bottom, and left segments (e.g., in the diagram, "LM" for left margin,
"RP" for right padding, "TB" for top border, etc.).

<p>The perimeter of each of the four areas (content, padding, border,
and margin) is called an "edge", so each box has four edges:</p>

<dl>
<dt><dfn id="content-edge">content edge</dfn>
or <dfn id="inner-edge">inner edge</dfn>
<dd>The content edge surrounds the rectangle given by the <a href="#Computing_widths_and_margins">width</a> and <a href="#Computing_heights_and_margins">height</a>
of the box, which often depend on the element's <a href="#rendered-content">rendered content</a>.
The four content edges define the
box's <dfn>content box</dfn>.
<dt><dfn id="padding-edge">padding edge</dfn>
<dd>The padding edge surrounds the box padding. If the padding
has 0 width, the padding edge is the same as the content edge.
The four padding edges define the
box's <dfn>padding box</dfn>.
<dt><dfn id="border-edge">border edge</dfn>
<dd>The border edge surrounds the box's border. If the border
has 0 width, the border edge is the same as the padding edge.
The four border edges define the box's <dfn>border
box</dfn>.
<dt><dfn id="margin-edge">margin edge</dfn>
or <dfn id="outer-edge">outer
edge</dfn>
<dd>The margin edge surrounds the box margin. If the margin
has 0 width, the margin edge is the same as the border edge.
The four margin edges define the box's <dfn>margin
box</dfn>.
</dl>

<p>Each edge may be broken down into a top, right, bottom, and left
edge.

<p>The dimensions of the content area of a box &mdash; the <dfn id="content-width">content width</dfn> and <dfn id="content-height">content height</dfn> &mdash;
depend on several factors: whether the element generating
the box has the 'width'
or 'height' property
set, whether the box contains text or other boxes, whether the
box is a table, etc. Box widths and heights are discussed
in the chapter on <a href="#visudet">visual formatting
model details</a>.

<p>The background style of the content, padding, and border areas of a
box is specified by the 'background' property of the
generating element. Margin backgrounds are always transparent.

<h3 id="mpb-examples">Example of margins, padding, and borders</h3>

<p>This example illustrates how margins, padding, and borders
interact. The example HTML document:

<pre class="lang-html example">
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
  &lt;HEAD&gt;
    &lt;TITLE&gt;Examples of margins, padding, and borders&lt;/TITLE&gt;
    &lt;STYLE type="text/css"&gt;
      UL {
        background: yellow;
        margin: 12px 12px 12px 12px;
        padding: 3px 3px 3px 3px;
                                     /* No borders set */
      }
      LI {
        color: white;                /* text color is white */
        background: blue;            /* Content, padding will be blue */
        margin: 12px 12px 12px 12px;
        padding: 12px 0px 12px 12px; /* Note 0px padding right */
        list-style: none             /* no glyphs before a list item */
                                     /* No borders set */
      }
      LI.withborder {
        border-style: dashed;
        border-width: medium;        /* sets border width on all sides */
        border-color: lime;
      }
    &lt;/STYLE&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
    &lt;UL&gt;
      &lt;LI&gt;First element of list
      &lt;LI class="withborder"&gt;Second element of list is
           a bit longer to illustrate wrapping.
    &lt;/UL&gt;
  &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>

<p>results in a <a href="#doctree">document tree</a> with
(among other relationships) a UL element that has two LI
children.

<p>The first of the following diagrams illustrates what this example
would produce. The second illustrates the relationship between the
margins, padding, and borders of the UL elements and those of its
children LI elements. (Image is not to scale.)</p>

<div class="figure">
<p><img src="./images/boxdimeg.png" alt="Image illustrating how parent and child margins, borders, and padding relate." id="img-boxdimeg"></p>
</div>

<p>Note that:</p>

<ul>

<li>The <a href="#content-width">content width</a> for each LI box is
calculated top-down; the <a href="#containing-block">containing
block</a> for each LI box is established by the UL element.

<li>The margin box height of each LI box depends on its <a href="#content-height">content height</a>, plus top and bottom
padding, borders, and margins. Note that vertical margins between the
LI boxes <a href="#collapsing-margins">collapse.</a>

<li>The right padding of the LI boxes has been set to zero width
(the 'padding' property). The
effect is apparent in the second illustration.

<li>The margins of the LI boxes are transparent &mdash; margins are always
transparent &mdash; so the background color (yellow) of the UL padding and
content areas shines through them.

<li>The second LI element specifies a dashed border (the
'border-style' property).
</ul>

<h3 id="margin-properties">Margin properties:
'margin-top',
'margin-right',
'margin-bottom',
'margin-left', and
'margin'</h3>

<p>Margin properties specify the width of the <a href="#box-margin-area">margin area</a> of a box.  The 'margin' shorthand property sets the
margin for all four sides while the other margin properties only set
their respective side.  These properties apply to all elements, but
vertical margins will not have any effect on non-replaced inline
elements.

<p>The properties defined in this section refer to the <dfn id="value-def-margin-width">&lt;margin-width&gt;</dfn>
value type, which may take one of the following values:</p>

<dl>
<dt><span class="value-inst-length"><strong><<length>></strong></span>
<dd>Specifies a fixed width.
<dt><span class="value-inst-percentage"><strong><<percentage>></strong></span>
<dd>The percentage is calculated
with respect to the <em>width</em> of the generated box's
<a href="#containing-block">containing block</a>.
<span class="note">Note that this is true for 'margin-top' and 'margin-bottom' as well.</span>
If the containing block's width depends on this element, then the
resulting layout is undefined in CSS&nbsp;2.
<dt><strong>auto</strong>
<dd>See the section on <a href="#Computing_widths_and_margins">calculating widths and
margins</a> for behavior.
</dl>

<p>Negative values for margin properties are allowed, but there may be
implementation-specific limits.

</p>
<xmp class="propdef">
Name: margin-top, margin-bottom
Value: <<margin-width>> | inherit
Initial: 0
Applies to: all elements except elements with table display
    types other than table-caption, table and inline-table
Inherited: no
Percentages: refer to width of containing block
Media: visual
Computed Value: the percentage as specified or the absolute length
Animation type: by computed value type
</xmp>



<p class="note">These properties have no effect on non-replaced inline
elements.</p>

<xmp class="propdef">
Name: margin-right, margin-left
Value: <<margin-width>> | inherit
Initial: 0
Applies to: all elements except elements with table display
    types other than table-caption, table and inline-table
Inherited: no
Percentages: refer to width of containing block
Media: visual
Computed Value: the percentage as specified or the absolute length
Animation type: by computed value type
</xmp>



<p>These properties set the top, right, bottom, and left margin of a
box.

<div class="example"><p>
<pre class="lang-css">
h1 { margin-top: 2em }
</pre>
</div>

<xmp class="propdef shorthand">
Name: margin
Value: <<margin-width>>{1,4} | inherit
Initial: see individual properties
Applies to: all elements except elements with table display
    types other than table-caption, table and inline-table
Inherited: no
Percentages: refer to width of containing block
Media: visual
Computed Value: see individual properties
</xmp>



<p> The 'margin' property is a
shorthand property for setting 'margin-top', 'margin-right', 'margin-bottom', and 'margin-left' at the same place in
the style sheet.

<p> If there is only one component value, it applies to all
sides. If there are two values, the top and bottom margins
are set to the first value and the right and left margins are
set to the second. If there are three values, the top is
set to the first value, the left and right are set to the
second, and the bottom is set to the third. If there are
four values, they apply to the top, right, bottom, and left,
respectively.

<div class="example"><p>
<pre class="lang-css">
body { margin: 2em }         /* all margins set to 2em */
body { margin: 1em 2em }     /* top &amp; bottom = 1em, right &amp; left = 2em */
body { margin: 1em 2em 3em } /* top=1em, right=2em, bottom=3em, left=2em */
</pre>

<p> The last rule of the example above is equivalent to the example
below:

<pre class="lang-css">
body {
  margin-top: 1em;
  margin-right: 2em;
  margin-bottom: 3em;
  margin-left: 2em;        /* copied from opposite side (right) */
}
</pre>
</div>

<h4 id="collapsing-margins">Collapsing margins</h4>

<p>In CSS, the adjoining margins of two or more boxes (which might or
might not be siblings) can combine to form a single margin. Margins
that combine this way are said to <dfn>collapse</dfn>, and the
resulting combined margin is called a <dfn data-lt="collapsed margin|collapsing margin">collapsed margin</dfn>.

<p>Adjoining vertical margins collapse, except:

<ul>
  <li>Margins of the root element's box do not collapse.

  <li>If the top and bottom margins of an element with <a href="#clearance">clearance</a> are adjoining, its
  margins collapse with the adjoining margins of following siblings
  but that resulting margin does not collapse with the bottom margin
  of the parent block.
</ul>

<p>Horizontal margins never collapse.

<p id="what-is-adjoining">Two margins are <dfn data-lt="adjoining margins|adjoining">adjoining</dfn> if and only if:

<ul>
  <li>both belong to in-flow <a href="#block-boxes">block-level boxes</a> that
  participate in the same <a href="#block-formatting">block formatting context</a>

  <li>no line boxes, no clearance, no padding and no border separate
  them <span class="note">(Note that <a href="#phantom-line-box">certain zero-height line
  boxes</a> (see <a href="#inline-formatting">9.4.2</a>)
  are ignored for this purpose.)</span>

  <li>both belong to vertically-adjacent box edges, i.e. form one of
  the following pairs:

  <ul>
    <li>top margin of a box and top margin of its first in-flow child

    <li>bottom margin of box and top margin of its next in-flow
    following sibling

    <li>bottom margin of a last in-flow child and bottom margin of its
    parent if the parent has ''height/auto'' computed height

    <li>top and bottom margins of a box that does not establish a new
    block formatting context and that has zero computed 'min-height', zero or ''height/auto''
    computed 'height', and no
    in-flow children
  </ul>
</ul>

<p>A collapsed margin is considered adjoining to another margin if any
of its component margins is adjoining to that margin.

<p class="note"><strong>Note.</strong> Adjoining margins can be
generated by elements that are not related as siblings or ancestors.

<div class="note">
<p><strong>Note</strong> the above rules imply that:

<ul>
  <li>Margins between a <a href="#floats">floated</a> box
  and any other box do not collapse (not even between a float and its
  in-flow children).

  <li>Margins of elements that establish new block formatting contexts
  (such as floats and elements with 'overflow' other than ''overflow/visible'') do
  not collapse with their in-flow children.

  <li>Margins of <a href="#absolutely-positioned">absolutely positioned</a>
  boxes do not collapse (not even with their in-flow children).

  <li>Margins of inline-block boxes do not collapse (not even with
  their in-flow children).

  <li>The bottom margin of an in-flow block-level element always
  collapses with the top margin of its next in-flow block-level
  sibling, unless that sibling has clearance.

  <li>The top margin of an in-flow block element collapses with its
  first in-flow block-level child's top margin if the element has no
  top border, no top padding, and the child has no clearance.

  <li>The bottom margin of an in-flow block box with a 'height' of ''height/auto'' and a 'min-height' of zero collapses
  with its last in-flow block-level child's bottom margin if the box
  has no bottom padding and no bottom border and the child's bottom
  margin does not collapse with a top margin that has clearance.

  <li>A box's own margins collapse if the 'min-height' property is zero,
  and it has neither top or bottom borders nor top or bottom padding,
  and it has a 'height' of either
  0 or ''height/auto'', and it does not contain a line box, and all of its
  in-flow children's margins (if any) collapse.
</ul>
</div>

<p>When two or more margins collapse, the resulting margin width is
the maximum of the collapsing margins' widths. In the case of negative
margins, the maximum of the absolute values of the negative adjoining
margins is deducted from the maximum of the positive adjoining
margins.  If there are no positive margins, the maximum of the
absolute values of the adjoining margins is deducted from zero.

<p id="collapsed-through">If the top and bottom margins of a box are
adjoining, then it is possible for margins to <dfn>collapse through</dfn> it. In this case,
the position of the element depends on its relationship with the other
elements whose margins are being collapsed.

<ul>
  <li>If the element's margins are collapsed with its parent's top
  margin, the top border edge of the box is defined to be the same as
  the parent's.

  <li>Otherwise, either the element's parent is not taking part in the
  margin collapsing, or only the parent's bottom margin is
  involved. The position of the element's top border edge is the same
  as it would have been if the element had a non-zero bottom border.
</ul>

<p>Note that the positions of elements that have been collapsed
through have no effect on the positions of the other elements with
whose margins they are being collapsed; the top border edge position
is only required for laying out descendants of these elements.


<h3 id="padding-properties">Padding properties:
'padding-top',
'padding-right',
'padding-bottom',
'padding-left', and
'padding'
</h3>

<p>The padding properties specify the width of the <a href="#box-padding-area">padding area</a> of a box. The 'padding' shorthand property sets the
padding for all four sides while the other padding properties only set
their respective side.

<p>The properties defined in this section refer to the <dfn id="value-def-padding-width" dfn-type="type">&lt;padding-width&gt;
</dfn> value type, which may take one of the following values:</p>

<dl dfn-type="value" dfn-for="&lt;padding-width&gt;">
<dt><dfn><<length>></dfn>
<dd>Specifies a fixed width.
<dt><dfn><<percentage>></dfn>
<dd>The percentage is calculated with
respect to the <em>width</em> of the generated box's <a href="#containing-block">containing block</a>, even for
'padding-top' and 'padding-bottom'.
If the containing block's width depends on this element, then the
resulting layout is undefined in CSS&nbsp;2.
</dl>

<p>Unlike margin properties, values for padding values cannot be
negative. Like margin properties, percentage values for padding
properties refer to the width of the generated box's containing block.

</p>
<xmp class="propdef">
Name: padding-top, padding-right, padding-bottom, padding-left
Value: <<padding-width>> | inherit
Initial: 0
Applies to: all elements except table-row-group, table-header-group, table-footer-group, table-row, table-column-group and table-column
Inherited: no
Percentages: refer to width of containing block
Media: visual
Computed Value: the percentage as specified or the absolute length
Animation type: by computed value type
</xmp>



<p>These properties set the top, right, bottom, and left padding of
a box.

<div class="example"><p>
<pre class="lang-css">
blockquote { padding-top: 0.3em }
</pre>
</div>

<xmp class="propdef shorthand">
Name: padding
Value: <<padding-width>>{1,4} | inherit
Initial: see individual properties
Applies to: all elements except table-row-group, table-header-group, table-footer-group, table-row, table-column-group and table-column
Inherited: no
Percentages: refer to width of containing block
Media: visual
Computed Value: see individual properties
</xmp>



<p> The 'padding' property is a
shorthand property for setting 'padding-top', 'padding-right', 'padding-bottom', and 'padding-left' at the same place
in the style sheet.

<p> If there is only one component value, it applies to all
sides. If there are two values, the top and bottom paddings
are set to the first value and the right and left paddings are
set to the second. If there are three values, the top is
set to the first value, the left and right are set to the
second, and the bottom is set to the third. If there are
four values, they apply to the top, right, bottom, and left,
respectively.

<p> The surface color or image of the padding area is specified via
the 'background' property:

<div class="example"><p>
<pre class="lang-css">
h1 {
  background: white;
  padding: 1em 2em;
}
</pre>

<p> The example above specifies a ''1em'' vertical padding ('padding-top' and 'padding-bottom') and a ''2em''
horizontal padding ('padding-right' and 'padding-left'). The ''em'' unit is
<a href="#absrel-units">relative</a>
to the element's font size: ''1em'' is equal to the size of the
font in use.
</div>

<h3 id="border-properties">Border properties</h3>

<p>The border properties specify the width, color, and style of the <a href="#box-border-area">border area</a> of a box. These properties
apply to all elements.


<div class="note"><p>
<em><strong>Note.</strong>
Notably for HTML,
user agents may render borders for certain user interface elements (e.g.,
buttons, menus, etc.) differently than for
"ordinary" elements.
</em>
</div>

<h4 id="border-width-properties">Border width: 'border-top-width', 'border-right-width', 'border-bottom-width',
'border-left-width', and
'border-width'</h4>

<p>The border width properties specify the width of the <a href="#box-border-area">border area</a>.  The properties
defined in this section refer to the <dfn id="value-def-border-width">&lt;border-width&gt;</dfn>
value type, which may take one of the following values:</p>

<dl dfn-for="&lt;border-width&gt;,border-top-width,border-right-width,border-bottom-width,border-left-width,border-width" dfn-type="value" >
<dt><dfn id="valdef-border-width-thin">thin</dfn>
<dd>A thin border.
<dt><dfn id="valdef-border-width-medium">medium</dfn>
<dd>A medium border.
<dt><dfn id="valdef-border-width-thick">thick</dfn>
<dd>A thick border.
<dt><dfn id="valdef-border-width-length"><<length>></dfn>
<dd>The border's thickness has an explicit value. Explicit
border widths cannot be negative.
</dl>

<p>The interpretation of the first three values depends on the user
agent. The following relationships must hold, however:

<p>''border-width/thin'' &le; ''border-width/medium'' &le; ''border-width/thick''.

<p>Furthermore, these widths must be constant throughout a document.

</p>
<xmp class="propdef">
Name: border-top-width, border-right-width, border-bottom-width, border-left-width
Value: <<border-width>> | inherit
Initial: medium
Applies to: *
Inherited: no
Percentages: N/A
Media: visual
Computed Value: absolute length; ''0'' if the border style is ''border-style/none'' or ''border-style/hidden''
Animation type: by computed value type
</xmp>



<p>These properties set the width of the top, right, bottom,
and left border of a box.

</p>
<xmp class="propdef shorthand">
Name: border-width
Value: <<border-width>>{1,4} | inherit
Initial: see individual properties
Applies to: *
Inherited: no
Percentages: N/A
Media: visual
Computed Value: see individual properties
</xmp>



<p> This property is a shorthand property for setting
'border-top-width',
'border-right-width',
'border-bottom-width',
 and
'border-left-width' at
the same place in the style sheet.

<p> If there is only one component value, it applies to all
sides. If there are two values, the top and bottom borders
are set to the first value and the right and left are
set to the second. If there are three values, the top is
set to the first value, the left and right are set to the
second, and the bottom is set to the third. If there are
four values, they apply to the top, right, bottom, and left,
respectively.

<div class="example"><p>
In the examples below, the comments indicate the resulting widths
of the top, right, bottom, and left borders:

<pre class="lang-css">
h1 { border-width: thin }                   /* thin thin thin thin */
h1 { border-width: thin thick }             /* thin thick thin thick */
h1 { border-width: thin thick medium }      /* thin thick medium thick */
</pre>
</div>

<h4 id="border-color-properties">Border color:
'border-top-color',
'border-right-color',
'border-bottom-color',
'border-left-color', and
'border-color'
</h4>

<p>The border color properties specify the color of a box's border.

</p>
<xmp class="propdef">
Name: border-top-color, border-right-color, border-bottom-color, border-left-color
Value: <<color>> | transparent | inherit
Initial: the value of the 'color' property
Applies to: *
Inherited: no
Percentages: N/A
Media: visual
Computed Value: when taken from the 'color' property, the computed value of 'color';
   otherwise, as specified
Animation type: by computed value type
</xmp>


<xmp class="propdef shorthand">
Name: border-color
Value: [ <<color>> | transparent ]{1,4} | inherit
Initial: see individual properties
Applies to: *
Inherited: no
Percentages: N/A
Media: visual
Computed Value: see individual properties
</xmp>



<p>The 'border-color'
property sets the color of the four borders. Values have the following
meanings:</p>

<dl dfn-for="border-color,border-top-color,border-right-color,border-bottom-color,border-left-color" dfn-type="value">
<dt><dfn><<color>></dfn>
<dd>Specifies a color value.
<dt><dfn id="valdef-border-color-transparent" noexport>transparent</dfn>
<dd>The border is transparent (though it may have width).
</dl>


<p>The 'border-color'
property can have from one to four component values, and the values
are set on the different sides as for 'border-width'.

<p>If an element's border color is not specified
with a border property, user agents must use the value
of the element's 'color' property as the
<a href="#computed-value">computed value</a>
for the border color.

<div class="example">
<p>In this  example, the border will be a solid black line.
<pre class="lang-css">
p {
  color: black;
  background: white;
  border: solid;
}
</pre>
</div>

<h4 id="border-style-properties">Border style:
'border-top-style',
'border-right-style',
'border-bottom-style',
'border-left-style', and
'border-style'</h4>

<p>The border style properties specify the line style of a box's
border (solid, double, dashed, etc.). The properties defined in this
section refer to the <dfn id="value-def-border-style">&lt;border-style&gt;</dfn>
value type, which may take one of the following values:</p>

<dl dfn-type="value" dfn-for="&lt;border-style&gt;,border-top-style,border-right-style,border-bottom-style,border-left-style,border-style">
<dt><dfn id="value-def-bo-none">none</dfn>
<dd>No border; the computed border width is zero.
<dt><dfn id="value-def-hidden">hidden</dfn>
<dd>Same as ''border-style/none'', except in terms of <a href="#border-conflict-resolution">border conflict
resolution</a> for <a href="#tables">table elements</a>.
<dt><dfn id="value-def-dotted">dotted</dfn>
<dd>The border is a series of dots.
<dt><dfn id="value-def-dashed">dashed</dfn>
<dd>The border is a series of short line segments.
<dt><dfn id="value-def-solid">solid</dfn>
<dd>The border is a single line segment.
<dt><dfn id="value-def-double">double</dfn>
<dd>The border is two solid lines. The sum of
the two lines and the space between them
equals the value of 'border-width'.
<dt><dfn id="value-def-groove">groove</dfn>
<dd>The border looks as though it were carved
into the canvas.
<dt><dfn id="value-def-ridge">ridge</dfn>
<dd>The opposite of ''<border-style>/groove'': the border
looks as though it were coming out of the canvas.
<dt><dfn id="value-def-inset">inset</dfn>
<dd>The border makes the box look as though
it were embedded in the canvas.
<dt><dfn id="value-def-outset">outset</dfn>
<dd>The opposite of ''<border-style>/inset'': the
border makes the box look as though
it were coming out of the canvas.
</dl>

<p>All borders are drawn on top of the box's background. The color of
borders drawn for values of ''<border-style>/groove'', ''<border-style>/ridge'', ''<border-style>/inset'', and ''<border-style>/outset''
depends on the element's <a href="#border-color-properties">border
color properties</a>, but UAs may choose their own algorithm to
calculate the actual colors used. For instance, if the 'border-color'
has the value ''silver'', then a UA could use a gradient of colors from
white to dark gray to indicate a sloping border.


<!-- Remove? BB 29 Apr 2003
<p><span class="index-inst" data-term="conformance"><a href="conform.html#conformance">Conforming HTML user agents</a></span> may
interpret 'dotted', 'dashed', 'double', 'groove', 'ridge',
'inset', and 'outset' to be 'solid'.
-->

</p>
<xmp class="propdef">
Name: border-top-style, border-right-style, border-bottom-style, border-left-style
Value: <<border-style>> | inherit
Initial: none
Applies to: *
Inherited: no
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>


<xmp class="propdef shorthand">
Name: border-style
Value: <<border-style>>{1,4} | inherit
Initial: see individual properties
Applies to: *
Inherited: no
Percentages: N/A
Media: visual
Computed Value: see individual properties
</xmp>



<p> The 'border-style'
property sets the style of the four borders. It can have from one to
four component values, and the values are set on the different sides as for
'border-width' above.

<div class="example"><p>
<pre class="lang-css">
#xy34 { border-style: solid dotted }
</pre>
<p> In the above example, the horizontal borders will be ''<border-style>/solid'' and
the vertical borders will be ''<border-style>/dotted''.
</div>

<p> Since the initial value of the border styles is ''border-style/none'', no borders
will be visible unless the border style is set.

<h4 id="border-shorthand-properties">Border shorthand properties:
'border-top',
'border-right',
'border-bottom',
'border-left', and
'border'</h4>

<xmp class="propdef shorthand">
Name: border-top, border-right, border-bottom, border-left
Value: [ <<border-width>> || <<border-style>> || <<'border-top-color'>> ] | inherit
Initial: see individual properties
Applies to: *
Inherited: no
Percentages: N/A
Media: visual
Computed Value: see individual properties
</xmp>



<p> This is a shorthand property for setting the width, style, and
color of the top, right, bottom, and left border of a box.

<div class="example"><p>
<pre class="lang-css">
h1 { border-bottom: thick solid red }
</pre>

<p> The above rule will set the width, style, and color of the border
<strong>below</strong> the H1 element. Omitted values are set to
their <a href="#initial-value">initial values</a>. Since
the following rule does not specify a border color, the border will
have the color specified by the
'color' property:

<pre class="lang-css">
H1 { border-bottom: thick solid }
</pre>
</div>

<xmp class="propdef shorthand">
Name: border
Value: [ <<border-width>> || <<border-style>> || <<'border-top-color'>> ] | inherit
Initial: see individual properties
Applies to: *
Inherited: no
Percentages: N/A
Media: visual
Computed Value: see individual properties
</xmp>



<p> The 'border' property is a
shorthand property for setting the same width, color, and style for
all four borders of a box.  Unlike the shorthand 'margin' and 'padding' properties, the 'border' property cannot set different
values on the four borders. To do so, one or more of the other border
properties must be used.

<div class="example"><p>
For example, the first rule below is
equivalent to the set of four rules shown after it:

<pre class="lang-css">
p { border: solid red }
p {
  border-top: solid red;
  border-right: solid red;
  border-bottom: solid red;
  border-left: solid red
}
</pre>
</div>

<p> Since, to some extent, the properties have overlapping
functionality, the order in which the rules are specified is
important.

<div class="example"><p>
Consider this example:
<pre class="lang-css">
blockquote {
  border: solid red;
  border-left: double;
  color: black;
}
</pre>

<p> In the above example, the color of the left border is black,
while the other borders are red. This is due to 'border-left' setting the
width, style, and color. Since the color value is not given by the
'border-left' property, it
will be taken from the 'color'
property. The fact that the 'color' property is set after the 'border-left' property is not
relevant.
</div>


<h3 id="bidi-box-model">The box model for inline elements in bidirectional context</h3>

<p>For each line box, UAs must take the inline boxes generated for
each element and render the margins, borders and padding in visual
order (not logical order).

<p>When the element's 'direction' property is ''direction/ltr'', the
left-most generated box of the first line box in which the element
appears has the left margin, left border and left padding, and the
right-most generated box of the last line box in which the element
appears has the right padding, right border and right margin.

<p>When the element's 'direction' property is ''direction/rtl'', the
right-most generated box of the first line box in which the element
appears has the right padding, right border and right margin, and the
left-most generated box of the last line box in which the element
appears has the left margin, left border and left padding.




</p>
<h2 id="visuren"><span id="q9.0">Visual formatting model</span></h2>

<h3 id="visual-model-intro">Introduction to the visual formatting model</h3>

<p>This chapter and the next describe the <dfn>visual formatting model</dfn>: how user
agents process the <a href="#doctree">document tree</a>
for visual <a href="#media">media</a>.
</p>

<p>In the visual formatting model, each element in the document tree
generates zero or more boxes according to the <a href="#box-model">box
model</a>. The layout of these boxes is governed by:</p>

<ul>
<li><a href="#box-dimensions">box dimensions</a> and <a href="#box-gen">type</a>.
<li><a href="#positioning-scheme">positioning scheme</a>
(normal flow, float, and absolute positioning).
<li>relationships between elements
in the <a href="#doctree">document tree.</a>
<li>external information (e.g., viewport size, <a href="#intrinsic">intrinsic</a> dimensions of images, etc.).
</ul>

<p>The properties defined in this chapter and the next apply to both
<a href="#continuous-media-group">continuous media</a> and
<a href="#paged-media-group">paged media</a>. <span class="paged">
However, the
meanings of the <a href="#margin-properties">margin
properties</a> vary when applied to paged media (see the <a href="#page-margins">page model</a> for details).
</span>
</p>

<p>The visual formatting model does not specify all aspects of
formatting (e.g., it does not specify a letter-spacing algorithm). <a href="#conformance">Conforming user agents</a> may behave
differently for those formatting issues not covered by this
specification.
</p>

<h4 id="viewport">The viewport</h4>

<p>User agents for <a href="#continuous-media-group">continuous media</a>
generally offer users a <dfn>
viewport</dfn> (a window or other
viewing area on the screen) through which users consult a
document. User agents may change the document's layout when the
viewport is resized (see the <a href="#containing-block-details">initial containing block</a>).
</p>
<p>
When the viewport is smaller than the area of the canvas on which
the document is rendered, the user agent should offer a scrolling
mechanism.

There is at most
one viewport per <a href="#canvas">canvas</a>, but user
agents may render to more than one canvas (i.e., provide different
views of the same document).
</p>

<h4 id="containing-block">
Containing blocks
</h4>

<p>In CSS&nbsp;2, many box positions and sizes are calculated with respect
to the edges
of a rectangular box called a containing block.  In
general, generated boxes act as containing blocks for descendant
boxes; we say that a box "establishes" the containing block for its
descendants. The phrase "a box's containing block" means "the
containing block in which the box lives," not the one it generates.
</p>
<p>Each box is given a position with respect to its containing block,
but it is not confined by this containing block; it may <a href="#overflow">overflow</a>.
</p>

<p>The <a href="#containing-block-details">details</a> of
how a containing block's dimensions are calculated are described in
the <a href="#visudet">next chapter</a>.
</p>
<h3 id="box-gen">Controlling box generation</h3>

<p>The following sections describe the types of boxes that may be
generated in CSS&nbsp;2. A box's type affects, in part, its behavior in the
visual formatting model. The 'display' property, described below,
specifies a box's type.
</p>

<h4 id="block-boxes">Block-level elements and block boxes</h4>

<p><dfn id="block-level">Block-level elements</dfn> are those elements of the source document that are formatted visually as
blocks (e.g., paragraphs). The following values of the 'display' property make an element
block-level: ''display/block'', ''display/list-item'', and ''display/table''.
</p>

<p><dfn>Block-level
boxes</dfn> are boxes that participate in
a <a href="#block-formatting">block formatting context.</a> Each
block-level element generates a <dfn id="principal-box">principal block-level
box</dfn> that contains descendant boxes and generated
content and is also the box involved in any positioning scheme.

Some block-level elements may generate additional boxes in addition
to the
principal box: ''display/list-item'' elements. These additional boxes are
placed with respect to the principal box.

<p>Except for table boxes, which are described in a later chapter, and
replaced elements, a block-level box is also a block container box.
A <dfn id="block-container-box">block
container box</dfn> either
contains only block-level boxes or establishes an inline formatting
context and thus contains only inline-level boxes. Not all block
container boxes are block-level boxes: non-replaced inline blocks
and non-replaced table cells are block containers but not block-level
boxes. Block-level boxes that are also block containers are
called <dfn>block
boxes</dfn>.

<p>The three terms "block-level box," "block container box," and
"block box" are sometimes abbreviated as "block" where unambiguous.

<h5 id="anonymous-block-level">Anonymous block boxes</h5>

<p>In a document like this:
</p>
<pre class="lang-html">
&lt;DIV&gt;
  Some text
  &lt;P&gt;More text
&lt;/DIV&gt;
</pre>
<p>
(and assuming the DIV and the P both have 'display: block'), the
DIV appears to have both inline content and block content. To make it
easier to define the formatting, we assume that there is an <em><dfn data-lt="anonymous">anonymous block box</dfn></em>
around "Some text".
</p>
<div class="figure">
<p><img src="images/anon-block.png" alt="diagram showing the three boxes for the example above" id="img-anon-block">
<p class="caption">Diagram showing the
three boxes, of which one is anonymous, for the example above.
</div>

<p>In other words: if a block container box (such as that generated
for the DIV above) has a block-level box inside it (such as the P
above), then we force it to have <em>only</em> block-level boxes
inside it.

<p>When an inline box contains an in-flow block-level box, the inline box
(and its inline ancestors within the same line box) is broken around
the block-level box (and any block-level siblings that are consecutive
or separated only by collapsible whitespace and/or out-of-flow
elements), splitting the inline box into two boxes (even if either
side is empty), one on each side of the block-level box(es). The line
boxes before the break and after the
break are enclosed in anonymous block boxes, and the block-level box
becomes a sibling of those anonymous boxes. When such an inline box is
affected by relative positioning, any resulting translation also
affects the block-level box contained in the inline box.

<div class="example">
<p>This model would apply in the following example if the following
rules:</p>

<pre class="lang-css">
p    { display: inline }
span { display: block }
</pre>

<p>were used with this HTML document:</p>

<pre class="lang-html example"><code class="html">
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;Anonymous text interrupted by a block&lt;/TITLE&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;
&lt;P&gt;
<em>This is anonymous text before the SPAN.</em>
&lt;SPAN&gt;This is the content of SPAN.&lt;/SPAN&gt;
<em>This is anonymous text after the SPAN.</em>
&lt;/P&gt;
&lt;/BODY&gt;
</code></pre>

<p>The P element contains a chunk (C1) of anonymous text followed
by a block-level element followed by another chunk (C2) of anonymous
text. The resulting boxes would be a block box representing the BODY,
containing an anonymous block box around C1, the SPAN block box, and
another anonymous block box around C2.
</div>

<p>The properties of anonymous boxes are inherited from the
enclosing non-anonymous box (e.g., in the example just below the subsection heading "Anonymous block boxes", the one for DIV).
Non-inherited properties have their initial value. For example,
the font of the anonymous box is inherited from the DIV, but the
margins will be 0.
</p>
<p>
Properties set on elements that cause anonymous block boxes to be
generated still apply to the boxes and content of that element. For
example, if a border had been set on the P element in the above
example, the border would be drawn around C1 (open at the end of the
line) and C2 (open at the start of the line).
</p>
<p>
Some user agents have implemented borders on inlines containing
blocks in other ways, e.g., by wrapping such nested blocks inside
"anonymous line boxes" and thus drawing inline borders around such
boxes. As CSS1 and CSS2&nbsp;(1998) did not define this behavior, CSS1-only and
CSS2&nbsp;(1998)-only user agents may implement this alternative model and still
claim conformance to this part of CSS&nbsp;2. This does not apply to UAs
developed after this specification was released.
</p>

<p>Anonymous block boxes are ignored when resolving percentage values
that would refer to it: the closest non-anonymous ancestor box is used
instead. For example, if the child of the anonymous block box inside
the DIV above needs to know the height of its containing block to
resolve a percentage height, then it will use the height of the
containing block formed by the DIV, not of the anonymous block box.

<h4 id="inline-boxes">Inline-level elements and inline boxes</h4>

<p><dfn id="inline-level">
Inline-level
elements</dfn> are those elements of the source document that
do not form new blocks of content; the content is distributed in lines
 (e.g., emphasized pieces of text
within a paragraph, inline images,
etc.). The following values of the 'display' property make an element
inline-level: ''display/inline'', ''display/inline-table'', and ''display/inline-block''.

Inline-level elements generate <dfn>inline-level
boxes</dfn>, which are boxes that participate in an inline
formatting context.

<p>An <dfn id="inline-box">inline
box</dfn> is one that is both inline-level and whose
contents participate in its containing inline formatting context. A
non-replaced element with a 'display' value of ''display/inline'' generates an
inline box.
Inline-level boxes that are not inline boxes (such as replaced
inline-level elements, inline-block elements, and inline-table
elements) are called <dfn>atomic inline-level boxes</dfn> because
they participate in their inline formatting context as a single opaque
box.

<h5 id="anonymous">Anonymous inline boxes</h5>

<p>Any text that is directly contained inside a block container element (not
inside an inline element) must be treated as an anonymous inline
element.

<p>In a document with HTML markup like this:</p>

<div class="lang-html example">
<pre class="lang-html">
&lt;p&gt;Some &lt;em&gt;emphasized&lt;/em&gt; text&lt;/p&gt;
</pre>
</div>

<p>the <code>&lt;p&gt;</code> generates a block box, with several inline boxes inside
it. The box for "emphasized" is an inline box generated by an inline
element (<code>&lt;em&gt;</code>), but the other boxes ("Some" and "text") are inline boxes generated by a block-level element (<code>&lt;p&gt;</code>). The latter are called <dfn>anonymous inline
boxes</dfn>, because they do not have an associated inline-level element.
</p>
<p>Such anonymous inline boxes inherit inheritable properties from
their block parent box. Non-inherited properties have their initial
value. In the example, the color of the anonymous inline boxes is
inherited from the P, but the background is transparent.
</p>

<p>
White space content that would subsequently be collapsed away according to the 'white-space' property does not generate any anonymous inline boxes.
</p>

<p>If it is clear from the context which type of anonymous box is
meant, both anonymous inline boxes and anonymous block boxes are
simply called anonymous boxes in this specification.
</p>
<p>There are more types of anonymous boxes that arise when formatting
<a href="#anonymous-boxes">tables</a>.
</p>
<h4 id="run-in">Run-in boxes</h4>

<p>[This section exists so that the section numbers are the same as in
previous drafts. <code class="lang-css">display: run-in</code> is now defined in CSS level&nbsp;3 (see <a href="/TR/css3-box">CSS basic box model</a>).]

<h4 id="display-prop">The 'display' property</h4>

<xmp class="propdef">
Name: display
Value: inline | block | list-item | inline-block | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-column-group | table-column | table-cell | table-caption | none | inherit
Initial: inline
Applies to: *
Inherited: no
Percentages: N/A
Media: all
Computed Value: see text
Animation type: discrete
</xmp>



<p>The values of this property have the following meanings:</p>

<dl dfn-for="display" dfn-type="value">
<dt><dfn id="value-def-block">block</dfn>
</dt>
<dd>This value causes an element to generate a block box.
</dd>
<dt><dfn id="value-def-inline-block">inline-block</dfn>
</dt>
<dd>This value causes an element to generate an inline-level block
container.
The inside of an inline-block is formatted as a block box, and the
element itself is formatted as an atomic inline-level box.
</dd>
<dt><dfn id="value-def-inline">inline</dfn>
</dt>
<dd>This value causes an element to generate one or more inline boxes.
</dd>
<dt><dfn id="value-def-list-item">list-item</dfn>
</dt>
<dd>This value causes an element (e.g., LI in HTML) to generate a
principal block box and a marker box. For information about
lists and examples of list formatting, please consult the section on
<a href="#lists">lists</a>.
</dd>
<dt><dfn id="valdef-display-none">none</dfn></dt>

<dd>This
value causes an element to not appear in the <a href="#formatting-structure">formatting structure</a> (i.e.,
in visual media the element generates no boxes and has no effect on
layout). Descendant elements do not generate any boxes either; the
element and its content are removed from the formatting structure
entirely. This behavior <strong>cannot</strong> be overridden by
setting the 'display' property
on the descendants.

<p>Please note that a display of ''display/none'' does not create an invisible
box; it creates no box at all. CSS includes mechanisms that enable an
element to generate boxes in the formatting structure that affect
formatting but are not visible themselves. Please consult the section
on <a href="#visibility">visibility</a> for details.
</p>
</dd>
<dt>
<dfn id="value-def-table">table</dfn>,
<dfn id="value-def-inline-table">inline-table</dfn>,
<dfn id="value-def-table-row-group">table-row-group</dfn>,
<dfn id="value-def-table-column">table-column</dfn>,
<dfn id="value-def-table-column-group">table-column-group</dfn>,
<dfn id="value-def-table-header-group">table-header-group</dfn>,
<dfn id="value-def-table-footer-group">table-footer-group</dfn>,
<dfn id="value-def-table-row">table-row</dfn>,
<dfn id="value-def-table-cell">table-cell</dfn>, and
<dfn id="value-def-table-caption">table-caption</dfn>
</dt>
<dd>These values cause an element to behave like a table element
(subject to restrictions described in the chapter on <a href="#tables">tables</a>).
</dd>
</dl>

<p>The computed value is the same as the specified value, except for
positioned and floating elements (see <a href="#dis-pos-flo">Relationships between <css>display</css>, <css>position</css>, and
<css>float</css></a>) and for the root element.
<!--
For the root element, the
computed value is as follows: 'inline-table' and 'table' become
'table', 'none' stays 'none', everything else becomes 'block'.
-->
For the root element, the computed value is changed as described in
the section on the <a href="#dis-pos-flo">relationships between <css>display</css>, <css>position</css>, and <css>float</css></a>.
</p>

<p>Note that although the <a href="#initial-value">initial value</a> of 'display' is ''inline'', 
rules in the user agent's <a href="#default-style-sheet">default style sheet</a> may <a href="#assigning">override</a> this value. 
See the <a href="#html-stylesheet">sample style sheet</a> for HTML 4 in the appendix.
</p>
<div class="example">
<p>Here are some examples of the 'display' property:
</p>
<pre class="lang-css">
p   { display: block }
em  { display: inline }
li  { display: list-item }
img { display: none }      /* Do not display images */
</pre>
</div>


<h3 id="positioning-scheme">Positioning schemes</h3>

<p>In CSS&nbsp;2, a box may be laid out according to three <dfn data-lt="positioning scheme|positioning schemes:">positioning
schemes:</dfn></p>

<ol>
<li><a href="#normal-flow">Normal flow</a>. In CSS&nbsp;2, normal
flow includes <a href="#block-formatting">block formatting</a>
of block-level boxes,
<a href="#inline-formatting">inline formatting</a>
of inline-level boxes, and <a href="#relative-positioning">relative positioning</a> of
block-level and inline-level boxes.
</li>
<li><a href="#floats">Floats</a>. In the float model,
a box is first laid out according to the normal flow, then
taken out of the flow and shifted
to the left or right as far as possible. Content may
flow along the side of a float.
</li>
<li><a href="#absolute-positioning">Absolute positioning</a>.
In the absolute positioning model, a box is removed from
the normal flow entirely (it has no impact on later siblings)
and assigned a position with respect to a containing block.
</li>
</ol>

<p>An element is called <dfn>out of
flow</dfn> if it is floated, absolutely positioned, or is the
root element. An element is called <dfn>in-flow</dfn> if it is not out-of-flow. The
<dfn>flow of an element</dfn>
<var>A</var> is the set consisting of <var>A</var> and all in-flow
elements whose nearest out-of-flow ancestor is <var>A</var>.

<div class="note">
<em><strong>Note.</strong>
CSS&nbsp;2's positioning schemes help authors make their documents
more accessible by allowing them to avoid mark-up tricks
(e.g., invisible images) used for layout effects.
</em>
</div>

<h4 id="choose-position">Choosing a positioning scheme: 'position' property</h4>

<p>The 'position' and 'float' properties determine which
of the CSS&nbsp;2 positioning algorithms is used to calculate
the position of a box.
</p>

<xmp class="propdef">
Name: position
Value: static | relative | absolute | fixed | inherit
Initial: static
Applies to: *
Inherited: no
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p>The values of this property have the following meanings:</p>

<dl dfn-for="position" dfn-type="value">
<dt><dfn id="valdef-position-static">static</dfn></dt>

<dd>The box is a normal box, laid out according to the <a href="#normal-flow">normal flow</a>. The
'top',
'right',
'bottom',
and 'left'
properties do not apply.
</dd>
<dt><dfn id="valdef-position-relative">relative</dfn></dt>

<dd>The box's position is calculated according to the <a href="#normal-flow">normal flow</a> (this is called the position in
normal flow). Then the box is offset <a href="#relative-positioning">relative</a> to its normal position. When
a box B is relatively positioned, the position of the following box is
calculated as though B were not offset.  The effect of ''position:relative'' on table-row-group, table-header-group, table-footer-group, table-row, table-column-group, table-column, table-cell, and table-caption elements is undefined.
</dd>
<dt><dfn id="valdef-position-absolute">absolute</dfn></dt>
<dd> The box's position (and possibly size) is specified
with the 'top',
'right',
'bottom', and
'left'
properties.
These properties specify offsets with respect to the box's
<a href="#containing-block">containing block</a>. Absolutely
positioned boxes are taken out of the normal flow. This means
they have no impact on the layout of later siblings. Also,
though <a href="#absolutely-positioned">absolutely positioned</a>
boxes have margins, they
do not <a href="#collapsing-margins">collapse</a>
with any other margins.
</dd>
<dt><dfn id="valdef-position-fixed">fixed</dfn></dt>
<dd> The box's position is calculated according to the ''absolute''
model, but in addition, the box is <a href="#fixed-positioning">fixed</a> with respect to some reference.
As with the ''absolute'' model, the box's margins do not collapse with any other margins.
In the case of handheld, projection, screen, tty, and tv media types,
the box is fixed with respect to the <a href="#viewport">viewport</a>
and does not move when
scrolled. In the case of the print media type, the box is rendered on every page, and is fixed with respect to the page box, even if the page is seen through a <a href="#viewport">viewport</a>
(in the case of a print-preview, for example). For other media
types, the presentation is undefined.
Authors may wish to specify ''position/fixed'' in a
media-dependent way.  For instance, an author may want a box to remain
at the top of the <a href="#viewport">viewport</a> on the screen, but
not at the top of each printed page. The two specifications may be
separated by using an <a href="#at-media-rule">@media
rule</a>, as in:

<div class="example">
<pre class="lang-css">
@media screen {
  h1#first { position: fixed }
}
@media print {
  h1#first { position: static }
}
</pre>
</div>
<p>UAs must not paginate the content of fixed boxes. <span class="note">Note that UAs may print invisible content in other
ways. See <a href="#outside-page-box">"Content outside the
page box"</a> in chapter&nbsp;13.</span>
</dd>
</dl>
<p>
User agents may treat position as ''static'' on the root element.
</p>

<h4 id="position-props">Box offsets: 'top', 'right', 'bottom', 'left'</h4>

<p>An element is said to be <dfn data-lt="positioned element/box|positioned" id="positioned-element">positioned</dfn>
if its 'position' property has
a value other than ''static''. Positioned elements generate
positioned boxes, laid out according to four properties:</p>

<xmp class="propdef">
Name: top
Value: <<length>> | <<percentage>> | auto | inherit
Initial: auto
Applies to: positioned elements
Inherited: no
Percentages: refer to height of containing block
Media: visual
Computed Value: if
  specified as a length, the corresponding absolute length; if
  specified as a percentage, the specified value; otherwise, ''auto''.
Animation type: by computed value type
</xmp>



<p>This property specifies how far an <a href="#absolutely-positioned">absolutely positioned</a> box's top
margin edge is offset below the top edge of the box's <a href="#containing-block">containing block</a>. For relatively
positioned boxes, the offset is with respect to the top edges of the
box itself (i.e., the box is given a position in the normal flow, then
offset from that position according to these properties).
</p>

<xmp class="propdef">
Name: right
Value: <<length>> | <<percentage>> | auto | inherit
Initial: auto
Applies to: positioned elements
Inherited: no
Percentages: refer to width of containing block
Media: visual
Computed Value: if
  specified as a length, the corresponding absolute length; if
  specified as a percentage, the specified value; otherwise,
  ''auto''.
Animation type: by computed value type
</xmp>



<p>Like 'top', but specifies how far a box's right margin edge is
offset to the left of the right edge of the box's <a href="#containing-block">containing block</a>.  For relatively
positioned boxes, the offset is with respect to the right edge of the
box itself.
</p>

<xmp class="propdef">
Name: bottom
Value: <<length>> | <<percentage>> | auto | inherit
Initial: auto
Applies to: positioned elements
Inherited: no
Percentages: refer to height of containing block
Media: visual
Computed Value: if
  specified as a length, the corresponding absolute length; if
  specified as a percentage, the specified value; otherwise, ''auto''.
Animation type: by computed value type
</xmp>



<p>Like 'top', but specifies how far a box's bottom margin edge is
offset above the bottom of the box's <a href="#containing-block">containing block</a>. For relatively
positioned boxes, the offset is with respect to the bottom edge of the
box itself.
</p>

<xmp class="propdef">
Name: left
Value: <<length>> | <<percentage>> | auto | inherit
Initial: auto
Applies to: positioned elements
Inherited: no
Percentages: refer to width of containing block
Media: visual
Computed Value: if
  specified as a length, the corresponding absolute length; if
  specified as a percentage, the specified value; otherwise,
  ''auto''.
Animation type: by computed value type
</xmp>



<p>Like 'top', but specifies how far a box's left margin edge is
offset to the right of the left edge of the box's <a href="#containing-block">containing block</a>.  For relatively
positioned boxes, the offset is with respect to the left edge of the
box itself.
</p>

<p>The values for the four properties have the following meanings:</p>

<dl dfn-for="top,right,bottom,left" dfn-type="value">
<dt><dfn><<length>></dfn></dt>
<dd>The offset is a fixed distance from the reference edge. Negative values are allowed.
</dd>
<dt><dfn><<percentage>></dfn></dt>

<dd>The offset is a percentage of the containing block's width (for 'left' or 'right') or height (for 'top' and 'bottom'). Negative values are allowed.
</dd>
<dt><dfn>auto</dfn></dt>
<dd>For non-replaced elements, the effect of this value
depends on which of related properties have the value <css>auto</css> as
well. See the sections on the
<a href="#abs-non-replaced-width">width</a>
and <a href="#abs-non-replaced-height">height</a>
of <a href="#absolutely-positioned">absolutely positioned</a>,
non-replaced elements for details.  For replaced elements, the
effect of this value depends only on the intrinsic dimensions of the
replaced content. See the sections on the <a href="#abs-replaced-width">width</a> and <a href="#abs-replaced-height">height</a> of absolutely
positioned, replaced elements for details.
</dd>
</dl>

<h3 id="normal-flow">Normal flow</h3>

<p>Boxes in the normal flow belong to a <dfn>formatting context</dfn>, which may be
block or inline, but not both simultaneously.  <a href="#block-level">Block-level</a> boxes participate in a <a href="#block-formatting">block formatting</a> context.  <a href="#inline-level">Inline-level boxes</a> participate in an <a href="#inline-formatting">inline formatting</a> context.
</p>
<h4 id="block-formatting">Block formatting contexts</h4>

<p>Floats, absolutely positioned elements, block containers (such as
inline-blocks, table-cells, and table-captions) that are not block
boxes, and block boxes with 'overflow' other than ''overflow/visible''
(except when that value has been propagated to the viewport) establish
new block formatting contexts for their contents.</p>

<p>In a block formatting context, boxes are laid out one after the
other, vertically, beginning at the top of a containing block. The
vertical distance between two sibling boxes is determined by the 'margin' properties. Vertical margins
between adjacent block-level boxes in a block formatting context <a href="#collapsing-margins">collapse</a>.
</p>

<p>
In a block formatting context, each box's left outer edge touches the
left edge of the containing block (for right-to-left formatting, right
edges touch).  This is true even in the presence of floats (although a
box's <em>line boxes</em> may shrink due to the floats), unless the box
establishes a new block formatting context (in which case the box itself
<a href="#bfc-next-to-float"><em>may</em> become narrower</a> due to
the floats).
</p>

<p>For information about page breaks in paged media, please consult
the section on <a href="#allowed-page-breaks">allowed
page breaks</a>.
</p>

<h4 id="inline-formatting">Inline formatting contexts</h4>

<p>In an inline formatting context, boxes are laid out horizontally,
one after the other, beginning at the top of a containing
block. Horizontal margins, borders, and padding are respected between
these boxes. The boxes may be aligned vertically in different ways: their
bottoms or tops may be aligned, or the baselines of text within them
may be aligned. The rectangular area that contains the boxes that form
a line is called a <dfn id="line-box">line box</dfn>.
</p>
<p>The width of a line box is determined by a <a href="#containing-block">containing block</a> and the presence of floats.
The height of a line
box is determined by the rules given in the section on <a href="#line-height">line height calculations</a>.
</p>
<p>A line box is always tall enough for all of the boxes it contains.
However, it may be taller than the tallest box it contains
(if, for example, boxes are aligned so that baselines line up).
When the height of a box B is less than the height of the line box containing it,
the vertical alignment of B within the line box is determined by
the 'vertical-align' property.
When several inline-level boxes cannot fit horizontally within a single
line box, they are distributed among two or more vertically-stacked
line boxes. Thus, a paragraph is a vertical stack of line boxes. Line
boxes are stacked with no vertical separation (except as specified
elsewhere) and they never overlap.
</p>
<p>In general, the left edge of a line box touches the left edge
of its containing block and the right edge touches the right edge of
its containing block. However, floating boxes may come between the
containing block edge and the line box edge.  Thus, although line
boxes in the same inline formatting context generally have the same
width (that of the containing block), they may vary in width if
available horizontal space is reduced due to <a href="#floats">floats</a>. Line boxes in the same inline formatting
context generally vary in height (e.g., one line might contain a tall
image while the others contain only text).
</p>
<p>When the total width of the inline-level boxes on a line is less than the
width of the line box containing them, their horizontal distribution
within the line box is determined by the 'text-align' property.  If that
property has the value ''justify'', the user agent may stretch spaces
and words in inline boxes (but not inline-table and inline-block
boxes) as well.
</p>

<p>
When an inline box exceeds the width of a line box, it is split into several boxes and these boxes are distributed across several line boxes.  If an inline box cannot be split (e.g., if the inline box contains a single character, or language specific word breaking rules disallow a break within the inline box, or if the inline box is affected by a white-space value of nowrap or pre), then the inline box overflows the line box.
</p>
<p>
When an inline box is split, margins,
borders, and padding have no visual effect where the split occurs (or
at any split, when there are several).
</p>
<p>Inline boxes may also be split into several boxes <em>within the
same line box</em> due to <a href="#direction">bidirectional text
processing</a>.
</p>
<p id="phantom-line-box">Line boxes are created as needed to hold
inline-level content within an inline formatting context. Line boxes
that contain no text, no <a href="#white-space-prop">preserved white space,</a> no inline
elements with non-zero margins, padding, or borders, and no other <a href="#positioning-scheme">in-flow</a> content (such as images, inline
blocks or inline tables), and do not end with a preserved newline must
be treated as zero-height line boxes for the purposes of determining
the positions of any elements inside of them, and must be treated as
not existing for any other purpose.
</p>
<div class="lang-html example"><p>
Here is an example of inline box construction. The following paragraph
(created by the HTML block-level element P) contains anonymous text
interspersed with the elements EM and STRONG:
</p>
<pre class="lang-html">
&lt;P&gt;Several &lt;EM&gt;emphasized words&lt;/EM&gt; appear
&lt;STRONG&gt;in this&lt;/STRONG&gt; sentence, dear.&lt;/P&gt;
</pre>

<p>The P element generates a block box that contains five inline
boxes, three of which are anonymous:</p>

<ul>
<li>Anonymous: "Several"</li>
<li>EM: "emphasized words"</li>
<li>Anonymous: "appear"</li>
<li>STRONG: "in this"</li>
<li>Anonymous: "sentence, dear."</li>
</ul>

<p>To format the paragraph, the user agent flows the five boxes into
line boxes. In this example, the box generated for the P element
establishes the containing block for the line boxes. If the containing
block is sufficiently wide, all the inline boxes will fit into a
single line box:
</p>
<pre>
 Several <em>emphasized words</em> appear <strong>in this</strong> sentence, dear.
</pre>

<p>If not, the inline boxes will be split up and distributed across
several line boxes. The previous paragraph might be split as follows:
</p>
<pre>
Several <em>emphasized words</em> appear
<strong>in this</strong> sentence, dear.
</pre>

or like this:

<pre>
Several <em>emphasized</em>
<em>words</em> appear <strong>in this</strong>
sentence, dear.
</pre>

</div>

<p>In the previous example, the EM box was split into two EM boxes
(call them "split1" and "split2"). Margins, borders,
padding, or text decorations have no visible effect after split1 or
before split2.
</p>
<div class="lang-html example"><p>
Consider the following example:
</p>
<pre class="lang-html">
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
  &lt;HEAD&gt;
    &lt;TITLE&gt;Example of inline flow on several lines&lt;/TITLE&gt;
    &lt;STYLE type="text/css"&gt;
      EM {
        padding: 2px;
        margin: 1em;
        border-width: medium;
        border-style: dashed;
        line-height: 2.4em;
      }
    &lt;/STYLE&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
    &lt;P&gt;Several &lt;EM&gt;emphasized words&lt;/EM&gt; appear here.&lt;/P&gt;
  &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>

<p>Depending on the width of the P, the boxes may be distributed as
follows:</p>

<div class="figure">
<p><img src="./images/inline-layout.png" alt="Image illustrating the effect of line breaking on the display of margins, borders, and padding." id="img-inline-layout"></p>
</div>

<ul>
<li> The margin is inserted before "emphasized" and after "words". </li>

<li> The padding is inserted before, above, and below
"emphasized" and after, above, and below "words". A
dashed border is rendered on three sides in each case.</li>
</ul>
</div>

<h4 id="relative-positioning">Relative positioning</h4>

<p>Once a box has been laid out according to the <a href="#normal-flow">normal flow</a> or floated, it may be shifted relative to
this position. This is called <dfn>relative positioning</dfn>. Offsetting a box
(B1) in this way has no effect on the box (B2) that follows: B2 is
given a position as if B1 were not offset and B2 is not re-positioned
after B1's offset is applied. This implies that relative positioning
may cause boxes to overlap.
However, if relative positioning causes an ''overflow:auto'' or
''overflow:scroll'' box to have
overflow, the UA must allow the user to access this content (at its offset
position), which, through the creation of scrollbars, may affect layout.
</p>
<p>A relatively positioned box keeps its normal flow size, including
line breaks and the space originally reserved for it. The section on
<a href="#containing-block">containing blocks</a> explains when a
relatively positioned box establishes a new containing block.
</p>
<p>For relatively positioned elements, 'left' and 'right' move the
box(es) horizontally, without changing their size. 'left' moves the
boxes to the right, and 'right' moves them to the left. Since boxes
are not split or stretched as a result of 'left' or 'right', the
used values are always: left = -right.
</p>
<p>If both 'left' and 'right' are <css>auto</css> (their initial values), the
used values are ''0'' (i.e., the boxes stay in their original
position).
</p>
<p>If 'left' is ''left/auto'', its used value is minus the value of 'right'
(i.e., the boxes move to the left by the value of 'right').
</p>
<p>If 'right' is specified as ''right/auto'', its used value is minus the
value of 'left'.
</p>
<p>If neither 'left' nor 'right' is <css>auto</css>, the position is
over-constrained, and one of them has to be ignored. If the 'direction' property of the containing block is ''direction/ltr'', the value of 'left' wins and 'right'
becomes -'left'. If 'direction' of the containing block is ''direction/rtl'', 'right' wins and 'left' is ignored.
</p>
<div class="example">
<p><strong>Example.</strong> The following three rules are equivalent:
</p>
<pre class="lang-css">
div.a8 { position: relative; direction: ltr; left: -1em; right: auto }
div.a8 { position: relative; direction: ltr; left: auto; right: 1em }
div.a8 { position: relative; direction: ltr; left: -1em; right: 5em }
</pre>
</div>

<p>The 'top' and 'bottom' properties move relatively positioned
element(s) up or down without changing their size. 'top' moves the
boxes down, and 'bottom' moves them up. Since boxes
are not split or stretched as a result of 'top' or 'bottom', the
used values are always: top = -bottom.
If both are <css>auto</css>, their used values are both ''0''. If one of them is
<css>auto</css>, it becomes the negative of the other. If neither is <css>auto</css>,
'bottom' is ignored (i.e., the used value of 'bottom' will be
minus the value of 'top').
</p>

<p class="note">
Note.
Dynamic movement of relatively positioned boxes can produce
animation effects in scripting environments (see also the 'visibility' property).
Although relative positioning may be used as a form of superscripting and
subscripting, the line height is not automatically adjusted to take the
positioning into consideration. See the description of <a href="#line-height">line height calculations</a> for more
information.
</p>
<p>Examples of relative positioning are provided in the section <a href="#comparison">comparing normal flow, floats, and absolute
positioning</a>.
</p>
<h3 id="floats">Floats</h3>

<p>A float is a box that is shifted to the left or right on the
current line. The most interesting characteristic of a float (or
"floated" or "floating" box) is that content may flow along its side
(or be prohibited from doing so by the 'clear' property). Content flows down
the right side of a left-floated box and down the left side of a
right-floated box. The following is an introduction to float
positioning and content flow; the exact <a href="#float-rules">rules</a> governing float behavior are given in
the description of the 'float'
property.
</p>
<p>
A floated box is
shifted to the left or right until its outer edge touches the
containing block edge or the outer edge of another float.
If there is a line box, the outer top of the floated box is aligned with
the top of the current line box.
</p>
<p>
If there is not enough horizontal room for the
float, it is shifted downward until either it fits or there are no
more floats present.
</p>
<p>Since a float is not in the flow, non-positioned block boxes
created before and after the float box flow vertically as if the float
did not exist. However,
the current and subsequent
line boxes created next to the float are
shortened
as necessary
to make room for the margin box of the float.

<p>A line box is next to a float when there exists a vertical position
that satisfies all of these four conditions: (a) at or below the top
of the line box, (b) at or above the bottom of the line box, (c) below
the top margin edge of the float, and (d) above the bottom margin edge
of the float.

<p class="note">Note: this means that floats with zero outer height or
negative outer height do not shorten line boxes.

<p>If a shortened line box is too small to contain any content, then
the line box is shifted downward (and its width recomputed) until
either some content fits or there are no more floats present.
Any content in the current line before a floated box is reflowed
in the same line on the other side of the float.
In other words, if inline-level boxes are placed
on the line before a left float is encountered that fits in the remaining line box space,
the left float is placed on that line, aligned with the top of the line box, and then the inline-level boxes already on the line are moved accordingly to the right of the float (the right being the other side of the left float) and vice versa for rtl and right floats.
</p>

<p id="bfc-next-to-float">
The border box of a table, a block-level replaced element, or an element in the normal flow that establishes a new <a href="#block-formatting">block formatting context</a>
(such as an element with 'overflow' other than ''overflow/visible'')
must not overlap the margin box of any floats in the same block
formatting context as
the element itself. If necessary, implementations should clear the
said element by placing it below any preceding floats, but may place
it adjacent to such floats if there is sufficient space.
They may even make the border box of said element narrower than
defined by <a href="#blockwidth">section&nbsp;10.3.3.</a>
CSS&nbsp;2 does not define when a UA may put said element next to the float
or by how much said element may become narrower.
</p>
<div class="example">
<p><strong>Example.</strong>
In the following document fragment, the containing block is too narrow
to contain the content next to the float,
so the content gets moved to below the floats
where it is aligned in the line box according to the text-align
property.
</p>
<pre class="lang-css"><code>
p { width: 10em; border: solid aqua; }
span { float: left; width: 5em; height: 5em; border: solid blue; }
</code>

...

<code class="html">
&lt;p&gt;
  &lt;span&gt; &lt;/span&gt;
  Supercalifragilisticexpialidocious
&lt;/p&gt;
</code></pre>
<p>This fragment might look like this:</p>
<div class="figure"><p>
<img style="display:block" src="images/supercal.png" alt="Image illustrating the effect of an unbreakable piece of content being reflowed to just after a float which left insufficient room next to it for the content to fit." id="img-supercal">
</p>
</div>
</div>

<p>Several floats may be adjacent, and this model also applies to
adjacent floats in the same line.
</p>
<div class="example"><p>
The following rule floats all IMG boxes with
<samp>class="icon"</samp> to the left (and
sets the left margin to ''0''):</p>

<pre class="lang-css">
img.icon {
  float: left;
  margin-left: 0;
}
</pre>
</div>


<div class="lang-html example"><p>
Consider the following HTML source and style sheet:</p>

<pre class="lang-html">
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
  &lt;HEAD&gt;
    &lt;TITLE&gt;Float example&lt;/TITLE&gt;
    &lt;STYLE type="text/css"&gt;
      IMG { float: left }
      BODY, P, IMG { margin: 2em }
    &lt;/STYLE&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
    &lt;P&gt;&lt;IMG src=img.png alt="This image will illustrate floats"&gt;
       Some sample text that has no other...
  &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>

<p>The IMG box is floated to the left. The content that follows is
formatted to the right of the float, starting on the same line as the
float. The line boxes to the right of the float are shortened due to
the float's presence, but resume their "normal" width (that of the
containing block established by the P element) after the float.  This
document might be formatted as:</p>

<div class="figure">
<p><img src="./images/floateg.png" alt="Image illustrating how floating boxes interact with margins." id="img-floateg"></p>
</div>

<p>Formatting would have been exactly the same if the document had
been:
</p>
<pre class="lang-html">
&lt;BODY&gt;
  &lt;P&gt;Some sample text
  &lt;IMG src=img.png alt="This image will illustrate floats"&gt;
           that has no other...
&lt;/BODY&gt;
</pre>

<p>because the content to the left of the float is displaced by
the float and reflowed down its right side.
</div>

<p>As stated in <a href="#collapsing-margins">section 8.3.1</a>,
the margins of floating boxes never <a href="#collapsing-margins">collapse</a> with margins of
adjacent boxes. Thus, in the previous example, vertical margins do not
<a href="#collapsing-margins">collapse</a> between the P box
and the floated IMG box.
</p>
<p>
The contents of floats are stacked as if floats generated new
stacking contexts, except that any positioned elements and elements
that actually create new
stacking contexts take part in the float's parent stacking context.
A float can overlap other boxes in the normal flow (e.g., when a
normal flow box next to a float has negative margins). When this
happens, floats are rendered in front of non-positioned in-flow
blocks, but behind in-flow inlines.
</p>
<div class="example">
<p>Here is another illustration, showing what happens when a float
overlaps borders of elements in the normal flow.
</p>
<div class="figure">
<p><img src="images/float2p.png" alt="Image showing a floating image that overlaps the borders of two paragraphs: the borders are interrupted by the image." id="img-float2p">
</p>
<p class="caption">A floating image obscures borders
of block boxes it overlaps.
</p>
</div>
</div>

<p>The following example illustrates the use of the 'clear' property to prevent content
from flowing next to a float.
</p>
<div class="example">
<p>Assuming a rule such as this:
</p>
<pre class="lang-css">
p { clear: left }
</pre>

<p>formatting might look like this:
</p>
<div class="figure">
<p><img src="images/floatclear.png" alt="Image showing a floating image and the effect of 'clear: left' on the two paragraphs." id="img-floatclear">
</p>
<p class="caption">Both paragraphs have set 'clear: left', which
causes the second paragraph to be "pushed down" to a position below
the float &mdash; "clearance" is added above its top margin to
accomplish this (see the 'clear' property).
</p>
</div>
</div>


<h4 id="float-position">Positioning the float: the
'float' property</h4>

<xmp class="propdef">
Name: float
Value: left | right | none | inherit
Initial: none
Applies to: all, but see {visuren.html#dis-pos-flo}9.7{}
Inherited: no
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p>This property specifies whether a box should float to the left,
right, or not at all. It may be set for any element, but only applies to
elements that generate boxes that are not
<a href="#absolutely-positioned">absolutely positioned</a>.
The values of this property have
the following meanings:</p>

<dl>
<dt><dfn class="css" dfn-for="float" dfn-type="value" id="valdef-float-left">left</dfn></dt>

<dd>The element generates a <a href="#block-boxes">block</a> box that is
floated to the left. Content flows on the right side of the box,
starting at the top (subject to the 'clear' property).
</dd>
<dt><dfn class="css" dfn-for="float" dfn-type="value" id="valdef-float-right">right</dfn></dt>

<dd>Similar to 'left', except the box is floated to the right, and content flows on the left side of the box, starting at the top.</dd>

<dt><dfn class="css" dfn-for="float" dfn-type="value" id="valdef-float-none">none</dfn></dt>

<dd>The box is not floated.</dd>
</dl>

<p>
User agents may treat float as ''float/none'' on the root element.
</p>


<p><dfn data-lt="float rules" id="float-rules">Here are the precise rules</dfn> that
govern the behavior of floats:</p>

<ol>
<li> The left <a href="#outer-edge">outer edge</a> of a
left-floating box may not be to the left of the left edge of its <a href="#containing-block">containing block</a>. An
analogous rule holds for right-floating elements.
</li>
<li> If the current box is left-floating, and there are any left-floating
boxes generated by elements earlier in the source document,
then for each such earlier box, either the left <a href="#outer-edge">outer edge</a> of the current box must be
to the right of the right <a href="#outer-edge">outer edge</a>
of the earlier box, or its top must be lower than the bottom of the
earlier box. Analogous rules hold for right-floating boxes.
</li>
<li>The right <a href="#outer-edge">outer edge</a> of a
left-floating box may not be to the right of the left <a href="#outer-edge">outer edge</a> of any right-floating
box that is next to it. Analogous rules hold for
right-floating elements.
</li>
<li>A floating box's <a href="#outer-edge">outer top</a>
may not be higher than the top of its <a href="#containing-block">containing block</a>.
When the float occurs between two collapsing margins, the
float is positioned as if it had an otherwise empty <a href="#anonymous-block-level">anonymous block parent</a> taking part in
the flow. The position of such a parent is defined by <a href="#collapsed-through">the rules</a> in the section on margin
collapsing.
</li>
<li> The <a href="#outer-edge">outer top</a> of a floating box
may not be higher than the outer top of any <a href="#block-boxes">block</a> or <a href="#floats">floated</a> box generated by an element
earlier in the source document.
</li>
<li>The <a href="#outer-edge">outer top</a> of an element's
floating box may not be higher than the top of any <a data-lt="line-box" href="#line-box">line-box</a> containing a box
generated by an element earlier in the source document.
</li>
<li>A left-floating box that has another left-floating box to its left
may not have its right outer edge to the right of its containing
block's right edge. (Loosely: a left float may not stick out at the
right edge, unless it is already as far to the left as possible.) An
analogous rule holds for right-floating elements.
</li>
<li> A floating box must be placed as high as possible.
</li>
<li> A left-floating box must be put as far to the left as
possible, a right-floating box as far to the right as possible. A
higher position is preferred over one that is further to the
left/right.
</li>
</ol>

<p>But in CSS&nbsp;2, if, within the block formatting context, there
is an in-flow negative vertical margin such that the float's position
is above the position it would be at were all such negative margins
set to zero, the position of the float is undefined.

<p>References to other elements in these rules refer only to other elements in the same <a href="#block-formatting">block formatting context</a> as the float.
</p>

<div class="example">
<p>This HTML fragment results in the b floating to the right.

<pre class="lang-xml">
&lt;P&gt;a&lt;SPAN style="float: right"&gt;b&lt;/SPAN&gt;&lt;/P&gt;
</pre>

<p>If the P element's width is enough, the a and the b will be side by
side. It might look like this:

<div class="figure">
<p><img src="images/float-right.png" alt="An a at the left side of a box and a b at the right side" id="img-float-right">
</div>
</div>


<h4 id="flow-control">Controlling flow next to floats:
the 'clear' property</h4>

<xmp class="propdef">
Name: clear
Value: none | left | right | both | inherit
Initial: none
Applies to: block-level elements
Inherited: no
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p>This property indicates which sides of an element's box(es) may
<em>not</em> be adjacent to an earlier floating box. The 'clear'
property does not consider floats inside the element itself or in
other <a href="#block-formatting">block formatting
contexts.</a>
</p>

<p>Values have the following meanings when applied to non-floating
block-level boxes:</p>

<dl>
<dt><dfn class="css" dfn-for="clear" dfn-type="value" id="valdef-clear-left">left</dfn></dt>

<dd>Requires that the top border edge of the box be below the bottom
outer edge of any left-floating boxes that resulted from elements
earlier in the source document.
</dd>

<dt><dfn class="css" dfn-for="clear" dfn-type="value" id="valdef-clear-right">right</dfn></dt>

<dd>Requires that the top border edge of the box be below the bottom
outer edge of any right-floating boxes that resulted from elements
earlier in the source document.
</dd>

<dt><dfn class="css" dfn-for="clear" dfn-type="value" id="valdef-clear-both">both</dfn></dt>

<dd>Requires that the top border edge of the box be below the bottom
outer edge of any right-floating and left-floating boxes that resulted
from elements earlier in the source document.
</dd>

<dt><dfn class="css" dfn-for="clear" dfn-type="value" id="valdef-clear-none">none</dfn></dt>

<dd>No constraint on the box's position with respect to floats.</dd>
</dl>

<p>Values other than ''clear/none'' potentially introduce <dfn id="clearance">clearance</dfn>.
Clearance inhibits margin collapsing
and acts as spacing above the margin-top of an element. It is used to
push the element vertically past the float.

<p>Computing the clearance of an element on which 'clear' is set is
done by first determining the hypothetical position of the element's
top border edge. This position is
where the actual top border edge would have been if the element's
'clear' property had been ''clear/none''.

<p>If this hypothetical position of the element's top border edge is
not past the relevant floats, then clearance is introduced, and
margins collapse according to the rules in 8.3.1.

<p>Then the amount of clearance is set to the greater of:

<ol>
  <li>The amount necessary to place the border edge of the block even
  with the bottom outer edge of the lowest float that is to be
  cleared.

  <li>The amount necessary to place the top border edge of the block
  at its hypothetical position.
</ol>

<p>Alternatively, clearance is set exactly to the amount necessary to
place the border edge of the block even with the bottom outer edge of
the lowest float that is to be cleared.

<p class="note"><em><strong>Note:</strong> Both behaviors are allowed
pending evaluation of their compatibility with existing Web content. A
future CSS specification will require either one or the other.</em>

<p class="note">
Note: The clearance can be negative or zero.

<div class="example">
<p>Example 1. Assume (for the sake of simplicity), that we have just
three boxes, in this order: block B1 with a bottom margin of M1 (B1
has no children and no padding or border), floating block F with a
height H, and block B2 with a top margin of M2 (no padding or border,
no children). B2 has 'clear' set to ''both''. We also assume B2 is not
empty.

<p>Without considering the 'clear' property on B2, we have the situation in
the diagram below. The margins of B1 and B2 collapse. Let's say the
bottom border edge of B1 is at y = 0, then the top of F is at y = M1,
the top border edge of B2 is at y = max(M1,M2), and the bottom of F is
at y = M1 + H.

<div class="figure">
<p><img src="./images/clearance.png" alt="Float F extends into the margin above M2." id="img-clearance"></p>
</div>

<p>We also assume that B2 is not below F, i.e., we are in the
situation described in the spec where we need to add clearance. That
means:

<blockquote>
<p>max(M1,M2) &lt; M1 + H
</blockquote>

<p>We need to compute clearance C twice, C1 and C2, and
keep the greater of the two: C = max(C1,C2). The first way is to put
the top of B2 flush with the bottom of F, i.e., at y = M1 + H. That
means, because the margins no longer collapse with a clearance between
them:

<blockquote class="math">
<p> <span>bottom of F</span> <span>= top border edge of B2</span> <span>&iff;</span>
<p>      <span>M1 + H</span> <span>= M1 + C1 + M2</span>          <span>&iff;</span>
<p>          <span>C1</span> <span>= M1 + H - M1 - M2</span>
<p>            <span></span> <span>= H - M2</span>
</blockquote>

<p>The second computation is to keep the top of B2 where it is, i.e., at y
= max(M1,M2). That means:

<blockquote class="math">
<p> <span>max(M1,M2)</span> <span>= M1 + C2 + M2</span>          <span>&iff;</span>
<p>         <span>C2</span> <span>= max(M1,M2) - M1 - M2</span>
</blockquote>

<p>We assumed that max(M1,M2) &lt; M1 + H, which implies

<blockquote class="math">
<p> <span>C2 = max(M1,M2) - M1 - M2</span> <span>&lt; M1 + H - M1 - M2 = H - M2</span> <span>&DoubleRightArrow;</span>
<p>                        <span>C2</span> <span>&lt; H - M2</span>
</blockquote>

<p>And, as C1 = H - M2, it follows that

<blockquote class="math">
<p> <span>C2 &lt; C1</span>
</blockquote>

<p>and hence

<blockquote class="math">
<p> <span>C = max(C1,C2) = C1</span>
</blockquote>
</div>

<div class="example">
<p>Example 2. An example of negative clearance is this situation, in
which the
clearance is -1em. (Assume none of the elements have borders or
padding):

<pre class="lang-html">
&lt;p style="<b>margin-bottom: 4em</b>"&gt;
  First paragraph.

&lt;p style="<b>float: left; height: 2em; margin: 0</b>"&gt;
  Floating paragraph.

&lt;p style="<b>clear: left; margin-top: 3em</b>"&gt;
  Last paragraph.
</pre>

<p>Explanation: Without the 'clear', the first and last paragraphs'
margins would collapse and the last paragraph's top border edge would
be flush with the top of the floating paragraph. But the 'clear'
requires the top border edge to be <em>below</em> the float, i.e., 2em
lower. This means that clearance must be introduced.  Accordingly, the
margins no longer collapse and the amount of clearance is set so that
clearance + margin-top = 2em, i.e., clearance = 2em - margin-top = 2em
\- 3em = -1em.
</div>

<p>When the property is set on floating elements, it results in a
modification of the <a href="#float-rules">rules</a> for
positioning the float. An extra constraint (#10) is added:
</p>

<ul>
<li>The top <a href="#outer-edge">outer edge</a>
of the float must be below the bottom outer
edge of all earlier left-floating boxes (in the case of 'clear:
left'), or all earlier right-floating boxes (in the case of 'clear:
right'), or both ('clear: both').</li>
</ul>

<div class="note"><p>
<em><strong>Note.</strong>
This property <a href="https://www.w3.org/TR/REC-CSS1#clear">applied to all elements in CSS1</a>. Implementations
may therefore have supported this property on all elements. In CSS2&nbsp;(1998)
and CSS&nbsp;2 the 'clear' property only applies to block-level elements.
Therefore authors should only use this property on block-level
elements.  If an implementation does support clear on inline elements,
rather than setting a clearance as explained above,
the implementation should force a break and effectively insert one or more empty line boxes (or shifting the new line box downward as described in <a href="#floats">section 9.5</a>) to move the top of the cleared inline's line box to below the respective floating box(es).
</em>
</p>
</div>

<h3 id="absolute-positioning">Absolute positioning</h3>

<p>In the absolute positioning model, a box is explicitly offset with
respect to its containing block.  It is removed from the normal flow
entirely (it has no impact on later siblings).  An absolutely
positioned box establishes a new containing block for normal flow
children and absolutely (but not fixed) positioned descendants.  However, the contents of an
absolutely positioned element do not flow around any other boxes. They
may obscure the contents of another box (or be obscured themselves),
depending on the
<a href="#stack-level">stack levels</a> of the overlapping boxes.
</p>
<p>References in this specification to an <dfn id="absolutely-positioned">
absolutely positioned
element</dfn> (or its box) imply that the element's 'position' property has the value
''position/absolute'' or ''position/fixed''.
</p>
<h4 id="fixed-positioning">Fixed positioning</h4>

<p>Fixed positioning is a subcategory of absolute positioning. The
only difference is that for a fixed positioned box, the containing
block is established by the <a href="#viewport">viewport</a>.  For <a href="#continuous-media-group">continuous media</a>, fixed
boxes do not move when the document is scrolled. In this respect, they
are similar to <a href="#background-properties">fixed
background images</a>.  For <a href="#the-page">paged media</a>, boxes
with fixed positions are repeated on every page. This is useful for
placing, for instance, a signature at the bottom of each page.
Boxes with fixed position that are larger than the page area are
clipped. Parts of the fixed position box that are not visible in the
initial containing block will not print.
</p>
<div class="lang-html example">
<p>Authors may use fixed positioning to create frame-like presentations.
Consider the following frame layout:</p>

<div class="figure">
<p><img src="./images/frame.png" alt="Image illustrating a frame-like layout with position='fixed'." id="img-frame"></p>
</div>

<p>This might be achieved with the following HTML document and
style rules:</p>

<pre class="lang-html">
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
  &lt;HEAD&gt;
    &lt;TITLE&gt;A frame document with CSS&nbsp;2&lt;/TITLE&gt;
    &lt;STYLE type="text/css" media="screen"&gt;
      BODY { height: 8.5in } /* Required for percentage heights below */
      #header {
        position: fixed;
        width: 100%;
        height: 15%;
        top: 0;
        right: 0;
        bottom: auto;
        left: 0;
      }
      #sidebar {
        position: fixed;
        width: 10em;
        height: auto;
        top: 15%;
        right: auto;
        bottom: 100px;
        left: 0;
      }
      #main {
        position: fixed;
        width: auto;
        height: auto;
        top: 15%;
        right: 0;
        bottom: 100px;
        left: 10em;
      }
      #footer {
        position: fixed;
        width: 100%;
        height: 100px;
        top: auto;
        right: 0;
        bottom: 0;
        left: 0;
      }
    &lt;/STYLE&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
    &lt;DIV id="header"&gt; ...  &lt;/DIV&gt;
    &lt;DIV id="sidebar"&gt; ...  &lt;/DIV&gt;
    &lt;DIV id="main"&gt; ...  &lt;/DIV&gt;
    &lt;DIV id="footer"&gt; ...  &lt;/DIV&gt;
  &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>
</div>

<h3 id="dis-pos-flo">Relationships between 'display', 'position',
and 'float'</h3>

<p>The three properties that affect box generation and layout &mdash;
'display',
'position', and
'float' &mdash; interact as follows:</p>

<ol>
<li>If 'display'
has the value ''display/none'', then
'position' and
'float' do not apply.
In this case, the element generates no box.</li>

<li>Otherwise, if 'position'
has the value ''position/absolute'' or ''position/fixed'', the box is absolutely positioned,
the computed
value of 'float' is ''float/none'',
and display is set according to the table below.
The position of the box will be determined by the 'top', 'right', 'bottom' and 'left' properties and the box's
containing block.
</li>

<li>Otherwise, if 'float' has a value other than ''float/none'', the box is
floated and 'display' is set according to the table below.
</li>

<li>Otherwise, if the element is the root element,
'display' is set according to the table below, except that it is
undefined in CSS&nbsp;2 whether a specified value of ''list-item''
becomes a computed value of ''block'' or ''list-item''.</li>

<li>Otherwise, the remaining 'display' property values apply
as specified.
</li>
</ol>

<table>
<tr><th>Specified value <th style="width:30%">Computed value</tr>
<tr><td>inline-table <td>table</tr>
<tr><td>inline, table-row-group, table-column,
table-column-group, table-header-group, table-footer-group, table-row,
table-cell, table-caption, inline-block <td>block</tr>
<tr><td>others <td>same as specified</tr>
</table>

<h3 id="comparison">Comparison of normal flow, floats,
and absolute positioning</h3>
<p>To illustrate the differences between normal flow, relative
positioning, floats, and absolute positioning, we provide a series of
examples based on the following HTML:
</p>
<pre class="lang-html example"><code class="html">
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
  &lt;HEAD&gt;
    &lt;TITLE&gt;Comparison of positioning schemes&lt;/TITLE&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
    &lt;P&gt;Beginning of body contents.
      &lt;SPAN id="outer"&gt; Start of outer contents.
      &lt;SPAN id="inner"&gt; Inner contents.&lt;/SPAN&gt;
      End of outer contents.&lt;/SPAN&gt;
      End of body contents.
    &lt;/P&gt;
  &lt;/BODY&gt;
&lt;/HTML&gt;
</code></pre>

<p>In this document, we assume the following rules:</p>

<pre class="example lang-css"><code>
body { display: block; font-size:12px; line-height: 200%;
       width: 400px; height: 400px }
p    { display: block }
span { display: inline }
</code></pre>

<p>The final positions of boxes generated by the <em>outer</em> and
<em>inner</em> elements vary in each example. In each illustration,
the numbers to the left of the illustration indicate the <a href="#normal-flow">normal flow</a> position of the double-spaced (for
clarity) lines. </p>

<p class="note">
Note. The diagrams in this section are illustrative and not to
scale. They are meant to highlight the differences between the
various positioning schemes in CSS&nbsp;2, and are not intended to be
reference renderings of the examples given.
</p>

<h4 id="comp-normal-flow">Normal flow</h4>

<p>Consider the following CSS declarations for <em>outer</em> and
<em>inner</em> that do not alter the <a href="#normal-flow">normal
flow</a> of boxes:</p>

<pre class="example lang-css"><code>
#outer { color: red }
#inner { color: blue }
</code></pre>

<p>The P element contains all inline content: <a href="#anonymous">anonymous inline text</a> and two SPAN
elements. Therefore, all of the content will be laid out
in an inline formatting context, within a containing block
established by the P element, producing something like:</p>

<div class="figure">
<p><img src="./images/flow-generic.png" alt="Image illustrating the normal flow of text between parent and sibling boxes." id="img-flow-generic"></p>
</div>

<h4 id="comp-relpos">Relative positioning</h4>

<p>To see the effect of <a href="#relative-positioning">relative
positioning</a>, we specify:</p>

<pre class="example lang-css"><code>
#outer { position: relative; top: -12px; color: red }
#inner { position: relative; top: 12px; color: blue }
</code></pre>

<p>Text flows normally up to the <em>outer</em> element.  The
<em>outer</em> text is then flowed into its normal flow position and
dimensions at the end of line 1. Then, the inline boxes containing the
text (distributed over three lines) are shifted as a unit by ''-12px''
(upwards).
</p>

<p>The contents of <em>inner</em>, as a child of <em>outer</em>, would
normally flow immediately after the words "of outer contents" (on line
1.5). However, the <em>inner</em> contents are themselves offset
relative to the <em>outer</em> contents by ''12px'' (downwards), back to
their original position on line 2.
</p>

<p>Note that the content following <em>outer</em> is not affected by the
relative positioning of <em>outer</em>.</p>

<div class="figure">
<p><img src="./images/flow-relative.png" alt="Image illustrating the effects of relative positioning on a box's content." id="img-flow-relative"></p>
</div>

<p>Note also that had the offset of <em>outer</em> been ''-24px'', the
text of <em>outer</em> and the body text would have overlapped.
</p>

<h4 id="comp-float">Floating a box</h4>

<p>Now consider the effect of <a href="#floats">floating</a> the
<em>inner</em> element's text to the right by means of the following
rules:
</p>
<pre class="example lang-css"><code>
#outer { color: red }
#inner { float: right; width: 130px; color: blue }
</code></pre>

<p>Text flows normally up to the <em>inner</em> box, which is pulled
out of the flow and floated to the right margin (its 'width' has been assigned explicitly).
Line boxes to the left of the float are shortened, and the
document's remaining text flows into them.</p>

<div class="figure">
<p><img src="./images/flow-float.png" alt="Image illustrating the effects of floating a box." id="img-flow-float"></p>
</div>

<p>To show the effect of the 'clear' property, we add a <em>sibling</em>
element to the example:
</p>
<pre class="lang-html example"><code class="html">
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
  &lt;HEAD&gt;
    &lt;TITLE&gt;Comparison of positioning schemes II&lt;/TITLE&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
    &lt;P&gt;Beginning of body contents.
      &lt;SPAN id=outer&gt; Start of outer contents.
      &lt;SPAN id=inner&gt; Inner contents.&lt;/SPAN&gt;
      &lt;SPAN id=sibling&gt; Sibling contents.&lt;/SPAN&gt;
      End of outer contents.&lt;/SPAN&gt;
      End of body contents.
    &lt;/P&gt;
  &lt;/BODY&gt;
&lt;/HTML&gt;
</code></pre>

<p>The following rules:
</p>
<pre class="example lang-css"><code>
#inner { float: right; width: 130px; color: blue }
#sibling { color: red }
</code></pre>

<p>cause the <em>inner</em> box to float to the right as before and the
document's remaining text to flow into the vacated space:</p>

<div class="figure">
<p><img src="./images/flow-clear.png" alt="Image illustrating the effects of floating a box without setting the clear property to control the flow of text around the box." id="img-flow-clear"></p>
</div>

<p>However, if the 'clear'
property on the <em>sibling</em> element is set to 'right' (i.e., the
generated <em>sibling</em> box will not accept a position next to
floating boxes to its right), the <em>sibling</em> content begins to
flow below the float:
</p>
<pre class="example lang-css"><code>
#inner { float: right; width: 130px; color: blue }
#sibling { clear: right; color: red }
</code></pre>

<div class="figure">
<p><img src="./images/flow-clear2.png" alt="Image illustrating the effects of floating an element with setting the clear property to control the flow of text around the element." id="img-flow-clear2"></p>
</div>

<h4 id="comp-abspos">Absolute positioning</h4>

<p>Finally, we consider the effect of <a href="#absolute-positioning">absolute positioning</a>.
Consider the following CSS declarations for <em>outer</em> and
<em>inner</em>:</p>

<pre class="example lang-css"><code>
#outer {
    position: absolute;
    top: 200px; left: 200px;
    width: 200px;
    color: red;
}
#inner { color: blue }
</code></pre>

<p>which cause the top of the <em>outer</em> box to be positioned with
respect to its containing block. The containing block for a positioned
box is established by the nearest positioned ancestor (or, if none
exists, the <a href="#containing-block-details">initial containing
block</a>, as in our example). The top side of the <em>outer</em> box
is ''200px'' below the top of the containing block and the left side is
''200px'' from the left side. The child box of <em>outer</em> is flowed
normally with respect to its parent.</p>

<div class="figure">
<p><img src="./images/flow-absolute.png" alt="Image illustrating the effects of absolutely positioning a box." id="img-flow-absolute"></p>
</div>

<p>The following example shows an absolutely positioned box that is a
child of a relatively positioned box. Although the parent
<em>outer</em> box is not actually offset, setting its 'position' property to ''relative''
means that its box may serve as the containing block for positioned
descendants. Since the <em>outer</em> box is an inline box that is
split across several lines, the first inline box's top and left edges
(depicted by thick dashed lines in the illustration below)
serve as references for 'top' and
'left' offsets.
</p>
<pre class="example lang-css"><code>
#outer {
  position: relative;
  color: red
}
#inner {
  position: absolute;
  top: 200px; left: -100px;
  height: 130px; width: 130px;
  color: blue;
}
</code></pre>

<p>This results in something like the following:</p>

<div class="figure">
<p><img src="./images/flow-abs-rel.png" alt="Image illustrating the effects of absolutely positioning a box with respect to a containing block." id="img-flow-abs-rel"></p>
</div>

<p>If we do not position the <em>outer</em> box:</p>

<pre class="example lang-css"><code>
#outer { color: red }
#inner {
  position: absolute;
  top: 200px; left: -100px;
  height: 130px; width: 130px;
  color: blue;
}
</code></pre>

<p>the containing block for <em>inner</em> becomes the <a href="#containing-block-details">initial containing block</a> (in our
example). The following illustration shows where the <em>inner</em>
box would end up in this case.</p>


<div class="figure">
<p><img src="./images/flow-static.png" alt="Image illustrating the effects of absolutely positioning a box with respect to a containing block established by a normally positioned parent." id="img-flow-static"></p>
</div>

<div class="lang-html example"><p>
Relative and absolute positioning may be used to implement change
bars, as shown in the following example. The following fragment:
</p>
<pre class="lang-html">
&lt;P style="position: relative; margin-right: 10px; left: 10px;"&gt;
I used two red hyphens to serve as a change bar. They
will "float" to the left of the line containing THIS
&lt;SPAN style="position: absolute; top: auto; left: -1em; color: red;"&gt;--&lt;/SPAN&gt;
word.&lt;/P&gt;
</pre>

<p>might result in something like:</p>

<div class="figure">
<p><img src="./images/changebar.png" alt="Image illustrating the use of floats to create a changebar effect." id="img-changebar"></p>
</div>

<p>First, the paragraph (whose containing block sides are shown in the
illustration) is flowed normally. Then it is offset ''10px'' from the
left edge of the containing block (thus, a right margin of ''10px'' has
been reserved in anticipation of the offset).  The two hyphens acting
as change bars are taken out of the flow and positioned at the current
line (due to 'top: auto'), ''-1em'' from the left edge of its containing
block (established by the P in its final position).  The result is
that the change bars seem to "float" to the left of the current
line.</p>
</div>

<h3 id="layers">Layered presentation</h3>

<h4 id="z-index">Specifying the stack level: the 'z-index' property</h4>

<xmp class="propdef">
Name: z-index
Value: auto | <<integer>> | inherit
Initial: auto
Applies to: positioned elements
Inherited: no
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: by computed value type
</xmp>



<p>For a positioned box, the 'z-index' property specifies:

<ol>
  <li>The stack level of the box in the current stacking context.

  <li>Whether the box establishes a stacking context.
</ol>

<p>Values have the following meanings:

<dl>
  <dt><a data-lt="&lt;integer&gt;"><span class="value-inst-integer"><strong>&lt;integer&gt;</strong></span></a>

  <dd>This integer is the stack level of the generated box in the
  current stacking context. The box also establishes a new stacking
  context.

  <dt><dfn class="css" dfn-for="z-index" dfn-type="value" id="valdef-z-index-auto">auto</dfn>

  <dd>The stack level of the generated box in the current stacking
  context is 0. The box does not establish a new stacking context
  unless it is the root element.
</dl>

<p><em>In this section, the expression "in front of"
means closer to the user as the user faces the screen.</em></p>

<p>In CSS&nbsp;2, each box has a position in three dimensions. In addition
to their horizontal and vertical positions, boxes lie along a "z-axis"
and are formatted one on top of the other.  Z-axis positions are
particularly relevant when boxes overlap visually. This section
discusses how boxes may be positioned along the z-axis.
</p>
<p>
The order in which the rendering tree is painted onto the canvas is
described in terms of stacking contexts. Stacking contexts can
contain further stacking contexts. A stacking context is atomic from
the point of view of its parent stacking context; boxes in other
stacking contexts may not come between any of its boxes.
</p>
<p>Each box belongs to one <dfn>stacking context</dfn>. Each positioned box in a
given stacking context has an integer <dfn id="stack-level">stack
level</dfn>, which is its position on the z-axis relative
other stack levels within the same stacking context. Boxes with
greater stack levels are always formatted
in front of boxes with lower stack levels.  Boxes may have negative
stack levels.  Boxes with the same stack level in a stacking context
are stacked back-to-front according to document tree order.
</p>

<p>
The root element forms the root stacking context. Other stacking
contexts are generated by any positioned element (including
relatively positioned elements) having a computed value of 'z-index'
other than ''z-index/auto''. Stacking contexts are not necessarily related to
containing blocks. In future levels of CSS, other properties may
introduce stacking contexts, for example '<a href="https://www.w3.org/TR/css3-color/#transparency">opacity</a>'
[[CSS3COLOR]].
</p>

<p>Within each stacking context, the following layers are painted in
back-to-front order:

<ol>
  <li>the background and borders of the element forming the stacking
  context.

  <li>the child stacking contexts with negative stack levels (most
  negative first).

  <li>the in-flow, non-inline-level, non-positioned descendants.

  <li>the non-positioned floats.

  <li>the in-flow, inline-level, non-positioned descendants, including
  inline tables and inline blocks.

  <li>the child stacking contexts with stack level 0 and the
  positioned descendants with stack level 0.

  <li>the child stacking contexts with positive stack levels (least
  positive first).
</ol>

<p>Within each stacking context, positioned elements with stack level
0 (in layer&nbsp;6), non-positioned floats (layer&nbsp;4), inline
blocks (layer&nbsp;5), and inline tables (layer&nbsp;5), are painted
as if those elements themselves generated new stacking contexts,
except that their positioned descendants and any would-be child
stacking contexts take part in the current stacking context.

<p>This painting order is applied recursively to each stacking
context. This description of stacking context painting order
constitutes an overview of the detailed normative definition in
<a href="#elaborate-stacking-contexts">Appendix&nbsp;E.</a>

<div class="lang-html example">
<p>In the following example, the stack levels of
the boxes (named with their "id" attributes) are:
"text2"=0, "image"=1, "text3"=2, and "text1"=3. The
"text2" stack level is inherited from the root box. The
others are specified with the 'z-index' property.
</p>
<pre class="lang-html">
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
  &lt;HEAD&gt;
    &lt;TITLE&gt;Z-order positioning&lt;/TITLE&gt;
    &lt;STYLE type="text/css"&gt;
      .pile {
        position: absolute;
        left: 2in;
        top: 2in;
        width: 3in;
        height: 3in;
      }
    &lt;/STYLE&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
    &lt;P&gt;
      &lt;IMG id="image" class="pile"
           src="butterfly.png" alt="A butterfly image"
           style="z-index: 1"&gt;

    &lt;DIV id="text1" class="pile"
         style="z-index: 3"&gt;
      This text will overlay the butterfly image.
    &lt;/DIV&gt;

    &lt;DIV id="text2"&gt;
      This text will be beneath everything.
    &lt;/DIV&gt;

    &lt;DIV id="text3" class="pile"
         style="z-index: 2"&gt;
      This text will underlay text1, but overlay the butterfly image
    &lt;/DIV&gt;
  &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>
</div>


<p>This example demonstrates the notion of
<em>transparency</em>. The default behavior of the background is to allow boxes behind it to be visible.
In the example, each box transparently overlays the boxes below it. This
behavior can be overridden by using one of the existing
<a href="#background-properties">
background properties</a>.
</p>

<h3 id="direction">Text direction:
the 'direction'
and 'unicode-bidi'
properties
</h3>

<p><a href="#conformance">Conforming</a> user agents that do
not support bidirectional text may ignore the 'direction' and 'unicode-bidi' properties
described in this section. This exception includes UAs that render
right-to-left characters simply because a font on the system contains them
but do not support the concept of right-to-left text direction.

<p>The characters in certain scripts are written from right to
left. In some documents, in particular those written with the Arabic
or Hebrew script, and in some mixed-language contexts, text in a
single (visually displayed) block may appear with mixed
directionality. This phenomenon is called <dfn data-lt="bidirectionality (bidi)|bidirectionality">bidirectionality</dfn>, or
"bidi" for short.
</p>
<p>The Unicode standard ([[!UNICODE]], [[!UAX9]]) defines a complex
algorithm for determining the proper directionality of text. The
algorithm consists of an implicit part based on character properties,
as well as explicit controls for embeddings and overrides. CSS&nbsp;2 relies
on this algorithm to achieve proper bidirectional rendering. The 'direction' and 'unicode-bidi' properties allow
authors to specify how the elements and attributes of a document
language map to this algorithm.
</p>
<p>User agents that support bidirectional text must apply the Unicode
bidirectional algorithm to every sequence of inline-level boxes uninterrupted
by a forced (<a href="http://www.unicode.org/reports/tr9/#Bidirectional_Character_Types">bidi
class&nbsp;B</a>) break or block boundary. This sequence forms the
"paragraph" unit in the bidirectional algorithm. The paragraph embedding
level is set according to the value of the 'direction' property of the containing
block rather than by the heuristic given in steps P2 and P3 of the Unicode
algorithm.</p>
<p>Because the directionality of a text depends on the structure and
semantics of the document language, these properties should in most
cases be used only by designers of document type descriptions (DTDs),
or authors of special documents. If a default style sheet specifies
these properties, authors and users should not specify rules to
override them.
</p>
<p>The HTML 4 specification ([[!HTML401]], section 8.2) defines
bidirectionality behavior for HTML elements. The style sheet
rules that would achieve the bidi behavior specified in [[!HTML401]] are
given in <a href="#bidi">the sample style sheet</a>. The
HTML 4 specification also contains more information on
bidirectionality issues.
</p>

<xmp class="propdef">
Name: direction
Value: ltr | rtl | inherit
Initial: ltr
Applies to: all elements, but see prose
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p>This property specifies the base writing direction of blocks and
the direction of embeddings and overrides (see 'unicode-bidi') for the Unicode
bidirectional algorithm. In addition, it specifies such things as the
direction of <a href="#tables">table</a> column layout, the direction of
horizontal <a href="#overflow">overflow</a>, the
position of an incomplete last line in a block in case of 'text-align:
justify'.
</p>

<p>Values for this property have the following meanings:</p>

<dl>
<dt><dfn class="css" dfn-for="direction" dfn-type="value" id="valdef-direction-ltr">ltr</dfn></dt>
<dd>Left-to-right direction.</dd>
<dt><dfn class="css" dfn-for="direction" dfn-type="value" id="valdef-direction-rtl">rtl</dfn></dt>
<dd> Right-to-left direction.</dd>
</dl>

<p>For the 'direction'
property to affect reordering in inline elements, the 'unicode-bidi' property's value
must be ''embed'' or ''override''.
</p>
<div class="note"><p>
<em><strong>Note.</strong>
The 'direction' property, when
specified for table column elements, is not inherited by cells in the
column since columns are not the ancestors of the cells in the document tree.
Thus, CSS cannot easily capture the "dir" attribute inheritance rules described
in [[!HTML401]], section 11.3.2.1.
</em></div>

<xmp class="propdef">
Name: unicode-bidi
Value: normal | embed | bidi-override | inherit
Initial: normal
Applies to: all elements, but see prose
Inherited: no
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p>Values for this property have the following meanings:</p>

<dl>
<dt><dfn class="css" dfn-for="unicode-bidi" dfn-type="value" id="valdef-unicode-bidi-normal">normal</dfn></dt>
<dd>The element does not open an additional level of embedding with
respect to the bidirectional algorithm. For inline elements,
implicit reordering works across element boundaries.
</dd>
<dt><dfn class="css" dfn-for="unicode-bidi" dfn-type="value" id="valdef-unicode-bidi-embed">embed</dfn></dt>

<dd>If the element is inline, this value
opens an additional level of embedding with respect to the
bidirectional algorithm. The direction of this embedding level is
given by the 'direction'
property. Inside the element, reordering is done implicitly. This
corresponds to adding a LRE (U+202A; for 'direction: ltr') or RLE
(U+202B; for 'direction: rtl') at the start of the element and a PDF
(U+202C) at the end of the element.
</dd>
<dt><dfn class="css" dfn-for="unicode-bidi" dfn-type="value" id="valdef-unicode-bidi-bidi-override">bidi-override</dfn></dt>

<dd>
For inline elements this creates an override.
For block container elements
this creates an override for inline-level descendants not within
another block container
element.
This means that inside the element, reordering is strictly in sequence
according to the 'direction'
property; the implicit part of the bidirectional algorithm is
ignored. This corresponds to adding a LRO (U+202D; for 'direction:
ltr') or RLO (U+202E; for 'direction: rtl') at the start of the
element or at the start of each anonymous child block box, if any, and
a PDF (U+202C) at the end of the element.
</dd>
</dl>

<p>The final order of characters in each block container is the
same as if the bidi control codes had been added as described above,
markup had been stripped, and the resulting character sequence had
been passed to an implementation of the Unicode bidirectional
algorithm for plain text that produced the same line-breaks as the
styled text.
In this process, replaced elements with 'display: inline'
are treated as
neutral characters, unless their 'unicode-bidi' property has a
value other than ''unicode-bidi/normal'', in which case they are treated as strong
characters in the 'direction'
specified for the element.
All other atomic inline-level boxes are treated as neutral characters
always.




</p>
<p>Please note that in order to be able to flow inline boxes in a
uniform direction (either entirely left-to-right or entirely
right-to-left), more inline boxes (including anonymous inline boxes)
may have to be created, and some inline boxes may have to be split up
and reordered before flowing.
</p>
<p>Because the Unicode algorithm has a limit of
<em title="According to unicode 3.0, chapter 3, section 12, definition BD2. Specifically, page 58 here: http://www.unicode.org/unicode/uni2book/ch03.pdf">61 levels</em> of
embedding, care should be taken not to use 'unicode-bidi' with a value other
than ''unicode-bidi/normal'' unless appropriate. In particular, a value of ''unicode-bidi/inherit''
should be used with extreme caution. However, for elements that are,
in general, intended to be displayed as blocks, a setting of
'unicode-bidi: embed' is preferred to keep the element together in
case display is changed to inline (see example below).
</p>
<p>The following example shows an XML document with bidirectional
text. It illustrates an important design principle: DTD designers should take bidi
into account both in the language proper (elements and attributes) and
in any accompanying style sheets. The style sheets should be designed
so that bidi rules are separate from other style rules. The bidi rules
should not be overridden by other style sheets so that the document
language's or DTD's bidi behavior is preserved.
</p>
<div class="example"><p>
In this example,
lowercase letters stand for inherently left-to-right characters and
uppercase letters represent inherently right-to-left characters:
</p>
<pre class="lang-xml example"><code class="xml">
&lt;HEBREW&gt;
  &lt;PAR&gt;HEBREW1 HEBREW2 english3 HEBREW4 HEBREW5&lt;/PAR&gt;
  &lt;PAR&gt;HEBREW6 &lt;EMPH&gt;HEBREW7&lt;/EMPH&gt; HEBREW8&lt;/PAR&gt;
&lt;/HEBREW&gt;
&lt;ENGLISH&gt;
  &lt;PAR&gt;english9 english10 english11 HEBREW12 HEBREW13&lt;/PAR&gt;
  &lt;PAR&gt;english14 english15 english16&lt;/PAR&gt;
  &lt;PAR&gt;english17 &lt;HE-QUO&gt;HEBREW18 english19 HEBREW20&lt;/HE-QUO&gt;&lt;/PAR&gt;
&lt;/ENGLISH&gt;
</code></pre>

<p>Since this is XML, the style sheet is responsible for setting the
writing direction. This is the style sheet:</p>

<pre class="example lang-css">
/* Rules for bidi */
HEBREW, HE-QUO  {direction: rtl; unicode-bidi: embed}
ENGLISH         {direction: ltr; unicode-bidi: embed}

/* Rules for presentation */
HEBREW, ENGLISH, PAR  {display: block}
EMPH                  {font-weight: bold}
</pre>

<p>The HEBREW element is a block with a right-to-left base direction,
the ENGLISH element is a block with a left-to-right base
direction. The PARs are blocks that inherit the base direction from
their parents. Thus, the first two PARs are read starting at the top
right, the final three are read starting at the top left.  Please note
that HEBREW and ENGLISH are chosen as element names for explicitness
only; in general, element names should convey structure without
reference to language.
</p>
<p>The EMPH element is inline-level, and since its value for 'unicode-bidi' is ''unicode-bidi/normal'' (the
initial value), it has no effect on the ordering of the text. The
HE-QUO element, on the other hand, creates an embedding.
</p>
<p>The formatting of this text might look like this if the line length
is long:
</p>
<pre class="ascii-art">
               5WERBEH 4WERBEH english3 2WERBEH 1WERBEH

                                8WERBEH <b>7WERBEH</b> 6WERBEH

english9 english10 english11 13WERBEH 12WERBEH

english14 english15 english16

english17 20WERBEH english19 18WERBEH
</pre>

<p>Note that the HE-QUO embedding causes HEBREW18 to be to the right
of english19.
</p>
<p>If lines have to be broken, it might be more like this:
</p>
<pre class="ascii-art">
       2WERBEH 1WERBEH
  -EH 4WERBEH english3
                 5WERB

   -EH <b>7WERBEH</b> 6WERBEH
                 8WERB

english9 english10 en-
glish11 12WERBEH
13WERBEH

english14 english15
english16

english17 18WERBEH
20WERBEH english19
</pre>

<p>Because HEBREW18 must be read before english19, it is on the line
above english19. Just breaking the long line from the earlier
formatting would not have worked. Note also that the first syllable
from english19 might have fit on the previous line, but hyphenation of
left-to-right words in a right-to-left context, and vice versa, is
usually suppressed to avoid having to display a hyphen in the middle
of a line.
</p>
</div><!-- example -->





<h2 id="visudet"><span id="q10.0">Visual formatting model details</span></h2>

<h3 id="containing-block-details">Definition of "containing
block"</h3>

<p>The position and size of an element's box(es) are sometimes
calculated relative to a certain rectangle, called the <dfn>containing
block</dfn> of the element. The containing block of an element
is defined as follows:</p>

<ol>
<li>The containing block in which the <a href="#root">root
element</a> lives is a rectangle called the <dfn>initial containing block</dfn>. For continuous
media, it has the dimensions of the <a href="#viewport">viewport</a> and is anchored at the
canvas origin; it is the <a href="#page-area">page area</a>
for paged media. The 'direction' property of the initial
containing block is the same as for the root element.
</li>
<li>For other elements, if the element's position is ''relative'' or ''static'',
the containing block is formed by the content edge of the nearest
<a href="#block-boxes">block container</a> ancestor box.
</li>
<li>If the element has 'position: fixed', the containing block is
established by the <a href="#viewport">viewport</a>
in the case of continuous media or the page area in the case of paged media.
</li>
<li>If the element has 'position: absolute', the containing block is
established by the nearest ancestor with a 'position' of ''position/absolute'', ''position/relative''
or ''position/fixed'', in the following way:
<ol>
<li>In the case that the ancestor is an inline element, the containing
block is the bounding box around the padding boxes of the first and
the last inline boxes
generated for that element. In CSS&nbsp;2, if the inline
element is split
across multiple lines, the containing block is undefined.
</li>
<li>Otherwise, the containing block
is formed by the <a href="#padding-edge">padding edge</a> of
<!-- we probably mean: the principal box of -->
the ancestor.
</li>
</ol>

<p>If there is no such ancestor, the containing block is the initial
containing block.
</p>
</li>
</ol>

<p>In paged media, an absolutely positioned element is positioned
relative to its containing block ignoring any page breaks (as if the
document were continuous). The element may subsequently be broken over
several pages.
</p>

<p>For absolutely positioned content that resolves to a position on a
page other than the page being laid out (the current page), or
resolves to a position on the current page which has already been
rendered for printing, printers may place the content
<ul>
<li>on another location on the current page,
<li>on a subsequent page, or
<li>may omit it.
</ul>

<p class="note">Note that a
block-level element that is split over several pages may have a different
width on each page and that there may be device-specific limits.
</p>

<div class="example">
<p>With no positioning, the containing blocks (C.B.) in the
following document:</p>

<pre class="lang-html example">
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
   &lt;HEAD&gt;
      &lt;TITLE&gt;Illustration of containing blocks&lt;/TITLE&gt;
   &lt;/HEAD&gt;
   &lt;BODY id="body"&gt;
      &lt;DIV id="div1"&gt;
      &lt;P id="p1"&gt;This is text in the first paragraph...&lt;/P&gt;
      &lt;P id="p2"&gt;This is text &lt;EM id="em1"&gt; in the
      &lt;STRONG id="strong1"&gt;second&lt;/STRONG&gt; paragraph.&lt;/EM&gt;&lt;/P&gt;
      &lt;/DIV&gt;
   &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>

<p>are established as follows:</p>

<table>
<tr><th>For box generated by </th>
<td><strong>C.B. is established by</strong></tr>
<tr><td>html<td>initial C.B. (UA-dependent)</tr>
<tr><td>body<td>html</tr>
<tr><td>div1<td>body</tr>
<tr><td>p1<td>div1</tr>
<tr><td>p2<td>div1</tr>
<tr><td>em1<td>p2</tr>
<tr><td>strong1<td>p2</tr>
</table>

<p>If we position "div1":</p>

<pre class="example lang-css">
   #div1 { position: absolute; left: 50px; top: 50px }
</pre>

<p>its containing block is no longer "body"; it becomes
the initial containing block (since there are no
other positioned ancestor boxes).
</p>
<p>If we position "em1" as well:</p>

<pre class="example lang-css">
   #div1 { position: absolute; left: 50px; top: 50px }
   #em1  { position: absolute; left: 100px; top: 100px }
</pre>

<p>the table of containing blocks becomes:</p>

<table>
<tr><th>For box generated by</th>
<td><strong>C.B. is established by</strong></tr>
<tr><td>html<td>initial C.B. (UA-dependent)</tr>
<tr><td>body<td>html</tr>
<tr><td>div1<td>initial C.B.</tr>
<tr><td>p1<td>div1</tr>
<tr><td>p2<td>div1</tr>
<tr><td>em1<td>div1</tr>
<tr><td>strong1<td>em1</tr>
</table>

<p>By positioning "em1", its containing block becomes
the nearest positioned ancestor box (i.e., that generated
by "div1").
</p>
</div>


<h3 id="the-width-property">Content width: the 'width' property</h3>

<xmp class="propdef">
Name: width
Value: <<length>> | <<percentage>> | auto | inherit
Initial: auto
Applies to: all elements but non-replaced inline elements, table rows, and row groups
Inherited: no
Percentages: refer to width of containing block
Media: visual
Computed Value: the percentage or ''auto'' as specified or the absolute length
Animation type: by computed value type
</xmp>



<p> This property specifies the <a href="#content-width">content width</a> of boxes.
</p>
<p>This property does not apply to non-replaced <a href="#inline-boxes">inline</a> elements. The
content width
of a non-replaced inline element's boxes is that of the rendered
content within them (<em>before</em> any relative offset of
children). Recall that inline boxes flow into <a href="#line-box">line boxes</a>. The width of line boxes
is given by the their <a href="#containing-block">containing block</a>, but may be
shorted by the presence of <a href="#floats">floats</a>.
</p>
<p>Values have the following meanings:</p>

<dl>
<dt><<length>>
</dt>
<dd>Specifies the width of the content area using a length unit.
</dd>
<dt><<percentage>>
</dt>
<dd>Specifies a percentage width. The percentage is calculated
with respect to the width of the generated box's
<a href="#containing-block">containing block</a>.
If the containing block's width depends on this element's width, then
the resulting layout is undefined in CSS&nbsp;2.
<span class="note">
Note: For absolutely positioned elements whose containing block is
based on a block container element, the percentage is calculated with
respect to the width of the <em>padding box</em> of that element.
This is a change from CSS1, where the percentage width was always
calculated with respect to the <em>content box</em> of the parent
element.
</span>
</dd>
<dt><dfn class="css" dfn-for="width" dfn-type="value" id="valdef-width-auto">auto</dfn>
</dt>
<dd>The width depends on the values of other properties.
See the sections below.
</dd>
</dl>

<p>Negative values for 'width' are
illegal.
</p>
<div class="example"><p>
For example, the following rule fixes the content width of paragraphs
at 100 pixels:</p>

<pre class="lang-css">
p { width: 100px }
</pre>
</div>

<h3 id="Computing_widths_and_margins">Calculating widths and
margins</h3>

<p>The values of an element's 'width', 'margin-left', 'margin-right', 'left' and 'right' properties as used for layout
depend on the type of box generated and on each other. (The value used
for layout is sometimes referred to as the <a href="#usedValue">used value</a>.) In
principle, the values used are the same as the computed values, with
<css>auto</css> replaced by some suitable value, and percentages calculated
based on the containing block, but there are exceptions. The following
situations need to be distinguished:</p>

    <ol>
      <li>inline, non-replaced elements</li>
      <li>inline, replaced elements</li>
      <li>block-level, non-replaced elements in normal flow</li>
      <li>block-level, replaced elements in normal flow</li>
      <li>floating, non-replaced elements</li>
      <li>floating, replaced elements</li>
      <li>absolutely positioned, non-replaced elements</li>
      <li>absolutely positioned, replaced elements</li>
      <li>''inline-block'', non-replaced elements in normal flow</li>
      <li>''inline-block'', replaced elements in normal flow</li>
    </ol>

<p>For Points 1-6 and 9-10, the values of 'left' and 'right' in the
case of relatively positioned elements are determined by the rules in <a href="#relative-positioning">section 9.4.3.</a>
</p>

<p class="note"><em><strong>Note.</strong> The used value of 'width'
calculated below is a tentative value, and may have to be calculated
multiple times, depending on 'min-width' and 'max-width', see the section <a href="#min-max-widths">Minimum and maximum widths</a> below.</em>

<h4 id="inline-width">Inline, non-replaced elements</h4>

<p>The 'width' property does not
apply. A computed value of <css>auto</css> for 'margin-left' or 'margin-right' becomes a used
value of ''0''.
</p>

<h4 id="inline-replaced-width">Inline, replaced elements</h4>

<p>A computed value of <css>auto</css> for 'margin-left' or 'margin-right' becomes a used
value of ''0''.

<p>If 'height' and 'width' both have computed values of
<css>auto</css> and the element also has an intrinsic width, then that
intrinsic width is the used value of 'width'.

<p>If 'height' and 'width' both have computed values of
<css>auto</css> and the element has no intrinsic width, but does have an
intrinsic height and intrinsic ratio; or if 'width' has a computed value of ''width/auto'',
'height' has some other computed
value, and the element does have an intrinsic ratio; then the used
value of 'width' is:

<blockquote><p>(used height) * (intrinsic ratio)</blockquote>

<p>If 'height' and 'width' both
have computed values of <css>auto</css> and the element has an intrinsic ratio
but no intrinsic height or width, then the used value of 'width' is
undefined in CSS&nbsp;2.
However, it is suggested that, if the containing block's width
does not itself depend on the replaced element's width, then the used
value of 'width' is calculated from the constraint equation used for
block-level, non-replaced elements in normal flow.

<p>Otherwise, if 'width' has a
computed value of ''width/auto'', and the element has an intrinsic width, then
that intrinsic width is the used value of 'width'.

<p>Otherwise, if 'width' has a
computed value of ''width/auto'', but none of the conditions above are met,
then the used value of 'width'
becomes 300px. If 300px is too wide to fit the device, UAs should use
the width of the largest rectangle that has a 2:1 ratio and fits the
device instead.


<h4 id="blockwidth">Block-level, non-replaced elements in normal
flow</h4>

<p>The following <span id="width-constraints">constraints</span> must hold
among the used values of the other properties:</p>
<blockquote>
<p>'margin-left' + 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' +
'margin-right' = width of <a href="#containing-block-details">containing block</a>
</p>
</blockquote>
 <p>If 'width' is not ''width/auto'' and 'border-left-width' + 'padding-left' +
'width' + 'padding-right' + 'border-right-width' (plus any of
'margin-left' or 'margin-right' that are not <css>auto</css>) is larger than
the width of the containing block, then any <css>auto</css> values for
'margin-left' or 'margin-right' are, for the following rules, treated
as zero.
</p>
<p>If
all of the above have a computed value other than <css>auto</css>, the values
are said to be "over-constrained" and one of the used values will
have to be different from its computed value. If the 'direction'
property of the containing block has the value ''direction/ltr'', the specified
value of 'margin-right' is ignored and the
value is calculated so as to make the equality true. If the value of
'direction' is ''direction/rtl'', this
happens to 'margin-left' instead.
</p>
<p>If there is exactly one value specified as <css>auto</css>, its used
value follows from the equality.
</p>
<p>If 'width' is set to ''width/auto'',
any other <css>auto</css> values become ''0'' and 'width' follows from the resulting
equality.
</p>
<p>If both 'margin-left' and
'margin-right' are <css>auto</css>,
their used values are equal. This horizontally centers the element
with respect to the edges of the containing block.
</p>

<h4 id="block-replaced-width">Block-level, replaced elements in normal flow</h4>

<p>The used value of
'width' is determined
as for <a href="#inline-replaced-width">inline replaced
elements</a>.
Then the rules <a href="#blockwidth">for non-replaced
block-level elements</a> are applied to determine the margins.
</p>
<h4 id="float-width">Floating, non-replaced elements</h4>

<p>If 'margin-left', or 'margin-right' are computed as
<css>auto</css>, their used value is ''0''.
</p>
<p>If 'width' is computed as
''width/auto'', the used value is the "shrink-to-fit" width.
</p>
<p id="shrink-to-fit-float"> Calculation of the shrink-to-fit
width is similar to calculating the width of a table cell using the
automatic table layout algorithm. Roughly: calculate the preferred
width by formatting the content without breaking lines other than
where explicit line breaks occur, and also calculate the preferred
<em>minimum</em> width, e.g., by trying all possible line breaks.
CSS&nbsp;2 does not define the exact algorithm. Thirdly, find the
<em>available width</em>: in this case, this is the width of the
containing block minus the used values of 'margin-left',
'border-left-width', 'padding-left', 'padding-right',
'border-right-width', 'margin-right', and the widths of any relevant
scroll bars.
</p>
<p>Then the shrink-to-fit width is: min(max(preferred minimum width,
available width), preferred width).</p>

<h4 id="float-replaced-width">Floating, replaced elements</h4>

<p>If 'margin-left' or 'margin-right' are computed as
<css>auto</css>, their used value is ''0''. The used value of 'width' is determined as for <a href="#inline-replaced-width">inline replaced elements</a>.
</p>
<h4 id="abs-non-replaced-width">Absolutely positioned, non-replaced elements</h4>

<p>For the purposes of this section and the next, the term <span id="static-position"><span class="index">"static position"</span></span>
(of an element) refers, roughly,
to the position an element would have had in the normal flow. More
precisely:
</p>
<ul>
<li>The <dfn>static-position containing block</dfn> is the containing
block of a hypothetical box that would have been the first box of the
element if its specified 'position' value had been ''static''
and its specified 'float' had been ''float/none''. (Note that due to the rules
in <a href="#dis-pos-flo">section&nbsp;9.7</a> this
hypothetical calculation might require also assuming a different
computed value for 'display'.)
</li>
<li>The static position for 'left' is the distance from the left edge
of the containing block to the left margin edge of a hypothetical box
that would have been the first box of the element if its 'position' property had been ''static''
and 'float' had been ''float/none''. The
value is negative if the hypothetical
box is to the left of the containing block.
</li>
<li>The static position for 'right' is the distance from the right
edge of the containing block to the right margin edge of the same
hypothetical box as above. The value is positive if the hypothetical
box is to the left of the containing block's edge.
</li>
</ul>

<p>But rather than actually calculating the dimensions of that
hypothetical box, user agents are free to make a guess at its probable
position.
</p>
<p>For the purposes of calculating the static position, the containing
block of fixed positioned elements is the initial containing block
instead of the viewport, and all scrollable boxes should be assumed to
be scrolled to their origin.

<p>The constraint that determines the used values for these
elements is:</p>

  <blockquote>
    <p>'left' + 'margin-left' + 'border-left-width' + 'padding-left' + 'width' +
       'padding-right' + 'border-right-width' + 'margin-right' + 'right' = width
       of containing block </p>
  </blockquote>

<p>If all three of 'left', 'width', and 'right' are <css>auto</css>: First set
any <css>auto</css> values for 'margin-left' and 'margin-right' to 0. Then, if
the 'direction' property of the element establishing the
static-position containing block is ''direction/ltr'' set 'left'
to the <a href="#static-position">static position</a> and apply rule number
three below; otherwise, set 'right' to the <a href="#static-position">static position</a> and apply rule number
one below.</p>

<p>If none of the three is <css>auto</css>: If both 'margin-left' and
'margin-right' are <css>auto</css>, solve the
equation under the extra constraint that the two margins get equal
values, unless this would make them negative, in which case when
direction of the containing block is ''direction/ltr'' (''direction/rtl''), set 'margin-left'
('margin-right') to zero
and solve for 'margin-right' ('margin-left'). If one of
'margin-left' or 'margin-right' is <css>auto</css>, solve the equation for that
value. If the values are over-constrained, ignore the value for 'left'
(in case the 'direction' property of the containing block is ''direction/rtl'') or
'right' (in case 'direction' is
''direction/ltr'') and solve for that value.</p>

<p>Otherwise, set <css>auto</css> values for 'margin-left' and 'margin-right'
to 0, and pick the one of the following six rules that applies.</p>

<ol>

<li>'left' and 'width' are <css>auto</css> and 'right' is not <css>auto</css>, then the
width is shrink-to-fit. Then solve for 'left'</li>

<li>'left' and 'right' are <css>auto</css> and 'width' is not <css>auto</css>, then if
the 'direction' property of the element establishing the
static-position containing block is ''direction/ltr'' set 'left'
to the <a href="#static-position">static position</a>, otherwise set 'right'
to the <a href="#static-position">static position</a>. Then solve
for 'left' (if 'direction is ''direction/rtl'') or 'right' (if 'direction' is
''direction/ltr'').</li>
<li>'width' and 'right' are <css>auto</css> and 'left' is not <css>auto</css>, then the
width is shrink-to-fit . Then solve for 'right'</li>

<li>'left' is <css>auto</css>, 'width' and 'right' are not <css>auto</css>, then solve for
'left'</li>

<li>'width' is <css>auto</css>, 'left' and 'right' are not <css>auto</css>, then solve
for 'width'</li>

<li>'right' is <css>auto</css>, 'left' and 'width' are not <css>auto</css>, then solve
for 'right'</li>
</ol>

<p>Calculation of the shrink-to-fit width is similar to calculating
the width of a table cell using the automatic table layout algorithm.
Roughly: calculate the preferred width by formatting the content
without breaking lines other than where explicit line breaks occur,
and also calculate the preferred <em>minimum</em> width, e.g., by
trying all possible line breaks. CSS&nbsp;2 does not define the
exact algorithm. Thirdly, calculate the <em>available width</em>: this
is found by solving for 'width' after setting 'left' (in case 1) or
'right' (in case 3) to 0.</p>

<p>Then the shrink-to-fit width is: min(max(preferred minimum width, available
width), preferred width).</p>

<h4 id="abs-replaced-width">Absolutely positioned, replaced elements</h4>

<p>In this case, <a href="#abs-non-replaced-width">section 10.3.7</a>
applies up through and including the constraint equation, but the rest
of <a href="#abs-non-replaced-width">section 10.3.7</a> is replaced by
the following rules:

<ol>
<li>The used value of 'width' is
determined as for <a href="#inline-replaced-width">inline replaced
elements</a>.
If 'margin-left' or 'margin-right' is specified as
<css>auto</css> its used value is determined by the rules below.
</li>
<li>If both 'left' and 'right' have the value <css>auto</css>, then if
the 'direction' property of the element establishing the
static-position containing block is ''direction/ltr'', set 'left' to
the static position; else if 'direction' is ''direction/rtl'', set 'right' to the static position.
</li>
<li>If 'left' or 'right' are <css>auto</css>, replace any <css>auto</css>
on 'margin-left' or 'margin-right' with ''0''.
</li>
<li>If at this point both 'margin-left' and 'margin-right' are still <css>auto</css>,
solve the equation under the extra constraint that the two margins
must get equal values, unless this would make them negative, in which
case when the direction of the containing block is ''direction/ltr'' (''direction/rtl''), set
'margin-left' ('margin-right') to zero and solve
for 'margin-right' ('margin-left').
</li>
<li>If at this point there is an <css>auto</css> left, solve the equation
for that value.
</li>
<li>If at this point the values are over-constrained, ignore the value
for either 'left' (in case the
'direction' property of the
containing block is ''direction/rtl'') or 'right' (in case 'direction' is ''direction/ltr'') and solve for
that value.
</li>
</ol>


<h4 id="inlineblock-width">''inline-block'', non-replaced elements in normal flow</h4>

<p>If 'width' is <css>auto</css>, the
used value is the <a href="#shrink-to-fit-float">shrink-to-fit</a>
width as for floating elements.
</p>
<p>A computed value of <css>auto</css> for 'margin-left' or 'margin-right' becomes a used
value of ''0''.
</p>

<h4 id="inlineblock-replaced-width">''inline-block'', replaced elements in normal flow</h4>

<p>Exactly as <a href="#inline-replaced-width">inline replaced
elements.</a>
</p>

<h3 id="min-max-widths">Minimum and maximum widths: 'min-width' and 'max-width'</h3>

<xmp class="propdef">
Name: min-width
Value: <<length>> | <<percentage>> | inherit
Initial: 0
Applies to: all elements but non-replaced inline elements, table rows, and row groups
Inherited: no
Percentages: refer to width of containing block
Media: visual
Computed Value: the percentage as specified or the absolute length
Animation type: by computed value type
</xmp>


<xmp class="propdef">
Name: max-width
Value: <<length>> | <<percentage>> | none | inherit
Initial: none
Applies to: all elements but non-replaced inline elements, table rows, and row groups
Inherited: no
Percentages: refer to width of containing block
Media: visual
Computed Value: the percentage as specified or the absolute length or ''max-width/none''
Animation type: by computed value type
</xmp>



<p>These two properties allow authors to constrain content widths to a
certain range. Values have the following meanings:</p>

<dl>
<dt><<length>>
</dt>
<dd>Specifies a fixed minimum or maximum used width.
</dd>
<dt><<percentage>>
</dt>
<dd>Specifies a percentage for determining the used value. The
percentage is calculated with respect to the width of the generated
box's <a href="#containing-block">containing block</a>.
If the containing block's width is negative, the used value is
zero.
If the containing block's width depends on this element's width,
then the resulting layout is undefined in CSS&nbsp;2.
</dd>
<dt><dfn dfn-for="max-width" dfn-type="value">none</dfn>
</dt>
<dd>(Only on 'max-width') No
limit on the width of the box.
</dd>
</dl>

<p>Negative values for 'min-width' and 'max-width' are illegal.
</p>

<p>In CSS&nbsp;2, the effect of 'min-width' and 'max-width' on
tables, inline tables,
table cells, table columns, and column groups is undefined.

<p>The following algorithm describes how the two properties influence
the <a href="#computed-value">used value</a>
of the 'width' property:</p>
<ol>

<li>The tentative used width is calculated (without 'min-width' and 'max-width') following the rules
under <a href="#Computing_widths_and_margins">"Calculating widths and
margins"</a> above.
</li>
<li>If the tentative used width is greater than 'max-width', the rules <a href="#Computing_widths_and_margins">above</a> are applied again, but
this time using the computed value of 'max-width' as the computed value
for 'width'.
</li>
<li>If the resulting width is smaller than 'min-width', the rules <a href="#Computing_widths_and_margins">above</a> are applied again, but
this time using the value of 'min-width' as the computed value
for 'width'.
</li>
</ol>

<p class="note">These steps do not affect the real computed values of
the above properties.</p>

<p>However, for replaced elements with an intrinsic ratio and both
'width' and 'height' specified as <css>auto</css>, the
algorithm is as follows:
</p>

<p>Select from the table the resolved height and width values for the
appropriate constraint violation. Take the <var>max-width</var> and
<var>max-height</var> as max(min, max) so that <var>min</var> &leq;
<var>max</var> holds true.
In this table <var>w</var> and <var>h</var> stand for the results of
the width and height computations ignoring the 'min-width', 'min-height', 'max-width' and 'max-height' properties. Normally
these are the intrinsic width and height, but they may not be in the
case of replaced elements with intrinsic ratios.

<p class="note">Note: In cases where an explicit width or height is
set and the other dimension is auto, applying a minimum or maximum
constraint on the auto side can cause an over-constrained situation.
The spec is clear in the behavior but it might not be what the author
expects. The CSS3 object-fit property can be used to obtain different
results in this situation.

<table>
<thead>
  <tr><th>Constraint Violation<th>Resolved Width<th>Resolved Height</tr>
</thead>
<tbody>

  <tr><td>none</td>
      <td><var>w</var></td>
      <td><var>h</var></tr>
  <tr><td><var>w&nbsp;&gt;&nbsp;max-width</var></td>
      <td><var>max-width</var></td>

      <td><var>max(max-width&nbsp;*&nbsp;h/w, min-height)</var></tr>
  <tr><td><var>w&nbsp;&lt;&nbsp;min-width</var></td>
      <td><var>min-width</var></td>
      <td><var>min(min-width&nbsp;*&nbsp;h/w, max-height)</var></tr>

  <tr><td><var>h&nbsp;&gt;&nbsp;max-height</var></td>
      <td><var>max(max-height&nbsp;*&nbsp;w/h, min-width)</var></td>
      <td><var>max-height</var></tr>
  <tr><td><var>h&nbsp;&lt;&nbsp;min-height</var></td>

      <td><var>min(min-height&nbsp;*&nbsp;w/h, max-width)</var></td>
      <td><var>min-height</var></tr>
  <tr><td>(<var>w&nbsp;&gt;&nbsp;max-width</var>) and (<var>h&nbsp;&gt;&nbsp;max-height</var>), where (<var>max-width/w&nbsp;&leq;&nbsp;max-height/h</var>)</td>

      <td><var>max-width</var></td>
      <td><var>max(min-height, max-width&nbsp;*&nbsp;h/w)</var></tr>
  <tr><td>(<var>w&nbsp;&gt;&nbsp;max-width</var>) and (<var>h&nbsp;&gt;&nbsp;max-height</var>), where (<var>max-width/w&nbsp;&gt;&nbsp;max-height/h</var>)</td>

      <td><var>max(min-width, max-height&nbsp;*&nbsp;w/h)</var></td>
      <td><var>max-height</var></tr>
  <tr><td>(<var>w&nbsp;&lt;&nbsp;min-width</var>) and (<var>h&nbsp;&lt;&nbsp;min-height</var>), where (<var>min-width/w&nbsp;&leq;&nbsp;min-height/h</var>)</td>

      <td><var>min(max-width, min-height&nbsp;*&nbsp;w/h)</var></td>
      <td><var>min-height</var></tr>
  <tr><td>(<var>w&nbsp;&lt;&nbsp;min-width</var>) and (<var>h&nbsp;&lt;&nbsp;min-height</var>), where (<var>min-width/w&nbsp;&gt;&nbsp;min-height/h</var>)</td>

      <td><var>min-width</var></td>
      <td><var>min(max-height, min-width&nbsp;*&nbsp;h/w)</var></tr>
  <tr><td>(<var>w&nbsp;&lt;&nbsp;min-width</var>) and (<var>h&nbsp;&gt;&nbsp;max-height</var>)</td>

      <td><var>min-width</var></td>
      <td><var>max-height</var></tr>
  <tr><td>(<var>w&nbsp;&gt;&nbsp;max-width</var>) and (<var>h&nbsp;&lt;&nbsp;min-height</var>)</td>

      <td><var>max-width</var></td>
      <td><var>min-height</var></tr>
</tbody>
</table>

<p>Then apply the rules under <a href="#Computing_widths_and_margins">"Calculating widths and
margins"</a> above, as if 'width'
were computed as this value.


<!--
<ol>
<li>Select from the following list of width-height pairs (a, b) the
first one that satisfies the two constraints min-width &#8804; a
&#8804; max(min-width, max-width) and min-height &#8804; b &#8804;
max(min-height, max-height). The resulting pair gives the used width
and height for the element. In this list, Wi and Hi stand for the
intrinsic width and height, respectively.
<ol>
<li>(Wi, Hi)</li>
<li>(max(Wi, min-width), max(Wi, min-width)*Hi/Wi)</li>
<li>(max(Hi, min-height)*Wi/Hi, max(Hi, min-height))</li>
<li>(min(Wi, max-width), min(Wi, max-width)*Hi/Wi)</li>
<li>(min(Hi, max-height)*Wi/Hi, min(Hi, max-height))</li>
<li>(max(Wi, min-width), min(Hi, max-height))</li>
<li>(min(Wi, max-width), max(Hi, min-height))</li>
<li>(max(Wi, min-width), max(Hi, min-height))</li>
<li>(min(Wi, max-width), min(Hi, max-height))</li>
</ol>
</li>
<li>Then apply the rules under <a href="#Computing_widths_and_margins">"Calculating widths and
margins"</a> above, as if <span class="propinst-width">'width'</span>
were computed as this value.
</li>
</ol>
-->


<h3 id="the-height-property">Content height: the 'height' property</h3>

<xmp class="propdef">
Name: height
Value: <<length>> | <<percentage>> | auto | inherit
Initial: auto
Applies to: all elements but non-replaced inline elements, table columns, and column groups
Inherited: no
Percentages: see prose
Media: visual
Computed Value: the percentage or ''auto'' (see prose under <<percentage>>) or the absolute length
Animation type: by computed value type
</xmp>



<p> This property specifies the <a href="#content-height">content height</a> of boxes.

<p>This property does not apply to non-replaced <a href="#inline-boxes">inline</a> elements. See the <a href="#inline-non-replaced">section on computing heights and margins
for non-replaced inline elements</a> for the rules used instead.
</p>
<p>Values have the following meanings:</p>

<dl>
<dt><<length>>
</dt>
<dd>Specifies the height of the content area using a length value.
</dd>
<dt><<percentage>>
</dt>
<dd>Specifies a percentage height. The percentage is calculated with
respect to the height of the generated box's <a href="#containing-block">containing block</a>. If the
height of the containing block is not specified explicitly (i.e., it
depends on content height), and this element is not absolutely
positioned, the value computes to ''height/auto''. A percentage height
on the <a href="#root">root element</a> is relative to the
<a href="#containing-block-details">initial containing block</a>.
<span class="note">
Note: For absolutely positioned elements whose containing block is
based on a block-level element, the percentage is calculated with
respect to the height of the <em>padding box</em> of that element.
This is a change from CSS1, where the percentage was always
calculated with respect to the <em>content box</em> of the parent
element.
</span>
</dd>
<dt><dfn class="css" dfn-for="height" dfn-type="value" id="valdef-height-auto">auto</dfn>
</dt>
<dd>The height depends on the values of other properties.
See the prose below.
</dd>
</dl>

<p class="note">Note that the height of the containing block of an
absolutely positioned element is independent of the size of the
element itself, and thus a percentage height on such an element can
always be resolved. However, it may be that the height is not known
until elements that come later in the document have been processed.
</p>

<p>Negative values for 'height'
are illegal.
</p>
<div class="example"><p>
For example, the following rule sets the content height of paragraphs
to 100 pixels:</p>

<pre class="lang-css">
p { height: 100px }
</pre>

<p>Paragraphs of which the height of the contents exceeds 100 pixels
will <a href="#overflow">overflow</a> according to the
'overflow' property.
</p>
</div>

<h3 id="Computing_heights_and_margins">Calculating heights and
margins</h3>

<p>For calculating the values of 'top', 'margin-top', 'height',
'margin-bottom', and 'bottom' a distinction must be made between
various kinds of boxes:
</p>
    <ol>
      <li>inline, non-replaced elements</li>
      <li>inline, replaced elements</li>
      <li>block-level, non-replaced elements in normal flow</li>
      <li>block-level, replaced elements in normal flow</li>
      <li>floating, non-replaced elements</li>
      <li>floating, replaced elements</li>
      <li>absolutely positioned, non-replaced elements</li>
      <li>absolutely positioned, replaced elements</li>
      <li>''inline-block'', non-replaced elements in normal flow</li>
      <li>''inline-block'', replaced elements in normal flow</li>
    </ol>

<p>For Points 1-6 and 9-10, the used values of 'top' and
'bottom' are determined by the rules in section 9.4.3.
</p>

<p class="note">Note: these rules apply to
the root element just as to any other element.

<p class="note"><em><strong>Note.</strong> The used value of 'height'
calculated below is a tentative value, and may have to be calculated
multiple times, depending on 'min-height' and 'max-height', see the section <a href="#min-max-heights">Minimum and maximum heights</a> below.</em>

<h4 id="inline-non-replaced">Inline, non-replaced elements</h4>

<p>The 'height' property does not
apply. The height of the content area should be based on the font, but
this specification does not specify how. A UA may, e.g., use the
em-box or the maximum ascender and descender of the font. (The latter
would ensure that glyphs with parts above or below the em-box still
fall within the content area, but leads to differently sized boxes for
different fonts; the former would ensure authors can control
background styling relative to the 'line-height', but leads to glyphs
painting outside their content area.)
</p>
<p class="note">Note: level 3 of CSS will probably include a property to
select which measure of the font is used for the content height.
</p>
<p>The vertical padding, border and margin of an inline, non-replaced
box start at the top and bottom of the content area, and has nothing
to do with the 'line-height'. But only the 'line-height' is used when calculating
the height of the line box.
</p>
<p id="multi-font-inline-height"> If more than one font is
used (this could happen when glyphs are found in different fonts), the
height of the content area is not defined by this specification.
However, we suggest that the height is chosen such that the content
area is just high enough for either (1) the em-boxes, or (2) the
maximum ascenders and descenders, of <em>all</em> the fonts in the
element. Note that this may be larger than any of the font sizes
involved, depending on the baseline alignment of the fonts.
</p>

<h4 id="inline-replaced-height">Inline replaced elements,
block-level replaced elements in normal flow, ''inline-block'' replaced
elements in normal flow and floating replaced elements</h4>

<p>If 'margin-top', or 'margin-bottom' are <css>auto</css>,
their used value is 0.

<p>If 'height' and 'width' both have computed values of
<css>auto</css> and the element also has an intrinsic height, then that
intrinsic height is the used value of 'height'.

<p>Otherwise, if 'height' has a
computed value of ''height/auto'', and the element has an intrinsic ratio then
the used value of 'height' is:

<blockquote><p>(used width) / (intrinsic ratio)</blockquote>

<p>Otherwise, if 'height' has a
computed value of ''height/auto'', and the element has an intrinsic height,
then that intrinsic height is the used value of 'height'.

<p>Otherwise, if 'height' has a
computed value of ''height/auto'', but none of the conditions above are met,
then the used value of 'height'
must be set to the height of the largest rectangle that has a 2:1
ratio, has a height not greater than 150px, and has a width not
greater than the device width.

<!-- Issue 181: remove the following -->
<!-- <p>For 'inline' and 'inline-block' elements, the margin box is used
when calculating the height of the line box. -->
<!-- /Issue 181 -->

<h4 id="normal-block">Block-level non-replaced elements in normal
flow when 'overflow' computes to ''overflow/visible''</h4>

<p>This section also applies to block-level non-replaced elements in
normal flow when 'overflow' does not compute to ''overflow/visible'' but has been
propagated to the viewport.

<p>If 'margin-top', or 'margin-bottom' are <css>auto</css>,
their used value is 0. If 'height' is ''height/auto'', the height depends
on whether the element has any block-level children and whether it has
padding or borders:
</p>

<p>The element's height is the distance from its top content edge to
the first applicable of the following:

<ol>
  <li>the bottom edge of the last line box, if the box establishes a
  inline formatting context with one or more lines

  <li>the bottom edge of the bottom (possibly collapsed) margin of its
  last in-flow child, if the child's bottom margin does not collapse
  with the element's bottom margin

  <li>the bottom border edge of the last in-flow child whose top
  margin doesn't collapse with the element's bottom margin

  <li>zero, otherwise
</ol>

<p>Only children in the normal flow are taken into account (i.e.,
floating boxes and absolutely positioned boxes are ignored, and
relatively positioned boxes are considered without their offset). Note
that the child box may be an <a href="#anonymous-block-level">anonymous block box.</a>
</p>

<h4 id="abs-non-replaced-height">Absolutely positioned, non-replaced elements</h4>

<p>For the purposes of this section and the next, the term "static
position" (of an element) refers, roughly, to the position an element
would have had in the normal flow. More precisely, the static position
for 'top' is the distance from the top edge of the containing block to
the top margin edge of a hypothetical box that would have been the
first box of the element if its specified 'position' value had been ''static''
and its specified 'float' had been
''float/none'' and its specified 'clear'
had been ''clear/none''. (Note that due to the rules
in <a href="#dis-pos-flo">section&nbsp;9.7</a> this might
require also assuming a different computed value for 'display'.)
The value is negative if the hypothetical box is above the containing
block.
</p>
<p>But rather than actually calculating the dimensions of that
hypothetical box, user agents are free to make a guess at its probable
position.
</p>
<p>For the purposes of calculating the static position, the containing
block of fixed positioned elements is the initial containing block
instead of the viewport.

<p>For absolutely positioned elements, the used values of the vertical
dimensions must satisfy this constraint:</p>

  <blockquote>
    <p>'top' + 'margin-top' + 'border-top-width' + 'padding-top' +      'height' +
    'padding-bottom' + 'border-bottom-width' +      'margin-bottom' + 'bottom'
    = height of containing block </p>
  </blockquote>

<p>If all three of 'top', 'height', and 'bottom' are auto, set 'top'
to the static position and apply rule number three below.</p>

<p>If none of the three are <css>auto</css>: If both 'margin-top' and
'margin-bottom' are <css>auto</css>, solve the equation under the extra
constraint that the two margins get equal values. If one of
'margin-top' or 'margin-bottom' is <css>auto</css>, solve the equation for that
value. If the values are over-constrained, ignore the value for
'bottom' and solve for that value.</p>

<p>Otherwise, pick the one of the following six rules that
applies.</p>

<ol>
<li>'top' and 'height' are <css>auto</css> and 'bottom' is not <css>auto</css>, then the
height is <a href="#root-height">based on the content per 10.6.7</a>, set <css>auto</css>
values for 'margin-top' and 'margin-bottom' to 0, and solve for 'top'

<li>'top' and 'bottom' are <css>auto</css> and 'height' is not <css>auto</css>, then
set 'top' to the static position, set <css>auto</css> values for 'margin-top'
and 'margin-bottom' to 0, and solve for 'bottom'</li>

<li>'height' and 'bottom' are <css>auto</css> and 'top' is not <css>auto</css>, then the
height is <a href="#root-height">based on the content per 10.6.7</a>, set <css>auto</css>
values for 'margin-top' and 'margin-bottom' to 0, and solve for
'bottom'</li>

<li>'top' is <css>auto</css>, 'height' and 'bottom' are not <css>auto</css>, then set
<css>auto</css> values for 'margin-top' and 'margin-bottom' to 0, and solve for
'top'</li>

<li>'height' is <css>auto</css>, 'top' and 'bottom' are not <css>auto</css>, then <css>auto</css>
values for 'margin-top' and 'margin-bottom' are set to 0 and solve for
'height'</li>

<li>'bottom' is <css>auto</css>, 'top' and 'height' are not <css>auto</css>, then set
<css>auto</css> values for 'margin-top' and 'margin-bottom' to 0 and solve for
'bottom'</li>
</ol>

<h4 id="abs-replaced-height">Absolutely positioned, replaced elements</h4>

<p>This situation is similar to the previous one, except that the
element has an <a href="#intrinsic">intrinsic</a> height. The
sequence of substitutions is now:
</p>
<ol>

<li>The used value of 'height' is determined as for <a href="#inline-replaced-height">inline replaced elements</a>.
If 'margin-top' or 'margin-bottom' is specified as <css>auto</css> its used
value is determined by the rules below.</li>
<li>If both 'top' and 'bottom' have the value <css>auto</css>, replace
'top' with the element's <a href="#static-position">static position</a>.
</li>
<li>If 'bottom' is <css>auto</css>,
replace any <css>auto</css> on 'margin-top' or 'margin-bottom' with ''0''.
</li>
<li>If at this point both 'margin-top' and 'margin-bottom' are still
<css>auto</css>, solve the equation under the extra constraint that the two
margins must get equal values.
</li>
<li>If at this point there is only one <css>auto</css> left, solve the equation
for that value.
</li>
<li>If at this point the values are over-constrained, ignore the value
for 'bottom' and solve for that
value.
</li>
</ol>





<h4 id="block-root-margin">Complicated cases</h4>

<p>This section applies to:

<ul>
    <li>Block-level, non-replaced elements in normal flow when
    'overflow' does not compute to ''overflow/visible'' (except if the 'overflow'
    property's value has been propagated to the viewport).

    <li>''inline-block'', non-replaced elements.

    <li>Floating, non-replaced elements.
</ul>

<p>If 'margin-top', or 'margin-bottom' are <css>auto</css>,
their used value is 0. If 'height' is <css>auto</css>, the <a href="#root-height">height depends on the element's descendants per 10.6.7</a>.

<p>For ''inline-block'' elements, the margin box is used when calculating
the height of the line box.


<h4 id="root-height"><css>auto</css> heights for block formatting context
roots</h4>

<p>In certain cases (see, e.g., sections
<a href="#abs-non-replaced-height">10.6.4</a> and
<a href="#block-root-margin">10.6.6</a> above), the height of an
element that establishes a block formatting context is computed as follows:

<p>If it only has inline-level children, the height is the distance
between the top of the topmost line box and the bottom of the
bottommost line box.
</p>
<p>If it has block-level children, the height is the distance between
the top margin-edge of the topmost block-level child box and the
bottom margin-edge of the bottommost block-level child box.
</p>
<p>Absolutely positioned children are ignored, and relatively
positioned boxes are considered without their offset. Note that the
child box may be an <a href="#anonymous-block-level">anonymous block box.</a>
</p>
<p>In addition, if the element has any floating descendants
whose bottom margin edge is below the element's bottom content edge,
then the height is increased to include those edges.
Only floats that participate in this block formatting context are taken into account,
e.g., floats inside absolutely positioned descendants or other floats are not.
</p>



<h3 id="min-max-heights">Minimum and maximum heights: 'min-height' and 'max-height'</h3>

<p>It is sometimes useful to constrain the height of elements to a
certain range. Two properties offer this functionality:
</p>

<xmp class="propdef">
Name: min-height
Value: <<length>> | <<percentage>> | inherit
Initial: 0
Applies to: all elements but non-replaced inline elements, table columns, and column groups
Inherited: no
Percentages: see prose
Media: visual
Computed Value: the percentage as specified or the absolute length
Animation type: by computed value type
</xmp>


<xmp class="propdef">
Name: max-height
Value: <<length>> | <<percentage>> | none | inherit
Initial: none
Applies to: all elements but non-replaced inline elements, table columns, and column groups
Inherited: no
Percentages: see prose
Media: visual
Computed Value: the percentage as specified or the absolute length or ''max-height/none''
Animation type: by computed value type
</xmp>



<p>These two properties allow authors to constrain box heights to a
certain range. Values have the following meanings:</p>

<dl>
<dt><<length>>
</dt>
<dd>Specifies a fixed minimum or maximum computed height.
</dd>
<dt><<percentage>>
</dt>
<dd>Specifies a percentage for determining the used value.
The percentage is calculated with respect to the height of the
generated box's <a href="#containing-block">containing block</a>.
If the height of the containing block is not
specified explicitly (i.e., it depends on content height), and this
element is not absolutely positioned, the
percentage value is treated as ''0'' (for 'min-height') or ''max-height/none''
(for 'max-height').
</dd>
<dt><dfn dfn-for="max-height" dfn-type="value">none</dfn>
</dt>
<dd>(Only on 'max-height') No limit on the height of the box.
</dd>
</dl>

<p>Negative values for 'min-height' and 'max-height' are illegal.
</p>

<p>In CSS&nbsp;2, the effect of 'min-height' and 'max-height' on
tables, inline tables, table cells, table rows, and row groups is undefined.

<p>The following algorithm describes how the two properties influence
the <a href="#computed-value">used value</a>
of the 'height' property:</p>

<ol>

<li>The tentative used height is calculated (without 'min-height' and 'max-height') following the rules
under <a href="#Computing_heights_and_margins">"Calculating heights and
margins"</a> above.
</li>
<li>If this tentative height is greater than 'max-height', the rules <a href="#Computing_heights_and_margins">above</a> are applied again, but
this time using the value of 'max-height' as the computed value
for 'height'.
</li>
<li>If the resulting height is smaller than 'min-height', the rules <a href="#Computing_heights_and_margins">above</a> are applied again, but
this time using the value of 'min-height' as the computed value
for 'height'.
</li>
</ol>

<p class="note">These steps do not affect the real computed values of
the above properties. The change of used 'height' has no effect on margin
collapsing except as specifically required by rules for 'min-height' or 'max-height' in <a href="#collapsing-margins">"Collapsing margins"
(8.3.1).</a></p>

<p>However, for replaced elements with both 'width' and 'height' computed as <css>auto</css>, use the
algorithm under <a href="#min-max-widths">Minimum and maximum
widths</a> above to find the used width and height. Then apply the
rules under <a href="#Computing_heights_and_margins">"Computing
heights and margins"</a> above, using the resulting width and height as
if they were the computed values.
</p>
<h3 id="line-height">Line height calculations: the 'line-height' and 'vertical-align'
properties</h3>

<p>As described in the section on <a href="#inline-formatting">inline formatting contexts</a>,
user agents flow inline-level boxes into a vertical stack of <a href="#line-box">line boxes</a>. The height of a line box
is determined as follows:</p>

<ol>
<li>The height of each inline-level box in the line box is calculated.
<!-- Issue 181 -->
For replaced elements, inline-block elements, and inline-table
elements, this is the height of their margin box; for inline boxes,
this is their 'line-height'.
<!-- /Issue 181 -->
(See <a href="#Computing_heights_and_margins">"Calculating heights and
margins"</a> and the <a href="#inline-box-height">height of inline
boxes</a> in <a href="#leading">"Leading and half-leading"</a>.)

</li>
<li>The inline-level boxes are aligned vertically according
to their 'vertical-align'
property.

In case they are aligned 'top' or 'bottom', they must be aligned so as
to minimize the line box height. If such boxes are tall enough, there
are multiple solutions and CSS&nbsp;2 does not define the position
of the line box's baseline (i.e., the position of the <a href="#strut">strut, see below</a>).
</li>
<li>The line box height is the distance between the uppermost
box top and the lowermost box bottom. (This includes the <a href="#strut">strut,</a> as explained under 'line-height' below.)
</li>
</ol>

<p>Empty inline elements generate empty inline boxes, but these boxes
still have margins, padding, borders and a line height, and thus
influence these calculations just like elements with content.
</p>

<h4 id="leading">Leading and half-leading</h4>

<p>CSS assumes that every font has font metrics that specify a
characteristic height above the baseline and a depth below it. In this
section we use <var>A</var> to mean that height (for a given font at a
given size) and <var>D</var> the depth. We also define <var>AD</var> =
<var>A</var> + <var>D</var>, the distance from the top to the
bottom. (See the note below for <a href="#sTypoAscender">how to find
<var>A</var> and <var>D</var> for TrueType and OpenType fonts.</a>)
Note that these are metrics of the font as a whole and need not
correspond to the ascender and descender of any individual glyph.

<p>User agent must align the glyphs in a non-replaced inline box to
each other by their relevant baselines. Then, for
each glyph, determine the <var>A</var> and <var>D</var>. Note that
glyphs in a single element may come from different fonts and thus need
not all have the same <var>A</var> and <var>D</var>. If the inline box
contains no glyphs at all, it is considered to contain a <a href="#strut">strut</a> (an invisible glyph of zero width) with the
<var>A</var> and <var>D</var> of the element's first available font.

<p>Still for each glyph, determine the leading <var>L</var> to add,
where <var>L</var> = 'line-height' - <var>AD</var>. Half
the leading is added above <var>A</var> and the other half below
<var>D</var>, giving the glyph and its leading a total height above
the baseline of <var>A'</var> = <var>A</var> + <var>L</var>/2 and a
total depth of <var>D'</var> = <var>D</var> + <var>L</var>/2.

<p class="note"><strong>Note.</strong> <var>L</var> may be negative.

<p id="inline-box-height">The height of the inline box encloses all
glyphs and their half-leading on each side and is thus exactly
'line-height'. Boxes of
child elements do not influence this height.

<p>Although margins, borders, and padding of non-replaced elements do
not enter into the line box calculation, they are still rendered
around inline boxes. This means that if the height specified by 'line-height' is less than the
content height of contained boxes, backgrounds and colors of padding
and borders may "bleed" into adjoining line boxes. User agents should
render the boxes in document order. This will cause the borders on
subsequent lines to paint over the borders and text of previous lines.
</p>

<p class="note"><em><strong>Note.</strong> CSS&nbsp;2 does not define
what the content area of an inline box is (see <a href="#inline-non-replaced">10.6.1</a> above) and thus different UAs
may draw the backgrounds and borders in different places.</em>

<p id="sTypoAscender" class="note"><em><strong>Note.</strong> It is
recommended that implementations that use OpenType or TrueType fonts
use the metrics "sTypoAscender" and "sTypoDescender" from the font's
OS/2 table for A and D (after scaling to the current element's font
size). In the absence of these metrics, the "Ascent" and "Descent"
metrics from the HHEA table should be used.</em>

</p>
<xmp class="propdef">
Name: line-height
Value: normal | <<number>> | <<length>> | <<percentage>> | inherit
Initial: normal
Applies to: *
Inherited: yes
Percentages: refer to the font size of the element itself
Media: visual
Computed Value: for <<length>> and <<percentage>> the absolute value; otherwise as specified
Animation type: by computed value type
</xmp>



<p>On a <a href="#block-boxes">block container element</a>
whose content
is composed of <a href="#inline-level">inline-level</a>
elements, 'line-height' specifies the <em>minimal</em> height of line boxes
within the element. The minimum height consists of a minimum height above
the baseline and a minimum depth below it, exactly as if each
line box starts with a <span id="strut">zero-width inline box with the
element's font and line height properties.</span> We call that imaginary
box a "strut." (The name is inspired by TeX.).
</p>

<p>The height and depth of the font above and below the baseline are
assumed to be metrics that are contained in the font. (For more
details, see CSS level&nbsp;3.)

<p>On a non-replaced <a href="#inline-boxes">inline</a> element, 'line-height'
specifies the height that is used in the calculation of the line box
height.
</p>
<p>Values for this property have the following meanings:</p>

<dl>
<dt><dfn class="css" dfn-for="line-height" dfn-type="value" id="valdef-line-height-normal">normal</dfn> </dt>
<dd>Tells user agents to set the used
value to a "reasonable" value based on the font of the element. The
value has the same meaning as <<number>>. We recommend a
used value for ''line-height/normal'' between 1.0 to 1.2. The <a href="#computed-value">computed value</a> is ''line-height/normal''.
</dd>
<dt><<length>>
</dt>
<dd>The specified length is used in the calculation of the line box
height. Negative values are illegal.
</dd>
<dt><a data-lt="&lt;number&gt;"><span class="value-inst-number"><strong>&lt;number&gt;</strong></span></a>
</dt>
<dd>The used value of the property is this number multiplied by the
element's font size. Negative values are illegal. The <a href="#computed-value">computed value</a> is the same as
the specified value.
</dd>
<dt><<percentage>>
</dt>
<dd>The <a href="#computed-value">computed value</a> of the
property is this percentage multiplied by the element's
computed font size. Negative values are illegal.
</dd>
</dl>

<div class="example"><p>
The three rules in the example below have the same resultant line height:
</p>
<pre class="lang-css">
div { line-height: 1.2; font-size: 10pt }     /* number */
div { line-height: 1.2em; font-size: 10pt }   /* length */
div { line-height: 120%; font-size: 10pt }    /* percentage */
</pre>
</div>

<p>When an element contains text that is rendered
in more than one font, user agents may determine the ''line-height/normal'' 'line-height' value according to
the largest font size.
</p>
<p class="note"><em><strong>Note.</strong> When there is only one value of 'line-height' (other than ''line-height/normal'') for all inline
boxes in a block container box and they all use the same first available font (and
there are no replaced elements, inline-block
elements, etc.), the above will ensure that
baselines of successive lines are exactly 'line-height' apart. This is
important when columns of text in different fonts have to be aligned,
for example in a table.</em>
</p>
<xmp class="propdef">
Name: vertical-align
Value: baseline | sub | super | top | text-top | middle | bottom | text-bottom | <<percentage>> | <<length>> | inherit
Initial: baseline
Applies to: inline-level and ''display/table-cell'' elements
Inherited: no
Percentages: refer to the 'line-height' of the element itself
Media: visual
Computed Value: for <<percentage>> and <<length>> the absolute length, otherwise as specified
Animation type: by computed value type
</xmp>



<p>This property affects the vertical positioning inside a line box of
the boxes generated by an inline-level element.</p>

<div class="note"><p>
<em><strong>Note.</strong> Values of this property have
different meanings in the context of tables.
Please consult the section on <a href="#height-layout">
table height algorithms</a> for details.
</em>
</p>
</div>

<p>The following values only have meaning with respect to a parent
inline element, or to the <a href="#strut">strut</a> of a parent
block container element.

<p>In the following definitions, for inline non-replaced elements, the
box used for alignment is the box whose height is the 'line-height'
(containing the box's glyphs and the half-leading on each side, see <a href="#inline-box-height">above</a>). For all other elements, the box
used for alignment is the margin box.

<dl dfn-for="vertical-align" dfn-type="value">
  <dt><dfn id="valdef-vertical-align-baseline">baseline</dfn></dt>
  <dd>Align the baseline of the box with the baseline of
      the parent box. If the box does not have a baseline, align the
      bottom margin edge with the parent's baseline.</dd>
  <dt><dfn id="valdef-vertical-align-middle">middle</dfn></dt>
  <dd>Align the vertical midpoint of the box with the baseline
      of the parent box plus half the x-height of the parent.</dd>
  <dt><dfn id="valdef-vertical-align-sub">sub</dfn></dt>
  <dd>Lower the baseline of the box to the proper position for
      subscripts of the parent's box. (This value has no effect on the
      font size of the element's text.)</dd>
  <dt><dfn id="valdef-vertical-align-super">super</dfn></dt>
  <dd>Raise the baseline of the box to the proper position for
      superscripts of the parent's box. (This value has no effect on the
      font size of the element's text.)</dd>
  <dt><dfn id="valdef-vertical-align-text-top">text-top</dfn></dt>
  <dd>Align the top of the box with the top of the parent's content
      area (see <a href="#inline-non-replaced">10.6.1</a>).</dd>
  <dt><dfn id="valdef-vertical-align-text-bottom">text-bottom</dfn></dt>
  <dd>Align the bottom of the box with the bottom of the parent's
      content area (see <a href="#inline-non-replaced">10.6.1</a>).</dd>
  <dt><dfn><<percentage>>
  </dfn></dt>
  <dd>Raise (positive value) or lower (negative value) the box
      by this distance (a percentage of the 'line-height' value).
      The value ''0%'' means the same as ''baseline''.</dd>
  <dt><dfn><<length>>
  </dfn></dt>
  <dd>Raise (positive value) or lower (negative value) the box
      by this distance.
      The value ''0cm'' means the same as ''baseline''.
  </dd>
</dl>
<p>The following values align the element relative to the line box.
Since the element may have children aligned relative to it (which in
turn may have descendants aligned relative to them), these values use
the bounds of the aligned subtree. The <dfn>aligned subtree</dfn> of
an inline element contains that element and the aligned subtrees of
all children inline elements whose computed 'vertical-align' value is
not 'top' or 'bottom'. The top of the aligned subtree is the highest
of the tops of the boxes in the subtree, and the bottom is analogous.
<dl dfn-for="vertical-align" dfn-type="value">
  <dt><dfn id="valdef-vertical-align-top">top</dfn></dt>
  <dd>Align the top of the aligned subtree with the top of the line box.</dd>
  <dt><dfn id="valdef-vertical-align-bottom">bottom</dfn></dt>
  <dd>Align the bottom of the aligned subtree with the bottom of the
  line box.</dd>
</dl>

<p>The baseline of an ''display/inline-table'' is the baseline of the first row
of the table.
</p>
<p>The baseline of an ''display/inline-block'' is the baseline of its last line
box in the normal flow, unless it has either no in-flow line boxes or
if its 'overflow' property has a computed value other than ''overflow/visible'',
in which case the baseline is the bottom margin edge.</p>





<h2 id="visufx"><span id="q11.0">Visual effects</span></h2>

<h3 id="overflow-clipping">Overflow and clipping</h3>

<p>Generally, the content of a block box is confined to the
content edges of the box. In certain cases, a box may <dfn>overflow</dfn>, meaning its
content lies partly or entirely outside of the box, e.g.:</p>

<ul>
<li>A line cannot be broken, causing the line box to be wider than the
block box.
</li>
<li>A block-level box is too wide for the containing block. This may
happen when an
element's 'width' property has a
value that causes the generated block box to spill over
sides of the containing block.
</li>
<li>An element's height exceeds an explicit height assigned to the containing
block (i.e., the containing block's height is determined by the 'height' property, not by content
height).
</li>
<li>A descendant box is <a href="#absolute-positioning">positioned
absolutely</a>, partly outside the box.  Such boxes are not always
clipped by the overflow property on their ancestors; specifically,
they are not clipped by the overflow of any ancestor between
themselves and their containing block.
</li>
<li>A descendant box has <a href="#margin-properties">negative margins</a>, causing it
to be positioned partly outside the box.
</li>
<li>The 'text-indent' property causes an inline box to hang off either the left or right edge of the block box.
</li>
</ul>

<p>Whenever overflow occurs, the 'overflow' property specifies
whether a box is clipped to its padding edge, and if so, whether
a scrolling mechanism is provided to access any clipped out content.
</p>

<h4 id="overflow">Overflow: the 'overflow' property</h4>

<xmp class="propdef">
Name: overflow
Value: visible | hidden | scroll | auto | inherit
Initial: visible
Applies to: block containers
Inherited: no
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p>
This property specifies whether content of a block container element is
clipped when it overflows the element's box.  It affects the clipping
of all of the element's content except any descendant elements (and
their respective content and descendants) whose containing block is the viewport or an ancestor of the element.  Values have the following meanings:
</p>

<dl>

<dt><dfn class="css" dfn-for="overflow" dfn-type="value" id="valdef-overflow-visible">visible</dfn></dt>

<dd>This value indicates that content is not clipped, i.e., it
may be rendered outside the block box.
</dd>

<dt><dfn class="css" dfn-for="overflow" dfn-type="value" id="valdef-overflow-hidden">hidden</dfn></dt>

<dd>This value indicates that the content is clipped and that no
scrolling user interface should be provided to view the content outside the
clipping region.
</dd>

<dt><dfn class="css" dfn-for="overflow" dfn-type="value" id="valdef-overflow-scroll">scroll</dfn></dt>

<dd>This value indicates that the content is clipped and that if the
user agent uses a scrolling mechanism that is visible on the screen
(such as a scroll bar or a panner), that mechanism should be displayed
for a box whether or not any of its content is clipped. This avoids
any problem with scrollbars appearing and disappearing in a dynamic
environment.
When this value is specified and the target medium is
''print'', overflowing content may be printed.
</dd>

<dt><dfn class="css" dfn-for="overflow" dfn-type="value" id="valdef-overflow-auto">auto</dfn></dt>

<dd>The behavior of the ''overflow/auto'' value is user agent-dependent, but
should cause a scrolling mechanism to be provided for overflowing boxes.
</dd>

</dl>

<p> Even if 'overflow' is set
to ''overflow/visible'', content may be clipped to a UA's document window by the
native operating environment.
</p>

<p>
UAs must apply the 'overflow' property set on the root element to
the viewport.
When the root element is an HTML "HTML" element or an XHTML "html"
element, and that element has an HTML "BODY" element or an XHTML
"body" element as a child, user agents must instead apply the
'overflow' property from the first such child element to the
viewport, if the value on the root element is ''overflow/visible''.
The ''overflow/visible'' value when used for the viewport
must be interpreted as ''overflow/auto''. The element from which the value is
propagated must have a used value for 'overflow' of ''overflow/visible''.
</p>

<p>
In the case of a scrollbar being placed on an edge of the element's
box, it should be inserted between the inner border edge and the outer
padding edge. Any space taken up by the scrollbars should be taken out
of (subtracted from the dimensions of) the containing block formed by
the element with the scrollbars.
</p>

<div class="example"><p>
Consider the following example of a block quotation
(<code>&lt;blockquote&gt;</code>) that is too big
for its containing block (established by a <code>&lt;div&gt;</code>). Here is
the source:</p>

<pre class="lang-html example"><code class="html">
&lt;div&gt;
&lt;blockquote&gt;
&lt;p&gt;I didn't like the play, but then I saw
it under adverse conditions - the curtain was up.&lt;/p&gt;
&lt;cite&gt;- Groucho Marx&lt;/cite&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
</code></pre>

<p>Here is the style sheet controlling the sizes and style of the
generated boxes:
</p>

<pre class="lang-css">
div { width : 100px; height: 100px;
      border: thin solid red;
      }

blockquote   { width : 125px; height : 100px;
      margin-top: 50px; margin-left: 50px;
      border: thin dashed black
      }

cite { display: block;
       text-align : right;
       border: none
       }
</pre>

<p>The initial value of 'overflow' is ''overflow/visible'', so
the <code>&lt;blockquote&gt;</code> would be formatted without clipping, something like this:</p>

<div class="figure">
<p><img src="./images/overflow1.png" alt="Rendered overflow" id="img-overflow1"></p>
</div>

<p>Setting 'overflow' to
''overflow/hidden'' for the <code>&lt;div&gt;</code>, on the other hand, causes the
<code>&lt;blockquote&gt;</code> to be clipped by the containing
<code>&lt;div&gt;</code>:
</p>

<div class="figure">
<p><img src="./images/overflow2.png" alt="Clipped overflow" id="img-overflow2"></p>
</div>

<p>A value of ''overflow/scroll'' would tell UAs that support
a visible scrolling mechanism to display one so that users
could access the clipped content.
</p>
</div>

<div>
<p>
Finally, consider this case where an absolutely positioned element
is mixed with an overflow parent.
</p>
<p>
Style sheet:
</p>
<pre class="lang-html">
  container { position: relative; border: solid; }
  scroller { overflow: scroll; height: 5em; margin: 5em; }
  satellite { position: absolute; top: 0; }
  body { height: 10em; }
</pre>
<p>
Document fragment:
</p>
<pre class="lang-xml">
  &lt;container&gt;
   &lt;scroller&gt;
    &lt;satellite/&gt;
    &lt;body/&gt;
   &lt;/scroller&gt;
  &lt;/container&gt;
</pre>
<p>
In this example, the "scroller" element will not scroll the
"satellite" element, because the latter's containing block is outside
the element whose overflow is being clipped and scrolled.
</p>
</div>

<h4 id="clipping">Clipping: the 'clip' property</h4>

<!--
<p>[What about the "lost errata" for clip? See
<a href="https://lists.w3.org/Archives/Member/w3c-css-wg/2001OctDec/0218.html">David</a>
and
<a href="https://lists.w3.org/Archives/Member/w3c-css-wg/2001OctDec/0235.html">Eric</a>.
BB]
-->

<p>A <dfn>clipping
region</dfn> defines what portion of an element's
border box
<!--<a href="conform.html#rendered-content">rendered content</a>-->
is visible. By default, the element is not clipped. However, the clipping region may be explicitly set with the 'clip' property.
</p>

<xmp class="propdef">
Name: clip
Value: <<shape>> | auto | inherit
Initial: auto
Applies to: absolutely positioned elements
Inherited: no
Percentages: N/A
Media: visual
Computed Value: ''auto'' if specified as ''auto'', otherwise a rectangle with four
  values, each of which is ''auto'' if specified as ''auto'' and the
  computed length otherwise
Animation type: by computed value type
</xmp>



<p>The 'clip' property applies only to absolutely positioned elements.
Values have the following meanings:</p>

<dl>
<dt><dfn dfn-for="clip" dfn-type="value" id="valdef-clip-auto">auto</dfn></dt>
<dd>The element does not clip.</dd>

<dt><dfn id="value-def-shape">&lt;shape&gt;</dfn></dt>
<dd>In CSS&nbsp;2, the only valid &lt;shape&gt; value is:
rect(<span class="value-inst-top">&lt;top&gt;</span>, <span class="value-inst-right">&lt;right&gt;</span>, <span class="value-inst-bottom">&lt;bottom&gt;</span>, <span class="value-inst-left">&lt;left&gt;</span>)

where <span class="value-inst-top">&lt;top&gt;</span> and <span class="value-inst-bottom">&lt;bottom&gt;</span> specify offsets from
the top border edge of the box, and <span class="value-inst-right">&lt;right&gt;</span>, and <span class="value-inst-left">&lt;left&gt;</span> specify offsets from the
left border edge of the box. Authors should separate
offset values with commas. User agents must support separation with
commas, but may also support separation without commas (but not a
combination), because a
previous revision of this specification was ambiguous in this respect.

<p><dfn id="value-def-top">&lt;top&gt;</dfn>, <dfn id="value-def-right">&lt;right&gt;</dfn>,
<dfn id="value-def-bottom">&lt;bottom&gt;</dfn>,
and <dfn id="value-def-left">&lt;left&gt;</dfn> may
either have a <span class="value-inst-length"><<length>></span>
value or <dfn dfn-type="value" dfn-for="<top>,<right>,<bottom>,<left>">auto</dfn>. Negative lengths are permitted. The value ''<top>/auto''
means that a given edge of the clipping region will be the same as the
edge of the element's generated border box (i.e., ''<top>/auto'' means the same as ''0'' for <span class="value-inst-top">&lt;top&gt;</span> and <span class="value-inst-left">&lt;left&gt;</span>, the same as the used
value of the height plus the sum of
vertical padding and border widths for <span class="value-inst-right">&lt;bottom&gt;</span>, and the same as the
used value of the width plus the sum of the horizontal padding and
border widths for <span class="value-inst-right">&lt;right&gt;</span>,
such that four ''<top>/auto'' values result in the clipping region being
the same as the element's border box).
</p>
<p>When coordinates are rounded to pixel coordinates, care should be
taken that no pixels remain visible when &lt;left&gt; and
&lt;right&gt; have the same value (or &lt;top&gt; and &lt;bottom&gt;
have the same value), and conversely that no pixels within the
element's border box remain hidden when these values are ''<top>/auto''.
</p>
</dd>
</dl>

<p>An element's clipping region clips out any aspect of the element (e.g., content, children, background, borders, text decoration, outline and visible scrolling mechanism &mdash; if any) that is outside the clipping region.
Content that has been clipped does not cause overflow.
</p>
<p>The element's ancestors may also clip portions of their content (e.g., via their own 'clip' property and/or if
their 'overflow' property is
not ''overflow/visible''); what is rendered is the cumulative intersection.
</p>
<p>If the clipping region exceeds the bounds of the UA's
document window, content may be clipped to that window by the
native operating environment.
</p>
<div class="example"><p>Example:
The following two rules:</p>
<pre class="lang-css">
p#one { clip: rect(5px, 40px, 45px, 5px); }
p#two { clip: rect(5px, 55px, 45px, 5px); }
</pre>

<p>and assuming both Ps are 50 by 55 px, will create, respectively,
the rectangular clipping regions delimited
by the dashed lines in the following illustrations:</p>

<div class="figure">
<p><img src="images/clip.png" alt="Two clipping regions" id="img-clip"></p>
</div>
</div>

<div class="note"><p> <em><strong>Note.</strong> In CSS&nbsp;2, all clipping
regions are rectangular. We anticipate future extensions to permit
non-rectangular clipping. Future updates may also reintroduce a
syntax for offsetting shapes from each edge instead of offsetting from
a point.</em></div>

<h3 id="visibility">Visibility: the 'visibility' property</h3>

<xmp class="propdef">
Name: visibility
Value: visible | hidden | collapse | inherit
Initial: visible
Applies to: *
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p>The 'visibility' property
specifies whether the boxes generated by an element are
rendered. Invisible boxes still affect layout (set the 'display' property to ''display/none'' to
suppress box generation altogether).  Values have the following
meanings:</p>

<dl>
<dt><dfn class="css" dfn-for="visibility" dfn-type="value" id="valdef-visibility-visible">visible</dfn></dt>
<dd>The generated box is visible.</dd>
<dt><dfn class="css" dfn-for="visibility" dfn-type="value" id="valdef-visibility-hidden">hidden</dfn></dt>
<dd>The generated box is invisible (fully transparent, nothing is drawn), but still
affects layout. Furthermore, descendants of the element will
be visible if they have 'visibility: visible'.</dd>
<dt><dfn class="css" dfn-for="visibility" dfn-type="value" id="valdef-visibility-collapse">collapse</dfn></dt>
<dd>Please consult the section on
<a href="#dynamic-effects">dynamic row and column
effects</a> in tables. If used on elements other than rows, row groups, columns, or column groups,
''visibility/collapse'' has the same meaning as ''visibility/hidden''.
</dd>
</dl>

<p>This property may be used in conjunction with scripts to create
dynamic effects.
</p>
<div class="lang-html example"><p> In the following example, pressing
either form button invokes an author-defined script function that causes
the corresponding box to become visible and the other to be
hidden. Since these boxes have the same size and position, the effect
is that one replaces the other. (The script code is in a hypothetical
script language. It may or may not have any effect in a CSS-capable
UA.)
</p>
<pre class="lang-html">
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
&lt;HEAD&gt;&lt;TITLE&gt;Dynamic visibility example&lt;/TITLE&gt;
&lt;META
 http-equiv="Content-Script-Type"
 content="application/x-hypothetical-scripting-language"&gt;
&lt;STYLE type="text/css"&gt;
&lt;!--
   #container1 { position: absolute;
                 top: 2in; left: 2in; width: 2in }
   #container2 { position: absolute;
                 top: 2in; left: 2in; width: 2in;
                 visibility: hidden; }
--&gt;
&lt;/STYLE&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;
&lt;P&gt;Choose a suspect:&lt;/P&gt;
&lt;DIV id="container1"&gt;
   &lt;IMG alt="Al Capone"
        width="100" height="100"
        src="suspect1.png"&gt;
   &lt;P&gt;Name: Al Capone&lt;/P&gt;
   &lt;P&gt;Residence: Chicago&lt;/P&gt;
&lt;/DIV&gt;

&lt;DIV id="container2"&gt;
   &lt;IMG alt="Lucky Luciano"
        width="100" height="100"
        src="suspect2.png"&gt;
   &lt;P&gt;Name: Lucky Luciano&lt;/P&gt;
   &lt;P&gt;Residence: New York&lt;/P&gt;
&lt;/DIV&gt;

&lt;FORM method="post"
      action="http://www.suspect.org/process-bums"&gt;
   &lt;P&gt;
   &lt;INPUT name="Capone" type="button"
          value="Capone"
          onclick='show("container1");hide("container2")'&gt;
   &lt;INPUT name="Luciano" type="button"
          value="Luciano"
          onclick='show("container2");hide("container1")'&gt;
&lt;/FORM&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;
</pre>

</div>




<h2 id="generated-text">
Generated <dfn data-lt="generated content">content</dfn>, automatic <dfn data-lt="automatic numbering">numbering</dfn>,
and lists</h2>

<p>In some cases, authors may want user agents to render content
that does not come from the <a href="#doctree">document
tree</a>. One familiar example of this is a numbered list; the author
does not want to list the numbers explicitly, they want the
user agent to generate them automatically. Similarly, authors
may want the user agent to insert the word
"Figure" before the caption of a figure, or "Chapter 7" before the
seventh chapter title. For audio or braille in particular, user agents
should be able to insert these strings.

<p>In CSS&nbsp;2, content may be generated by two mechanisms:</p>

<ul>
<li>The 'content'
property, in conjunction with the :before and :after pseudo-elements.
<li>Elements with a value of ''list-item''
for the 'display' property.
</ul>


<h3 id="before-after-content">The <dfn>:before</dfn> and <dfn>:after</dfn>
pseudo-elements</h3>

<p>Authors specify the style and location of generated content with
the :before and :after pseudo-elements. As their names indicate, the
:before and :after pseudo-elements specify the location of content
before and after an element's <a href="#doctree">document
tree</a> content.  The 'content'
property, in conjunction with these pseudo-elements, specifies what is
inserted.

<div class="example">
<p>For example, the following rule inserts the string "Note: "
before the content of
every P element whose "class" attribute has the value "note":</p>

<pre class="lang-css">
p.note:before { content: "Note: " }
</pre>
</div>

<p>The formatting objects (e.g., boxes) generated by an element include
generated content. So, for example, changing the above style sheet
to:</p>

<pre class="example lang-css">
p.note:before { content: "Note: " }
p.note        { border: solid green }
</pre>

<p>would cause a solid green border to be rendered around the entire
paragraph, including the initial string.

<p>The :before and :after pseudo-elements <a href="#inheritance">inherit</a> any inheritable properties
from the element in the document tree to which they are attached.</p>

<!-- Does the previous statement apply to all pseudo-elements? -IJ -->

<div class="example">

<p>For example, the following rules insert an open quote mark before every
Q element. The color of the quote mark will be red, but the font will
be the same as the font of the rest of the Q element:</p>

<pre class="lang-css">
q:before {
  content: open-quote;
  color: red
}
</pre>
</div>

<p>In a :before or :after pseudo-element declaration, non-inherited
properties take their <a href="#initial-value">initial
values</a>.</p>

<div class="example">
<p>So, for example, because the initial value of the 'display' property is ''inline'', the
quote in the previous example is inserted as an inline box (i.e.,
on the same line as the element's initial text content).
The next example explicitly sets the
'display' property to
''block'', so that the inserted text becomes a block:</p>

<pre class="lang-css">
body:after {
    content: "The End";
    display: block;
    margin-top: 2em;
    text-align: center;
}
</pre>

</div>

<p>The :before and :after pseudo-elements interact with other
boxes as if they were real elements inserted just
inside their associated element.</p>

<div class="example">
<p>For example, the following document fragment and style sheet:</p>
<pre class="lang-css">
&lt;p&gt; Text &lt;/p&gt;                   p:before { display: block; content: 'Some'; }
</pre>
<p>...would render in exactly the same way as the following document
fragment and style sheet:</p>
<pre class="lang-css">
&lt;p&gt;&lt;span&gt;Some&lt;/span&gt; Text &lt;/p&gt;  span { display: block }
</pre>
<p>Similarly, the following document fragment and style sheet:</p>
<pre class="lang-css">
&lt;h2&gt; Header &lt;/h2&gt;     h2:after { display: block; content: 'Thing'; }
</pre>
<p>...would render in exactly the same way as the following document
fragment and style sheet:</p>
<pre class="lang-css">
&lt;h2&gt; Header &lt;span&gt;Thing&lt;/span&gt;&lt;/h2&gt;   h2 { display: block; }
                                      span { display: block; }
</pre>
</div>

<div class="note">
<p><strong>Note.</strong> This specification does not fully define the interaction of :before
and :after with replaced elements (such as IMG in HTML). This will
be defined in more detail in a future specification.</p>
</div>

<h3 id="content">The 'content' property</h3>

<xmp class="propdef">
Name: content
Value: normal | none | [ <<string>> | <<uri>> | <<counter>> | attr(<<identifier>>) | open-quote | close-quote | no-open-quote | no-close-quote ]+ | inherit
Initial: normal
Applies to: :before and :after pseudo-elements
Inherited: no
Percentages: N/A
Media: all
Computed Value: On elements, always computes to ''content/normal''. On :before and :after, if
  ''content/normal'' is specified, computes to ''content/none''. Otherwise, for URI
  values, the absolute URI; for attr() values, the resulting string;
  for other keywords, as specified.
Animation type: by computed value type
</xmp>



<p>This property is used with the :before and :after pseudo-elements
to generate content in a document. Values have the following
meanings:</p>

<dl dfn-for="content" dfn-type="value">

<dt><dfn id="valdef-content-none">none</dfn>
<dd>The pseudo-element is not generated.</dd>

<dt><dfn id="valdef-content-normal">normal</dfn>
<dd>Computes to ''content/none'' for the :before and :after pseudo-elements.</dd>

<dt><dfn><<string>></dfn>
<dd>Text content
(see the section on <a href="#strings">strings</a>).

<dt><dfn><<uri>></dfn>
<dd>The value is a URI that designates an external resource (such as an image).
If  the user agent cannot display the resource it must either leave
it out as if it were not specified or display some indication that
the resource cannot be displayed.

<dt><dfn><<counter>></dfn>
<dd><a href="#counter">Counters</a> may be specified
with two different functions: ''counter()'' or ''counters()''.
The former has two forms:
'counter(<var>name</var>)' or 'counter(<var>name</var>,
<var>style</var>)'.

The generated text is the value of the innermost counter of the given
name in scope at this pseudo-element; it is formatted in the indicated
<a href="#counter-styles">style</a> (''list-style-type/decimal'' by default). The latter
function also has two forms: 'counters(<var>name</var>,
<var>string</var>)' or 'counters(<var>name</var>, <var>string</var>,
<var>style</var>)'. The generated text is the value of all counters
with the given name in scope at this pseudo-element, from outermost to
innermost separated by the specified string. The counters are rendered
in the indicated <a href="#counter-styles">style</a> (''list-style-type/decimal'' by
default). See the section on <a href="#counters">automatic counters
and numbering</a> for more information.

The name must not be <css>none</css>, <css>inherit</css> or <css>initial</css>. Such a name
causes the declaration to be ignored.

<dt><dfn id="value-def-open-quote">open-quote</dfn>
and <dfn id="value-def-close-quote">close-quote</dfn>

<dd>These values are replaced by the appropriate string
from the <strong>'quotes'</strong> property.

<dt><dfn id="value-def-no-open-quote">no-open-quote</dfn>
and <dfn id="value-def-no-close-quote">no-close-quote</dfn>

<dd>Introduces no content, but increments (decrements) the level of nesting for quotes.

<dt><dfn>attr(X)</dfn>
<dd>This function returns as a string the value of attribute X
for the subject of the selector. The
string is not parsed by the CSS processor.  If the subject of the selector
does not have an attribute X, an empty string is returned. The
case-sensitivity of attribute names depends on the document language.
</dl>

<div class="note">
<strong>Note.</strong> In CSS&nbsp;2, it is not possible to refer to
attribute values for other elements than the subject of the selector.
</div>


<p>The 'display' property
controls whether the content is placed in a block or inline box.

<div class="example"><p>The following rule causes the string "Chapter: " to be generated before each H1 element:</p>

<pre class="lang-css">
H1:before {
  content: "Chapter: ";
  display: inline;
}
</pre>
</div>

<p>Authors may include newlines in the generated content by writing
the "\A" escape sequence in one of the strings after the 'content' property. This inserted line
break is still subject to the 'white-space' property. See <a href="#strings">"Strings"</a> and <a href="#escaped-characters">"Characters and case"</a> for
more information on the "\A" escape sequence.

<div class="example"><p>

<pre class="lang-css">
h1:before {
    display: block;
    text-align: center;
    white-space: pre;
    content: "chapter\A hoofdstuk\A chapitre"
}
</pre>
</div>

<p>Generated content does not alter the document tree. In particular, it
is not fed back to the document language processor (e.g., for
reparsing).

<h3 id="quotes">Quotation marks</h3>

<p>In CSS&nbsp;2, authors may specify, in a style-sensitive and
context-dependent manner, how user agents should render quotation
marks. The 'quotes' property
specifies pairs of quotation marks for each level of embedded
quotation. The 'content'
property gives access to those quotation marks and causes them to be
inserted before and after a quotation.

<h4 id="quotes-specify">Specifying quotes with the 'quotes' property</h4>

<xmp class="propdef">
Name: quotes
Value: [<<string>> <<string>>]+ | none | inherit
Initial: depends on user agent
Applies to: *
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p>This property specifies quotation marks for any number of embedded
quotations. Values have the following meanings:</p>

<dl dfn-for="quotes" dfn-type="value">
<dt><dfn id="valdef-quotes-none">none</dfn>

<dd>The ''content/open-quote'' and ''content/close-quote'' values of the
'content' property
produce no quotation marks.

<dt><dfn id="valdef-quotes-strings">[<<string>>
&nbsp;<<string>>]+</dfn>

<dd>Values for the ''content/open-quote'' and ''content/close-quote'' values of the
'content' property are taken
from this list of pairs of quotation marks (opening and
closing). The first (leftmost) pair represents the outermost level of
quotation, the second pair the first level of embedding, etc. The user
agent must apply the appropriate pair of quotation marks according to
the level of embedding.
</dl>


<div class="example">
<p>For example, applying the following style sheet:</p>

<pre class="example lang-css">
/* Specify pairs of quotes for two levels in two languages */
q:lang(en) { quotes: '"' '"' "'" "'" }
q:lang(no) { quotes: "&laquo;" "&raquo;" '"' '"' }

/* Insert quotes before and after Q element content */
q:before { content: open-quote }
q:after  { content: close-quote }
</pre>

<p>to the following HTML fragment:</p>

<pre class="lang-html example">
&lt;HTML lang="en"&gt;
  &lt;HEAD&gt;
  &lt;TITLE&gt;Quotes&lt;/TITLE&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
    &lt;P&gt;&lt;Q&gt;Quote me!&lt;/Q&gt;
  &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>

<p>would allow a user agent to produce:</p>

<pre class="ascii-art">
"Quote me!"
</pre>

<p>while this HTML fragment:</p>

<pre class="lang-html example">
&lt;HTML lang="no"&gt;
  &lt;HEAD&gt;
  &lt;TITLE&gt;Quotes&lt;/TITLE&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
    &lt;P&gt;&lt;Q&gt;Tr&oslash;ndere gr&aring;ter n&aring;r &lt;Q&gt;Vinsjan p&aring; kaia&lt;/Q&gt; blir deklamert.&lt;/Q&gt;
  &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>

<p>would produce:</p>

<pre class="ascii-art">
&laquo;Tr&oslash;ndere gr&aring;ter n&aring;r "Vinsjan p&aring; kaia" blir deklamert.&raquo;
</pre>
</div>

<div class="note"><p>
<em><strong>Note.</strong>
While the quotation marks specified by 'quotes' in the previous examples are
conveniently located on computer keyboards, high quality typesetting
would require different ISO 10646 characters. The following
informative table lists some of the ISO 10646 quotation
mark characters:</em></p>

<table>
<tr><th>Character<th>Approximate rendering<th>ISO 10646 code (hex)<th>Description
<tr><td>"<td>"<!--"--><td>0022<td>QUOTATION MARK [the ASCII double quotation mark]
<tr><td>'<td>'<td>0027<td>APOSTROPHE     [the ASCII single quotation mark]
<tr><td>&lsaquo;<td>&lt;<td>2039<td>SINGLE LEFT-POINTING ANGLE QUOTATION MARK
<tr><td>&rsaquo;<td>&gt;<td>203A<td>SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
<tr><td>&laquo;<td>&laquo;<td>00AB<td>LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
<tr><td>&raquo;<td>&raquo;<td>00BB<td>RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
<tr><td>&lsquo;<td>`<td>2018<td>LEFT SINGLE QUOTATION MARK [single high-6]
<tr><td>&rsquor;<td>'<td>2019<td>RIGHT SINGLE QUOTATION MARK [single high-9]
<tr><td>&ldquo;<td>``<td>201C<td>LEFT DOUBLE QUOTATION MARK  [double high-6]
<tr><td>&rdquor;<td>&apos;&apos;<td>201D<td>RIGHT DOUBLE QUOTATION MARK [double high-9]
<tr><td>&ldquor;<td>,,<td>201E<td>DOUBLE LOW-9 QUOTATION MARK [double low-9]
</table>
</div>


<h4 id="quotes-insert">Inserting quotes with the 'content' property</h4>

<p>Quotation marks are inserted in appropriate places in a document
with the ''content/open-quote'''
and ''content/close-quote'' values of the
'content' property. Each
occurrence of ''content/open-quote'' or ''content/close-quote'' is replaced by one of the
strings from the value of 'quotes', based on the depth of
nesting.

<p>''content/open-quote'' refers to the first of a pair of quotes, ''content/close-quote''
refers to the second. Which pair of quotes is used depends on the
nesting level of quotes: the number of occurrences of ''content/open-quote'' in
all generated text before the current occurrence, minus the number of
occurrences of ''content/close-quote''. If the depth is 0, the first pair is
used, if the depth is 1, the second pair is used, etc. If the depth is
greater than the number of pairs, the last pair is repeated. A ''content/close-quote''
or ''content/no-close-quote'' that would make the depth negative is in error and is
ignored (at rendering time): the depth stays at 0 and no quote mark is
rendered (although the rest of the 'content' property's value is still
inserted).


<div class="note"><p>
<em><strong>Note.</strong> The quoting depth is independent of the nesting
of the source document or the formatting structure.</em>
</div>

<p>Some typographic styles require open quotation marks to be repeated
before every paragraph of a quote spanning several paragraphs, but
only the last paragraph ends with a closing quotation mark. In CSS,
this can be achieved by inserting "phantom" closing quotes. The
keyword ''content/no-close-quote'' decrements
the quoting level, but does not insert a quotation mark.


<div class="example">
<p>The following style sheet puts opening quotation marks on every
paragraph in a BLOCKQUOTE, and inserts a single closing quote at the
end:

<pre class="lang-css">
blockquote p:before     { content: open-quote }
blockquote p:after      { content: no-close-quote }
blockquote p.last:after { content: close-quote }
</pre>

<p>This relies on the last paragraph being marked with a class "last".
</div>

<p>For symmetry, there is also a no-open-quote keyword,
which inserts nothing, but increments the quotation depth by one.


<h3 id="counters">Automatic <dfn>counters</dfn> and numbering</h3>

<p>Automatic numbering in CSS&nbsp;2 is controlled with two properties,
'counter-increment'
and 'counter-reset'. The
counters defined by these properties are used with the counter() and
counters() functions of the 'content' property.

</p>
<xmp class="propdef">
Name: counter-reset
Value: [ <<identifier>> <<integer>>? ]+ | none | inherit
Initial: none
Applies to: *
Inherited: no
Percentages: N/A
Media: all
Computed Value: as specified
Animation type: by computed value type
</xmp>


<xmp class="propdef">
Name: counter-increment
Value: [ <<identifier>> <<integer>>? ]+ | none | inherit
Initial: none
Applies to: *
Inherited: no
Percentages: N/A
Media: all
Computed Value: as specified
Animation type: by computed value type
</xmp>



<p>The 'counter-increment' property
accepts one or more names of counters (identifiers), each one
optionally followed by an integer. The integer indicates by how much the
counter is incremented for every occurrence of the element. The
default increment is 1. Zero and negative integers are allowed.

<p>The 'counter-reset'
property also contains a list of one or more names of counters, each
one optionally followed by an integer. The integer gives the value that
the counter is set to on each occurrence of the element. The default
is 0.

<p>The keywords <css>none</css>, <css>inherit</css> and <css>initial</css> must not be used as
counter names. A value of <dfn dfn-type="value" dfn-for="counter-reset,counter-increment">none</dfn> on its own means no counters are
reset, resp. incremented. ''inherit'' on its own has its usual meaning
(see <a href="#value-def-inherit">6.2.1</a>). <css>initial</css> is
reserved for future use.

<div class="example">
<p>This example shows a way to number chapters and sections with
"Chapter 1", "1.1", "1.2", etc.

<pre class="lang-css">
BODY {
    counter-reset: chapter;      /* Create a chapter counter scope */
}
H1:before {
    content: "Chapter " counter(chapter) ". ";
    counter-increment: chapter;  /* Add 1 to chapter */
}
H1 {
    counter-reset: section;      /* Set section to 0 */
}
H2:before {
    content: counter(chapter) "." counter(section) " ";
    counter-increment: section;
}
</pre>
</div>

<p>If an element increments/resets a counter and also uses it (in the
'content' property of its
:before or :after pseudo-element), the counter is used <em>after</em>
being incremented/reset.

<p>If an element both resets and increments a counter, the counter is
reset first and then incremented.

<p>If the same counter is specified more than once in the value of the
'counter-reset' and 'counter-increment'
properties, each reset/increment of the counter is processed in the order
specified.

<div class="example">
<p>The following example will reset the ''section'' counter to 0:

<pre class="lang-css">
H1 { counter-reset: section 2 section }
</pre>

<p>The following example will increment the ''chapter'' counter by 3:

<pre class="lang-css">
H1 { counter-increment: chapter chapter 2 }
</pre>
</div>




<p>The 'counter-reset'
property follows the cascading rules. Thus, due to cascading, the
following style sheet:</p>

<pre class="example lang-css">
H1 { counter-reset: section -1 }
H1 { counter-reset: imagenum 99 }
</pre>

<p>will only reset ''imagenum''. To reset both counters, they have to be
specified together:</p>

<pre class="example lang-css">
H1 { counter-reset: section -1 imagenum 99 }
</pre>

<h4 id="scope">Nested counters and scope</h4>

<p>Counters are "self-nesting", in the sense that resetting a counter
in a descendant element or pseudo-element automatically creates a new
instance of the counter. This is important for situations like lists
in HTML, where elements can be nested inside themselves to arbitrary
depth. It would be impossible to define uniquely named counters for
each level.

<div class="example">
<p>Thus, the following suffices to number nested list items. The
result is very similar to that of setting ''display:list-item'' and
'list-style: inside' on the LI element:

<pre class="lang-css">
OL { counter-reset: item }
LI { display: block }
LI:before { content: counter(item) ". "; counter-increment: item }
</pre>
</div>

<p>The <dfn>scope</dfn>
of a counter starts at the first element in the document that has a
'counter-reset' for that
counter and includes the element's descendants and its following
siblings with their descendants. However, it does not include any
elements in the scope of a counter with the same name created by a 'counter-reset' on a
later sibling of the element or by a later 'counter-reset' on the same
element.

<p>If 'counter-increment' or 'content' on an element or
pseudo-element refers to a counter that is not in the scope of any
'counter-reset',
implementations should behave as though a 'counter-reset' had reset the
counter to 0 on that element or pseudo-element.

<p>In the example above, an OL will create a counter, and all children
of the OL will refer to that counter.

<div class="lang-html example"> <p>If we denote by item[n] the
n<sup>th</sup> instance of the "item"
counter, and by "{" and "}" the beginning and end of a
scope, then the following HTML fragment will use the indicated
counters. (We assume the style sheet as given in the example above).

<pre class="lang-css">
&lt;OL&gt;                    &lt;!-- {item[0]=0        --&gt;
  &lt;LI&gt;item&lt;/LI&gt;         &lt;!--  item[0]++ (=1)   --&gt;
  &lt;LI&gt;item              &lt;!--  item[0]++ (=2)   --&gt;
    &lt;OL&gt;                &lt;!--  {item[1]=0       --&gt;
      &lt;LI&gt;item&lt;/LI&gt;     &lt;!--   item[1]++ (=1)  --&gt;
      &lt;LI&gt;item&lt;/LI&gt;     &lt;!--   item[1]++ (=2)  --&gt;
      &lt;LI&gt;item          &lt;!--   item[1]++ (=3)  --&gt;
        &lt;OL&gt;            &lt;!--   {item[2]=0      --&gt;
          &lt;LI&gt;item&lt;/LI&gt; &lt;!--    item[2]++ (=1) --&gt;
        &lt;/OL&gt;           &lt;!--                   --&gt;
        &lt;OL&gt;            &lt;!--   }{item[2]=0     --&gt;
          &lt;LI&gt;item&lt;/LI&gt; &lt;!--    item[2]++ (=1) --&gt;
        &lt;/OL&gt;           &lt;!--                   --&gt;
      &lt;/LI&gt;             &lt;!--   }               --&gt;
      &lt;LI&gt;item&lt;/LI&gt;     &lt;!--   item[1]++ (=4)  --&gt;
    &lt;/OL&gt;               &lt;!--                   --&gt;
  &lt;/LI&gt;                 &lt;!--  }                --&gt;
  &lt;LI&gt;item&lt;/LI&gt;         &lt;!--  item[0]++ (=3)   --&gt;
  &lt;LI&gt;item&lt;/LI&gt;         &lt;!--  item[0]++ (=4)   --&gt;
&lt;/OL&gt;                   &lt;!--                   --&gt;
&lt;OL&gt;                    &lt;!-- }{item[0]=0       --&gt;
  &lt;LI&gt;item&lt;/LI&gt;         &lt;!--  item[0]++ (=1)   --&gt;
  &lt;LI&gt;item&lt;/LI&gt;         &lt;!--  item[0]++ (=2)   --&gt;
&lt;/OL&gt;                   &lt;!--                   --&gt;
</pre>
</div>

<div class="example">
<p>Another example, showing how scope works when counters are used on
elements that are not nested, is the following.  This shows how the
style rules given above to number chapters and sections would apply to
the markup given.

<pre class="lang-xml">
                     &lt;!--"chapter" counter|"section" counter --&gt;
&lt;body&gt;               &lt;!-- {chapter=0      |                  --&gt;
  &lt;h1&gt;About CSS&lt;/h1&gt; &lt;!--  chapter++ (=1) | {section=0       --&gt;
  &lt;h2&gt;CSS 2&lt;/h2&gt;     &lt;!--                 |  section++ (=1)  --&gt;
  &lt;h2&gt;CSS&nbsp;2&lt;/h2&gt;   &lt;!--                 |  section++ (=2)  --&gt;
  &lt;h1&gt;Style&lt;/h1&gt;     &lt;!--  chapter++ (=2) |}{ section=0      --&gt;
&lt;/body&gt;              &lt;!--                 | }                --&gt;
</pre>

</div>

<p>The ''counters()'' function generates a string composed of all of the
counters with the same name that are in scope, separated by a given
string.

<div class="example"><p>
<p>The following style sheet numbers nested list items
as "1", "1.1", "1.1.1", etc.

<pre class="lang-css">
OL { counter-reset: item }
LI { display: block }
LI:before { content: counters(item, ".") " "; counter-increment: item }
</pre>
</div>

<h4 id="counter-styles">Counter styles</h4>

<p>By default, counters are formatted with decimal numbers, but all the
styles available for the 'list-style-type' property are
also available for counters. The notation is:</p>

<pre>
counter(<var>name</var>)
</pre>
<p>for the default style, or:</p>

<pre>
counter(<var>name</var>, &lt;'list-style-type'&gt;)
</pre>

<p>All the styles are allowed, including ''list-style-type/disc'', ''list-style-type/circle'', ''list-style-type/square'',
and ''list-style-type/none''.

<div class="example"><p>

<pre class="lang-css">
H1:before        { content: counter(chno, upper-latin) ". " }
H2:before        { content: counter(section, upper-roman) " - " }
BLOCKQUOTE:after { content: " [" counter(bq, lower-greek) "]" }
DIV.note:before  { content: counter(notecntr, disc) " " }
P:before         { content: counter(p, none) }
</pre>
</div>


<h4 id="undisplayed-counters">Counters in elements with 'display: none'</h4>

<p>An element that is not displayed ('display' set to ''display/none'') cannot
increment or reset a counter.

<div class="example">
<p>For example, with the following style sheet,
H2s with class "secret" do not increment ''count2''.

<pre class="lang-css">
H2.secret {counter-increment: count2; display: none}
</pre>
</div>

<p>Pseudo-elements that are not generated also cannot increment or
reset a counter.

<div class="example">
<p>For example, the following does not increment ''heading'':

<pre class="lang-css">
h1::before {
    content: normal;
    counter-increment: heading;
}
</pre>
</div>

<p>Elements with 'visibility'
set to ''visibility/hidden'', on the other hand, <em>do</em> increment counters.



<h3 id="lists">Lists</h3>

<p>CSS&nbsp;2 offers basic visual formatting of lists. An element with
'display: list-item' generates a <a href="#principal-box">principal block box</a> for the element's
content and, depending on the values of 'list-style-type' and
'list-style-image', possibly also a marker box as a visual indication
that the
element is a list item.

<p>The <dfn>list
properties</dfn> describe basic visual formatting of lists:
they allow style sheets to specify the marker type (image, glyph, or
number), and the marker position with respect to the principal box
(outside it or within it before content). They do not allow authors to
specify distinct style (colors, fonts, alignment, etc.) for the list
marker or adjust its position with respect to the principal box; these
may be derived from the principal box.

<p>The <a href="#background-properties">background
properties</a> apply to the principal box only; an ''outside'' marker
box is transparent.


<h4 id="list-style">Lists: the 'list-style-type', 'list-style-image', 'list-style-position', and
'list-style' properties</h4>


<xmp class="propdef">
Name: list-style-type
Value: disc | circle | square | decimal | decimal-leading-zero | lower-roman | upper-roman | lower-greek | lower-latin | upper-latin | armenian | georgian | lower-alpha | upper-alpha | none | inherit
Initial: disc
Applies to: elements with 'display: list-item'
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p> This property specifies appearance of the list item marker if
'list-style-image' has
the value ''list-style-image/none'' or if the image pointed to by the URI cannot be
displayed. The value <dfn dfn-type="value" dfn-for="list-style-type">none</dfn> specifies no marker, otherwise there are
three types of marker: glyphs, numbering systems, and alphabetic
systems.

<p>Glyphs are specified with
<dfn class="value-def" id="value-def-disc" dfn-type="value" dfn-for="list-style-type">disc</dfn>,
<dfn class="value-def" id="value-def-circle" dfn-type="value" dfn-for="list-style-type">circle</dfn>, and
<dfn class="value-def" id="value-def-square" dfn-type="value" dfn-for="list-style-type">square</dfn>. Their exact
rendering depends on the user agent.

<p>Numbering systems are specified with:</p>

<dl>

<dt><dfn class="value-def" id="value-def-decimal" dfn-type="value" dfn-for="list-style-type">decimal</dfn><dd>Decimal numbers, beginning with 1.

<dt><dfn class="value-def" id="value-def-decimal-leading-zero" dfn-type="value" dfn-for="list-style-type">decimal-leading-zero</dfn>
<dd>Decimal numbers padded by initial zeros (e.g., 01, 02, 03, ..., 98, 99).

<!-- should this be included -->

<dt><dfn class="value-def" id="value-def-lower-roman" dfn-type="value" dfn-for="list-style-type">lower-roman</dfn>
<dd>Lowercase roman numerals (i, ii, iii, iv, v, etc.).

<dt><dfn class="value-def" id="value-def-upper-roman" dfn-type="value" dfn-for="list-style-type">upper-roman</dfn>
<dd>Uppercase roman numerals (I, II, III, IV, V, etc.).

<dt><dfn class="value-def" id="value-def-georgian" dfn-type="value" dfn-for="list-style-type">georgian</dfn>
<dd>Traditional Georgian numbering
(an, ban, gan, ..., he, tan, in, in-an, ...).
<dt><dfn class="value-def" id="value-def-armenian" dfn-type="value" dfn-for="list-style-type">armenian</dfn>
<dd>Traditional uppercase Armenian numbering.
</dl>


<p>Alphabetic systems are specified with:</p>

<dl>
<dt><dfn class="value-def" id="value-def-lower-latin" dfn-type="value" dfn-for="list-style-type">lower-latin</dfn> or <dfn class="value-def" id="velue-def-lower-alpha" dfn-type="value" dfn-for="list-style-type">lower-alpha</dfn>
<dd>Lowercase ascii letters (a, b, c, ... z).
<dt><dfn class="value-def" id="value-def-upper-latin" dfn-type="value" dfn-for="list-style-type">upper-latin</dfn> or <dfn class="value-def" id="value-def-upper-alpha" dfn-type="value" dfn-for="list-style-type">upper-alpha</dfn>
<dd>Uppercase ascii letters (A, B, C, ... Z).
<dt><dfn class="value-def" id="value-def-lower-greek" dfn-type="value" dfn-for="list-style-type">lower-greek</dfn>
<dd>Lowercase classical Greek
alpha, beta, gamma, ... (&alpha;, &beta;, &gamma;, ...)
</dl>

<p>This specification does not define how alphabetic systems wrap at
the end of the alphabet. For instance, after 26 list items,
''list-style-type/lower-latin'' rendering is undefined. Therefore, for long lists, we
recommend that authors specify true numbers.

<p>CSS&nbsp;2 does not define how the list numbering is reset and
incremented. This is expected to be defined in the CSS List Module
[[CSS3LIST]].

<div class="lang-html example"><p>
For example, the following HTML document:

<pre>
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
   &lt;HEAD&gt;
     &lt;TITLE&gt;Lowercase latin numbering&lt;/TITLE&gt;
     &lt;STYLE type="text/css"&gt;
          ol { list-style-type: lower-roman }
     &lt;/STYLE&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
    &lt;OL&gt;
      &lt;LI&gt; This is the first item.
      &lt;LI&gt; This is the second item.
      &lt;LI&gt; This is the third item.
    &lt;/OL&gt;
  &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>

<p>might produce something like this:

<pre>
  i This is the first item.
 ii This is the second item.
iii This is the third item.
</pre>

<p>The list marker alignment (here, right justified) depends on the user agent.

</div>


<xmp class="propdef">
Name: list-style-image
Value: <<uri>> | none | inherit
Initial: none
Applies to: elements with 'display: list-item'
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: absolute URI or ''list-style-image/none''
Animation type: discrete
</xmp>



<p> This property sets the image that will be used as the list item
marker. When the image is available, it will replace the marker set
with the 'list-style-type' marker.

<p>The size of the image is calculated from the following rules:
<ol>
<li>If the image has a intrinsic width and height, the used width and
height are the intrinsic width and height.

<li>Otherwise, if the image has an intrinsic ratio and either an
intrinsic width or an intrinsic height, the used width/height is the
same as the provided intrinsic width/height, and the used value of the
missing dimension is calculated from the provided dimension and the
ratio.

<li>Otherwise, if the image has an intrinsic ratio, the used width is
1em and the used height is calculated from this width and the
intrinsic ratio. If this would produce a height larger than 1em, then
the used height is instead set to 1em and the used width is calculated
from this height and the intrinsic ratio.

<li>Otherwise, the image's used width is its intrinsic width if it has
one, or else 1em. The image's used height is its intrinsic height if
it has one, or else 1em.
</ol>

<div class="example"><p>
The following example sets the marker at the beginning of each list
item to be the image "ellipse.png".


<pre class="lang-css">
ul { list-style-image: url("http://png.com/ellipse.png") }
</pre>
</div>

<xmp class="propdef">
Name: list-style-position
Value: inside | outside | inherit
Initial: outside
Applies to: elements with 'display: list-item'
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p> This property specifies the position of the marker box with
respect to the
principal block box. Values have the following meanings:</p>

<dl>
<dt><dfn class="css" dfn-for="list-style-position" dfn-type="value" id="valdef-list-style-position-outside">outside</dfn>

<dd>The marker box is outside the principal block box. <!--86-->The
position of the list-item marker adjacent to floats is undefined in
CSS&nbsp;2.<!--/86--> CSS&nbsp;2 does not specify the precise
location of the marker box <!--191-->or its position in the painting
order<!--/191-->, but does
require that for list items whose 'direction' property is ''direction/ltr'' the
marker box be on the left side of the content and for elements whose
'direction' property is ''direction/rtl'' the marker box be on the right side of
the content.

The marker box is fixed with respect to the principal block box's
border and does not scroll with the principal block box's content.

<!--telcon 2010-11-24-->In CSS&nbsp;2, a UA may hide the marker if
the element's 'overflow' is other
than ''overflow/visible''. (This is expected to change in the future.)<!--/telcon
2010-11-24-->

The size or contents of the marker box may affect the height of the
principal block box and/or the height of its first line box, and in
some cases may cause the creation of a new line box. <span class="note"><strong>Note:</strong> This interaction may be more
precisely defined in a future level of CSS.</span>

<dt><dfn class="css" dfn-for="list-style-position" dfn-type="value" id="valdef-list-style-position-inside">inside</dfn>

<dd>The marker box is placed as the first inline box in the principal
block box, before the element's content and before any :before
pseudo-elements. CSS&nbsp;2 does not specify
the precise location of the marker box.

</dl>

<div class="lang-html example"><p>
For example:

<pre>
&lt;HTML&gt;
  &lt;HEAD&gt;
    &lt;TITLE&gt;Comparison of inside/outside position&lt;/TITLE&gt;
    &lt;STYLE type="text/css"&gt;
      ul         { list-style: outside }
      ul.compact { list-style: inside }
    &lt;/STYLE&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
    &lt;UL&gt;
      &lt;LI&gt;first list item comes first
      &lt;LI&gt;second list item comes second
    &lt;/UL&gt;

    &lt;UL class="compact"&gt;
      &lt;LI&gt;first list item comes first
      &lt;LI&gt;second list item comes second
    &lt;/UL&gt;
  &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>

<p> The above example may be formatted as:</p>

<div class="figure">
<p><img src="./images/list-inout.png" alt="Difference between inside and outside list style position" id="img-list-inout"></p>
</div>

<p>In right-to-left text, the markers would have been on the right
side of the box.
</div>

<xmp class="propdef shorthand">
Name: list-style
Value: [ <<'list-style-type'>> || <<'list-style-position'>> || <<'list-style-image'>> ] | inherit
Initial: see individual properties
Applies to: elements with 'display: list-item'
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: see individual properties
</xmp>



<p> The 'list-style' property
is a shorthand notation for setting the three properties 'list-style-type', 'list-style-image', and 'list-style-position' at
the same place in the style sheet.

<div class="example"><p>

<pre class="lang-css">
ul { list-style: upper-roman inside }  /* Any "ul" element */
ul &gt; li &gt; ul { list-style: circle outside } /* Any "ul" child
                                             of an "li" child
                                             of a "ul" element */
</pre>
</div>

<p>Although authors may specify 'list-style' information directly
on list item elements (e.g., "li" in HTML), they should do so with
care. The following rules look similar, but the first declares a <a href="#descendant-selectors">descendant selector</a>
and the second a (more specific) <a href="#child-selectors">child
selector.</a>

<pre class="example lang-css">
ol.alpha li   { list-style: lower-alpha } /* Any "li" descendant of an "ol" */
ol.alpha &gt; li { list-style: lower-alpha } /* Any "li" child of an "ol" */
</pre>

<p>Authors who use only the <a href="#descendant-selectors">descendant selector</a> may
not achieve the results they expect. Consider the following rules:

<pre class="lang-html example">
&lt;HTML&gt;
  &lt;HEAD&gt;
    &lt;TITLE&gt;WARNING: Unexpected results due to cascade&lt;/TITLE&gt;
    &lt;STYLE type="text/css"&gt;
      ol.alpha li  { list-style: lower-alpha }
      ul li        { list-style: disc }
    &lt;/STYLE&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
    &lt;OL class="alpha"&gt;
      &lt;LI&gt;level 1
      &lt;UL&gt;
         &lt;LI&gt;level 2
      &lt;/UL&gt;
    &lt;/OL&gt;
  &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>

<p>The desired rendering would have level 1 list items with
''list-style-type/lower-alpha'' labels and level 2 items with ''list-style-type/disc'' labels. However,
the <a href="#cascading-order">cascading order</a> will
cause the first style rule (which includes specific class information)
to mask the second. The following rules solve the problem by employing
a <a href="#child-selectors">child
selector</a> instead:

<pre class="example lang-css">
ol.alpha &gt; li  { list-style: lower-alpha }
ul li   { list-style: disc }
</pre>

<p>Another solution would be to specify 'list-style' information only on
the list type elements:

<pre class="example lang-css">
ol.alpha  { list-style: lower-alpha }
ul        { list-style: disc }
</pre>

<p>Inheritance will transfer the 'list-style' values from OL and
UL elements to LI elements. This is the recommended way to
specify list style information.

<div class="example">
<p>A URI value may be combined with any other value, as in:

<pre class="lang-css">
ul { list-style: url("http://png.com/ellipse.png") disc }
</pre>
<p> In the example above, the ''list-style-type/disc'' will be used when the image is
unavailable.
</div>

<p>A value of ''list-style/none'' within the 'list-style' property sets
whichever of 'list-style-type' and 'list-style-image' are not
otherwise specified to <css>none</css>. However, if both are otherwise
specified, the declaration is in error (and thus ignored).

<div class="example">
<p>For example, a value of ''list-style/none'' for the 'list-style' property sets both
'list-style-type' and
'list-style-image' to
<css>none</css>:

<pre class="lang-css">
ul { list-style: none }
</pre>

<p>The result is that no list-item marker is displayed.

</div>





<h2 id="the-page">Paged media</h2>

<h3 id="page-intro">Introduction to paged media</h3>

<p>Paged media (e.g., paper, transparencies, pages that are displayed
on computer screens, etc.) differ from <a href="#continuous-media-group">continuous media</a> in
that the content of the document is split into one or more discrete
pages. To handle pages, CSS&nbsp;2 describes how page margins are set
on <a href="#page-box">page boxes</a>, and how <a href="#page-breaks">page breaks</a> are declared.

<p>The user agent is responsible for transferring the page boxes of a
document onto the real <dfn>sheets</dfn> where the document will
ultimately be rendered (paper, transparency, screen, etc.). There is
often a 1-to-1 relationship between a page box and a sheet, but this
is not always the case. Transfer possibilities include:</p>

<ul>
<li>Transferring one page box to one sheet (e.g., single-sided printing).
<li>Transferring two page boxes to both sides of the same sheet (e.g.,
double-sided printing).
<li>Transferring N (small) page boxes to one sheet (called "n-up").
<li>Transferring one (large) page box to N x M sheets (called "tiling").
<li>Creating signatures. A signature is a group of pages
printed on a sheet, which, when folded and trimmed like a book, appear in their
proper sequence.
<li>Printing one document to several output trays.
<li>Outputting to a file.
</ul>


<h3 id="page-box">Page boxes: the @page rule</h3>

<p>The <dfn>page
box</dfn> is a rectangular region that contains two areas:</p>

<ul>

<li>The <dfn id="page-area">page area</dfn>. The page area
includes the boxes laid out on that page. The edges of the first page
area establish the rectangle that is the initial <a href="#containing-block-details">containing block</a> of
the document.
The canvas background is painted within and covers the page area.


<li>The margin area, which surrounds the page area.
The page margin area is transparent.
</ul>

<p>The size of a page box cannot be specified in CSS&nbsp;2.

<p>Authors can specify the margins of a page box inside an <dfn>@page</dfn> rule. An @page rule
consists of the keyword "@page", followed by an optional page
selector, followed by a block containing declarations and
at-rules. Comments and white space are allowed, but optional, between
the @page token and the page selector and between the page selector
and the block. The declarations in an
@page rule are said to be in the <dfn data-lt="page-context|page context" id="page-context">page
context</dfn>.</p>

<p class="note">Note: CSS level&nbsp;2 has no at-rules that may appear
inside @page, but such at-rules are expected to be defined in
level&nbsp;3.

<p>The <dfn>page
selector</dfn> specifies for which pages the declarations
apply. In CSS&nbsp;2, page selectors may designate the first page,
all left pages, or all right pages</p>

<p>The rules for handling malformed declarations, malformed
statements, and invalid at-rules inside @page are as defined in <a href="#parsing-errors">section&nbsp;4.2,</a> with the
following addition: when the UA expects the start of a declaration or
at-rule (i.e., an IDENT token or an ATKEYWORD token) but finds an
unexpected token instead, that token is considered to be the first
token of a malformed declaration. I.e., the rule for malformed
declarations, rather than malformed statements is used to determine
which tokens to ignore in that case.

<h4 id="page-margins">Page margins</h4>

<p>In CSS&nbsp;2, only the <a href="#margin-properties">margin
properties</a> ('margin-top',
'margin-right', 'margin-bottom', 'margin-left', and 'margin') apply within the <a href="#page-context">page context</a>. The following diagram shows the
relationships between the sheet, page box, and page margins:</p>

<div class="figure">
<p><img src="./images/page-info.png" alt="Illustration of sheet, page box, margin, and page area." id="img-page-info"></p>
</div>

<div class="example"><p>
Here is a simple example which sets all page margins on all pages:

<pre class="lang-css">
@page {
  margin: 3cm;
}
</pre>
</div>

<p>The <a href="#page-context">page context</a> has no notion of
fonts, so ''em'' and ''ex'' units are not allowed. Percentage values on
the margin properties are relative to the dimensions of the <a href="#page-box">page box</a>; for left and right margins, they refer
to the width of the page box while for top and bottom margins, they
refer to the height of the page box. All other units associated with
the respective CSS&nbsp;2 properties are allowed.

<p>Due to negative margin values (either on the page box or on
elements) or <a href="#absolute-positioning">absolute
positioning</a> content may end up outside the page box, but this
content may be "cut" &mdash; by the user agent, the printer, or ultimately,
the paper cutter.




<!--
<h4><span id="oversized-page-box">[This section intentionally left blank]</span></h4>


<h4><span id="positioning-page-box">[This section intentionally left blank]</span></h4>
-->


<h4 id="page-selectors">Page selectors: selecting left, right, and first pages</h4>

<p>When printing double-sided documents, the <a href="#page-box">page
boxes</a> on left and right pages may be different. This can be
expressed through two CSS pseudo-classes that may be used in page selectors.

<p>All pages are automatically classified by user agents into either
the <dfn>:left</dfn> or <dfn>:right</dfn>
pseudo-class.
Whether the first page of a document is :left or :right depends on the
major writing direction of the root element. For example, the first
page of a document with a left-to-right major writing direction would
be a :right page, and the first page of a document with a
right-to-left major writing direction would be a :left page. To
explicitly force a document to begin printing on a left or right page,
authors can <a href="#page-break-props">insert a page break</a> before
the first generated box.

<div class="example"><p>
<pre class="lang-css">
@page :left {
  margin-left: 4cm;
  margin-right: 3cm;
}

@page :right {
  margin-left: 3cm;
  margin-right: 4cm;
}
</pre>
</div>

<p>If different declarations have been given for left and right pages,
the user agent must honor these declarations even if the user agent
does not transfer the page boxes to left and right sheets (e.g., a
printer that only prints single-sided).

<p>Authors may also specify style for the first page of a document
with the <dfn>:first</dfn> pseudo-class:

<div class="example"><p>
<pre class="lang-css">
@page { margin: 2cm } /* All margins set to 2cm */

@page :first {
  margin-top: 10cm    /* Top margin on first page 10cm */
}
</pre>
</div>

<p>Properties specified in a :left or :right @page rule override
those specified in an @page rule that has no pseudo-class specified.
Properties specified in a :first @page rule override those specified
in :left or :right @page rules.

<p>If a <a href="#forced">forced break</a> occurs before the first
generated box, it is undefined in CSS&nbsp;2 whether '':first''
applies to the blank page before the break or to the page after it.

<p>Margin declarations on left, right, and first pages may result in
different <a href="#page-area">page area</a> widths. To simplify
implementations, user agents may use a single page area width
on left, right, and first pages. In this case, the page area width
of the first page should be used.


<h4 id="outside-page-box"> Content outside the page box</h4>

<p>When formatting content in the page model, some content may end up
outside the current page box. For example, an element whose 'white-space' property has the
value ''pre'' may generate a box that is wider than the page box. As
another example, when boxes are positioned absolutely or relatively,
they may end up in "inconvenient" locations. For example, images may
be placed on the edge of the page box or 100,000 meters below the page
box.

<p>The exact formatting of such elements lies outside the scope of
this specification. However, we recommend that authors and user agents
observe the following general principles concerning content outside
the page box:</p>

<ul>

<li>Content should be allowed slightly beyond the page box to allow
pages to "bleed".

<li>User agents should avoid generating a large number of empty page
boxes to honor the positioning of elements (e.g., you do not want to
print 100 blank pages).

<li>Authors should not position elements in inconvenient locations
just to avoid rendering them.

<li>User agents may handle boxes positioned outside the page box in
several ways, including discarding them or creating page boxes for
them at the end of the document.
</ul>

<h3 id="page-breaks">Page breaks</h3>

<p>This section describes page breaks in CSS&nbsp;2. Five
properties indicate where the user agent may or should break pages,
and on what page (left or right) the subsequent content should resume.
Each page break ends layout in the current <a href="#page-box">page
box</a> and causes remaining pieces of the <a href="#doctree">document tree</a> to be laid out in a new
page box.

<h4 id="page-break-props">Page break properties: 'page-break-before',
'page-break-after',
'page-break-inside'
</h4>

<xmp class="propdef">
Name: page-break-before
Value: auto | always | avoid | left | right | inherit
Initial: auto
Applies to: block-level elements (but see text)
Inherited: no
Percentages: N/A
Media: visual, paged
Computed Value: as specified
Animation type: discrete
</xmp>



<xmp class="propdef">
Name: page-break-after
Value: auto | always | avoid | left | right | inherit
Initial: auto
Applies to: block-level elements (but see text)
Inherited: no
Percentages: N/A
Media: visual, paged
Computed Value: as specified
Animation type: discrete
</xmp>



<xmp class="propdef">
Name: page-break-inside
Value: avoid | auto | inherit
Initial: auto
Applies to: block-level elements (but see text)
Inherited: no
Percentages: N/A
Media: visual, paged
Computed Value: as specified
Animation type: discrete
</xmp>



<p>Values for these properties have the following meanings:</p>

<dl>
<dt><dfn class="css" dfn-for="page-break-before,page-break-after,page-break-inside" dfn-type="value" id="valdef-page-break-auto">auto</dfn></dt>
<dd>Neither force nor forbid a page break before (after, inside) the
generated box.
<dt><dfn class="css" dfn-for="page-break-before,page-break-after,page-break-inside" dfn-type="value" id="valdef-page-break-always">always</dfn></dt>
<dd>Always force a page break before (after) the
generated box.</dd>
<dt><dfn class="css" dfn-for="page-break-before,page-break-after,page-break-inside" dfn-type="value" id="valdef-page-break-avoid">avoid</dfn></dt>
<dd>Avoid a page break before (after, inside) the generated box.
<dt><dfn class="css" dfn-for="page-break-before,page-break-after,page-break-inside" dfn-type="value" id="valdef-page-break-left">left</dfn></dt>
<dd>
Force one or two page breaks before
(after) the generated box
so that the next page is formatted as a left page.</dd>
<dt><dfn class="css" dfn-for="page-break-before,page-break-after,page-break-inside" dfn-type="value" id="valdef-page-break-right">right</dfn></dt>
<dd>
Force one or two page breaks before (after) the generated
box so that the next page is formatted as a right page.</dd>
</dl>

<p>A conforming user agent
may interpret the values 'left' and 'right' as ''always''.

<p>A potential page break location is typically under the influence
of the parent element's 'page-break-inside'
property, the 'page-break-after' property
of the preceding element, and the 'page-break-before' property
of the following element.  When these properties have values other
than ''page-break-before/auto'', the values ''always'', 'left', and 'right' take precedence
over ''avoid''.

<p>User agents must apply these properties to block-level elements
in the normal flow of the root element. User agents may also apply
these properties to other elements, e.g., ''display/table-row'' elements.

<p>When a page break splits a box, the box's margins, borders, and
padding have no visual effect where the split occurs.


<h4 id="break-inside">Breaks inside elements: 'orphans', 'widows'</h4>

<xmp class="propdef">
Name: orphans
Value: <<integer>> | inherit
Initial: 2
Applies to: block container elements
Inherited: yes
Percentages: N/A
Media: visual, paged
Computed Value: as specified
Animation type: by computed value type
</xmp>



<xmp class="propdef">
Name: widows
Value: <<integer>> | inherit
Initial: 2
Applies to: block container elements
Inherited: yes
Percentages: N/A
Media: visual, paged
Computed Value: as specified
Animation type: by computed value type
</xmp>



<p>The 'orphans' property
specifies the minimum number of lines in a block container that must be left
at the bottom of a page. The 'widows' property specifies the minimum
number of lines in a block container that must be left at the top of a page.
Examples of how they are used to control page breaks are given below.

<p>Only positive values are allowed.

<p>For information about paragraph formatting, please consult the
section on <a href="#line-box">line boxes</a>.

<h4 id="allowed-page-breaks">Allowed page breaks</h4>

<p>In the normal flow, page breaks can occur at the following places:</p>

<ol>
<li>
In the vertical margin between block-level boxes. When an unforced page
break occurs here, the <a href="#used-value">used
values</a> of the relevant 'margin-top' and 'margin-bottom' properties are
set to ''0''. When a forced page break occurs here, the used value of
the relevant 'margin-bottom' property is set
to ''0''; the relevant 'margin-top' used value may either
be set to ''0'' or retained.

<li>Between <a href="#line-box">line boxes</a>
inside a <a href="#block-boxes">block container</a> box.

<li>Between the content edge of a block container box and the outer edges of its
child content (margin edges of block-level children or line box edges
for inline-level children) if there is a (non-zero) gap between them.
</ol>

<p class="note">Note: It is expected that CSS3 will specify that the
relevant 'margin-top' applies (i.e., is not set to ''0'') after a forced
page break.

<!-- What about line boxes next to a float? -IJ -->

<p>These breaks are subject to the following rules:

<ul>
<li><strong>Rule A:</strong> Breaking at (1) is allowed only if the 'page-break-after' and 'page-break-before' properties of all
the elements generating boxes that
meet at this margin allow it, which is when at least
one of them has the value ''always'', 'left', or 'right', or when all of them are
<css>auto</css>.

<li><strong>Rule B:</strong> However, if all of them are <css>auto</css> and
a common ancestor of all the elements has a 'page-break-inside' value of
''avoid'', then breaking here is not allowed.

<li>
<strong>Rule C:</strong> Breaking at (2) is allowed only if the number of <a href="#line-box">line boxes</a> between the
break and the start of the enclosing block box is
the value of 'orphans' or more, and the number of
line boxes between the break and the end of the box is
the value of 'widows' or more.

<li><strong>Rule D:</strong> In addition, breaking at (2) or (3) is
allowed only if the 'page-break-inside' property
of the element and all its ancestors is ''page-break-inside/auto''.
</ul>

<p>If the above does not provide enough break points to keep content
from overflowing the page boxes, then rules A, B and D are dropped in
order to find additional breakpoints.

<p>If that still does not lead to sufficient break points, rule
C is dropped as well, to find still more break points.


<h4 id="forced">Forced page breaks</h4>

<p>A page break <em>must</em> occur at (1) if, among the 'page-break-after' and 'page-break-before'
properties of all the elements generating boxes that meet at this
margin, there is at least one with the value ''always'', 'left', or
'right'.

<h4 id="best-page-breaks">"Best" page breaks</h4>

<p>CSS&nbsp;2 does <em>not</em> define which of a set of allowed page breaks
must be used; CSS&nbsp;2 does not forbid a user agent from breaking at every
possible break point, or not to break at all. But CSS&nbsp;2 does recommend
that user agents observe the following heuristics (while recognizing
that they are sometimes contradictory):</p>

<ul>
<li>Break as few times as possible.
<li>Make all pages that do not end with a forced break appear to have about
the same height.
<li>Avoid breaking inside a replaced element.
</ul>

<div class="example"><p>
Suppose, for example, that the style sheet
contains 'orphans: 4', 'widows: 2', and
there are 20 lines (<a href="#line-box">line boxes</a>)
available at the bottom of the current page:</p>

<ul>

<li>If a paragraph at the end of the current page contains 20 lines or fewer,
it should be placed on the current page.

<li>If the paragraph contains 21 or 22 lines, the second part of the
paragraph must not violate the 'widows' constraint, and so the
second part must contain exactly two lines

<li>If the paragraph contains 23 lines or more, the first part should
contain 20 lines and the second part the remaining lines.

</ul>

<p>Now suppose that 'orphans' is
''10'',
'widows' is ''20'',
and there are 8 lines available at the bottom of the current page:</p>

<ul>

<li>If a paragraph at the end of the current page contains 8 lines or
fewer, it should be placed on the current page.

<li>If the paragraph contains 9 lines or more, it cannot be split
(that would violate the orphan constraint), so it should move
as a block to the next page.
</ul>
</div>

<h3 id="page-cascade">Cascading in the page context</h3>

<p>Declarations in the <a href="#page-context">page context</a> obey
the <a href="#assigning">cascade</a> just like normal CSS
declarations.

<div class="example"><p>
Consider the following example:

<pre class="lang-css">
@page {
  margin-left: 3cm;
}

@page :left {
  margin-left: 4cm;
}
</pre>

<p>Due to the <a href="#cascading-order">higher
specificity</a> of the pseudo-class selector, the left margin on left
pages will be ''4cm'' and all other pages (i.e., the right pages) will
have a left margin of ''3cm''.
</div>




<h2 id="color-bg"><span id="q14.0">Colors and Backgrounds</span></h2>

<p>CSS properties allow authors to specify the foreground color and
background of an element. Backgrounds may be colors or
images. Background properties allow authors to position a background image,
repeat it, and declare whether it should be fixed with respect
to the <a href="#viewport">viewport</a> or scrolled
along with the document.
</p>
<p> See the section on <a href="#color-units">color units</a>
for the syntax of valid color values.
</p>
<h3 id="colors">Foreground color: the 'color' property</h3>

<xmp class="propdef">
Name: color
Value: <<color>> | inherit
Initial: depends on user agent
Applies to: *
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: by computed value type
</xmp>



<p> This property describes the foreground color of an element's text
content. There are different ways to specify red:
</p>
<div class="example">
<pre class="lang-css">
em { color: red }              /* predefined color name */
em { color: rgb(255,0,0) }     /* RGB range 0-255   */
</pre>
</div>

<h3 id="background">The background</h3>

<p>Authors may specify the background of an element (i.e., its
rendering surface) as either a color or an image.  In terms of the <a href="#box-model">box model</a>, "background" refers to
the background of the <a href="#box-content-area">content</a>, <a href="#box-padding-area">padding</a> and <a href="#box-border-area">border</a> areas. Border colors
and styles are set with the <a href="#border-properties">border properties</a>.  Margins
are always transparent.
</p>
<p>Background properties are not inherited, but the parent box's
background will shine through by default because of the initial
''transparent'' value on 'background-color'.
</p>
<p>
The background of the root element becomes the background of the canvas and
covers the entire <a href="#canvas">canvas</a>, anchored (for
'background-position') at
the same point as it would be if it was painted only for the root element
itself. The root element does not paint this background again.
</p>

<p>For HTML documents, however, we recommend that authors specify the
background for the BODY element rather than the HTML element.
For documents whose root element is an HTML "HTML" element or an XHTML
"html" element that has computed values of ''background-color/transparent'' for 'background-color' and ''background-image/none''
for 'background-image',
user agents must instead use the computed value of the background properties
from that element's first HTML "BODY" element or XHTML "body" element
child when painting backgrounds for the canvas, and must not paint a
background for that child element. Such backgrounds must also be
anchored at the same point as they would be if they were painted only
for the root element.
</p>
<div class="lang-html example"><p>
According to these rules, the canvas underlying the following
HTML document will have a "marble" background:
</p>
<pre>
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
    &lt;TITLE&gt;Setting the canvas background&lt;/TITLE&gt;
    &lt;STYLE type="text/css"&gt;
       BODY { background: url("http://example.com/marble.png") }
    &lt;/STYLE&gt;
    &lt;P&gt;My background is marble.
</pre>
<p>
Note that the rule for the BODY element will work even though the BODY tag has been omitted in the HTML source since the HTML parser will infer the missing tag.
</p>
</div>

<p>
Backgrounds of elements that form a stacking context (see the
'z-index' property) are painted at the bottom of the element's
stacking context, below anything in that stacking context.
</p>

<h4 id="background-properties">Background properties: 'background-color', 'background-image', 'background-repeat', 'background-attachment',
'background-position', and
'background'
</h4>

<xmp class="propdef">
Name: background-color
Value: <<color>> | transparent | inherit
Initial: transparent
Applies to: *
Inherited: no
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: by computed value type
</xmp>



<p>This property sets the background color of an element, either a
<a data-lt="&lt;color&gt;"><span class="value-inst-color">&lt;color&gt;</span></a> value or the keyword
''transparent'', to make the underlying colors shine through.
</p>
<div class="example">
<pre class="lang-css">
h1 { background-color: #F00 }
</pre>
</div>


<xmp class="propdef">
Name: background-image
Value: <<uri>> | none | inherit
Initial: none
Applies to: *
Inherited: no
Percentages: N/A
Media: visual
Computed Value: absolute URI or none
Animation type: discrete
</xmp>



<p> This property sets the background image of an element. When
setting a background image, authors should also specify a background
color that will be used when the image is unavailable. When the image
is available, it is rendered on top of the background color.  (Thus,
the color is visible in the transparent parts of the image).
</p>
<p dfn-type="value" dfn-for="background-image">
Values for this property are either <dfn><<uri>></dfn>, to specify the
image, or <dfn>none</dfn>, when no image is used.
</p>

<div class="example">
<pre class="lang-css">
body { background-image: url("marble.png") }
p { background-image: none }
</pre>
</div>

<p>Intrinsic dimensions expressed as percentages must be resolved
relative to the dimensions of the rectangle that establishes the
coordinate system for the 'background-position'
property.
</p>
<p>If the image has one of either an intrinsic width or an intrinsic
height and an intrinsic aspect ratio, then the missing dimension is
calculated from the given dimension and the ratio.
</p>
<p> If the image has one of either an intrinsic width or an intrinsic
height and no intrinsic aspect ratio, then the missing dimension is
assumed to be the size of the rectangle that establishes the
coordinate system for the 'background-position' property.
</p>
<p>If the image has no intrinsic dimensions and has an intrinsic ratio
the dimensions must be assumed to be the largest dimensions at that
ratio such that neither dimension exceeds the dimensions of the
rectangle that establishes the coordinate system for the 'background-position'
property.
</p>
<p>If the image has no intrinsic ratio either, then the dimensions
must be assumed to be the rectangle that establishes the coordinate
system for the 'background-position'
property.
</p>

<xmp class="propdef">
Name: background-repeat
Value: repeat | repeat-x | repeat-y | no-repeat | inherit
Initial: repeat
Applies to: *
Inherited: no
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p>If a background image is specified, this property specifies whether
the image is repeated (tiled), and how.  All tiling covers the <a href="#box-content-area">content</a>, <a href="#box-padding-area">padding</a> and <a href="#box-border-area">border</a> areas of a box.
<p>
The tiling and positioning of the
background-image on inline elements is undefined in this specification.
A future level of CSS may define the tiling and positioning of the
background-image on inline elements.
</p>
<p>Values have the following meanings:</p>

<dl>
<dt><strong>repeat</strong></dt>
<dd>The image is repeated both horizontally and vertically.</dd>
<dt><strong>repeat-x</strong></dt>
<dd>The image is repeated horizontally only.</dd>
<dt><strong>repeat-y</strong></dt>
<dd>The image is repeated vertically only.</dd>
<dt><strong>no-repeat</strong></dt>
<dd>The image is not repeated: only one copy of the image is drawn.</dd>
</dl>

<div class="example">
<pre class="lang-css">
body {
  background: white url("pendant.png");
  background-repeat: repeat-y;
  background-position: center;
}
</pre>
<div class="figure">
<p><img src="images/bg-repeat.png" alt="A centered background image, with copies repeated up and down the padding and content areas." id="img-bg-repeat">
</p>
<p class="caption">One copy of the background image is centered, and
other copies are put above and below it to make a vertical band behind
the element.
</p>
</div>
</div>

<xmp class="propdef">
Name: background-attachment
Value: scroll | fixed | inherit
Initial: scroll
Applies to: *
Inherited: no
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p dfn-type="value" dfn-for="background-attachment">
If a background image is specified, this property specifies
whether it is fixed with regard to the <a href="#viewport">viewport</a> (<dfn>fixed</dfn>) or scrolls along
with the containing block (<dfn>scroll</dfn>).</p>

<p>Note that there is only one viewport per view. If an element has
a scrolling mechanism (see 'overflow'), a ''background-attachment/fixed'' background does not
move with the element, and a ''background-attachment/scroll'' background does not move with
the scrolling mechanism.</p>

<p>Even if the image is fixed, it is still only visible when it is in
the content, padding or border area of the element. Thus, unless
the image is tiled ('background-repeat: repeat'), it may be invisible.
</p>
<p>In paged media, where there is no viewport, a ''background-attachment/fixed'' background is
fixed with respect to the page box and is therefore replicated on
every page.

<div class="example"><p>This example creates an infinite vertical band
that remains "glued" to the viewport when the element is scrolled.
</p>
<pre class="lang-css">
body {
  background: red url("pendant.png");
  background-repeat: repeat-y;
  background-attachment: fixed;
}
</pre>
</div>

<p>
User agents that do not support ''background-attachment/fixed'' backgrounds (for example due
to limitations of the hardware platform) should ignore declarations
with the keyword ''background-attachment/fixed''. For example:
</p>
<pre class="lang-css">
body {
  background: white url(paper.png) scroll; /* for all UAs */
  background: white url(ledger.png) fixed; /* for UAs that do fixed backgrounds */
}
</pre>
<p>
See the section on <a href="#conformance">conformance</a> for details.
</p>

<xmp class="propdef">
Name: background-position
Value: [ [ <<percentage>> | <<length>> | left | center | right ] [ <<percentage>> | <<length>> | top | center | bottom ]? ] | [ [ left | center | right ] || [ top | center | bottom ] ] | inherit
Initial: 0% 0%
Applies to: *
Inherited: no
Percentages: refer to the size of the box itself
Media: visual
Computed Value: for <<length>> the absolute value, otherwise a percentage
Animation type: by computed value type
</xmp>



<p>If a background image has been specified, this property specifies
its initial position. If only one value is specified, the second value
is assumed to be ''background-position/center''. If at least one value is not a keyword,
then the first value represents the horizontal position and the second
represents the vertical position. Negative <<percentage>> and
<<length>> values are allowed.

<!-- '50% left' is not allowed, because 'left' is not a vertical
position. Is that clear from the above? -->

<dl>
  <dt><<percentage>>

  <dd>A percentage X aligns the point X% across (for horizontal) or
  down (for vertical) the image with the point X% across (for
  horizontal) or down (for vertical) the element's padding box. For
  example, with a value pair of '0% 0%',the upper left corner of the
  image is aligned with the upper left corner of the padding box. A
  value pair of '100% 100%' places the lower right corner of the image
  in the lower right corner of the padding box. With a value pair of
  '14% 84%', the point 14% across and 84% down the image is to be
  placed at the point 14% across and 84% down the padding box.

  <dt><<length>>

  <dd>A length L aligns the top left corner of the image a distance L
  to the right of (for horizontal) or below (for vertical) the top
  left corner of the element's padding box. For example, with a value
  pair of '2cm 1cm', the upper left corner of the image is placed 2cm
  to the right and 1cm below the upper left corner of the padding
  box.

  <dt><dfn class="css" dfn-for="background-position" dfn-type="value" id="valdef-background-position-top">top</dfn>

  <dd>Equivalent to ''0%'' for the vertical position.

  <dt><dfn class="css" dfn-for="background-position" dfn-type="value" id="valdef-background-position-right">right</dfn>

  <dd>Equivalent to ''100%'' for the horizontal position.

  <dt><dfn class="css" dfn-for="background-position" dfn-type="value" id="valdef-background-position-bottom">bottom</dfn>

  <dd>Equivalent to ''100%'' for the vertical position.

  <dt><dfn class="css" dfn-for="background-position" dfn-type="value" id="valdef-background-position-left">left</dfn>

  <dd>Equivalent to ''0%'' for the horizontal position.

  <dt><dfn class="css" dfn-for="background-position" dfn-type="value" id="valdef-background-position-center">center</dfn>

  <dd>Equivalent to ''50%'' for the horizontal position if it is not
  otherwise given, or ''50%'' for the vertical position if it is.
</dl>

<p>However, the position is undefined in CSS&nbsp;2 if the image has
an intrinsic ratio, but no intrinsic size.

<div class="example">
<pre class="lang-css">
body { background: url("banner.jpeg") right top }    /* 100%   0% */
body { background: url("banner.jpeg") top center }   /*  50%   0% */
body { background: url("banner.jpeg") center }       /*  50%  50% */
body { background: url("banner.jpeg") bottom }       /*  50% 100% */
</pre>
</div>

<p>
The tiling and positioning of the
background-image on inline elements is undefined in this specification.
A future level of CSS may define the tiling and positioning of the
background-image on inline elements.
</p>
<p> If the background image is fixed within the viewport (see the
'background-attachment'
property), the image is placed relative to the viewport instead of the
element's padding box. For example,
</p>
<div class="example">
<pre class="lang-css">
body {
  background-image: url("logo.png");
  background-attachment: fixed;
  background-position: 100% 100%;
  background-repeat: no-repeat;
}
</pre>

<p> In the example above, the (single) image is placed in the lower-right
corner of the viewport.
</p>
</div>

<xmp class="propdef shorthand">
Name: background
Value: [<<'background-color'>> || <<'background-image'>> || <<'background-repeat'>> || <<'background-attachment'>> || <<'background-position'>>] | inherit
Initial: see individual properties
Applies to: *
Inherited: no
Percentages: allowed on 'background-position'
Media: visual
Computed Value: see individual properties
</xmp>



<p> The 'background' property
is a shorthand property for setting the individual background
properties (i.e., 'background-color', 'background-image', 'background-repeat', 'background-attachment'
and 'background-position') at
the same place in the style sheet.
</p>
<p>Given a valid declaration,
the 'background' property
first sets all the individual background properties to their initial
values, then assigns explicit values given in the declaration.
</p>
<div class="example"><p>
In the first rule of the following example, only a value for 'background-color' has been
given and the other individual properties are set to their initial
value. In the second rule, all individual properties have been
specified.
</p>
<pre class="lang-css">
BODY { background: red }
P { background: url("chess.png") gray 50% repeat fixed }
</pre>
</div>






<h2 id="fonts"><span id="q15.0">Fonts</span></h2>

<h3 id="fonts-intro">Introduction</h3>

<p>Setting font properties will be among the most common uses of style
sheets. Unfortunately, there exists no well-defined and universally
accepted taxonomy for classifying fonts, and terms that apply to one
font family may not be appropriate for others. E.g., ''italic'' is
commonly used to label slanted text, but slanted text may also be
labeled as being <em>Oblique, Slanted, Incline, Cursive</em> or
<em>Kursiv</em>. Therefore it is not a simple problem to map typical
font selection properties to a specific font.
</p>

<h3 id="algorithm">Font matching algorithm</h3>

<p>Because there is no accepted, universal taxonomy of font
properties, matching of properties to font faces must be done
carefully. The properties are matched in a well-defined order to
insure that the results of this matching process are as consistent as
possible across UAs (assuming that the same library of font faces is
presented to each of them).
</p>

<ol>

<li>The user agent makes (or accesses) a database of relevant CSS&nbsp;2
properties of all the fonts of which the UA is aware.
If there are two fonts with exactly the same properties, the user
agent selects one of them.
</li>
<li>At a given element and for each character in that element, the UA
assembles the font properties applicable to that element. Using the
complete set of properties, the UA uses the 'font-family' property to
choose a tentative font family. The remaining properties are tested
against the family according to the matching criteria described with
each property. If there are matches for all the remaining properties,
then that is the matching font face for the given element or character.
</li>
<li>If there is no matching font face within the 'font-family' being
processed by step 2, and if there is a next alternative 'font-family'
in the font set, then repeat step 2 with the next alternative
'font-family'.
</li>
<li>If there is a matching font face, but it does not contain a glyph
for the current character, and if there is a next alternative
'font-family' in the font sets, then repeat step 2 with the next
alternative 'font-family'.
</li>
<li>If there is no font within the family selected in 2, then use a
   UA-dependent default 'font-family' and repeat step 2, using the best
   match that can be obtained within the default font. If a particular
   character cannot be displayed using this font, then the UA may use other
   means to determine a suitable font for that character. The UA should map
   each character for which it has no suitable font to a visible symbol
   chosen by the UA, preferably a "missing character" glyph from one of the
   font faces available to the UA.
</li>
</ol>

<p>(The above algorithm can be optimized to avoid having to revisit
the CSS&nbsp;2 properties for each character.)
</p>
<p>The per-property matching rules from (2) above are as follows:
</p>
<ol>

<li>'font-style' is tried first. ''italic''
will be satisfied if there is either a face in the UA's font database
labeled with the CSS keyword ''italic'' (preferred) or ''oblique''.
Otherwise the values must be matched exactly or font-style will fail.
</li>
<li>'font-variant' is tried next. ''small-caps'' matches (1) a
font labeled as ''small-caps'', (2) a font in which the small caps are
synthesized, or (3) a font where all lowercase letters are replaced by
uppercase letters. A small-caps font may be synthesized by
electronically scaling uppercase letters from a normal font.
''font-variant/normal'' matches a font's normal (non-small-caps) variant. A font cannot fail to have a normal variant. A font
 that is only available as small-caps shall be selectable as either a ''font-variant/normal'' face or a ''small-caps'' face.
</li>
<li>'font-weight' is matched next, it will
never fail. (See 'font-weight' below.)
</li>
<li>'font-size' must be matched within a
UA-dependent margin of tolerance. (Typically, sizes for scalable fonts
are rounded to the nearest whole pixel, while the tolerance for
bitmapped fonts could be as large as 20%.) Further computations, e.g.,
by ''em'' values in other properties, are based on
the computed value of 'font-size'.
</li>

</ol>

<h3 id="font-family-prop">Font family: the 'font-family' property</h3>

<xmp class="propdef">
Name: font-family
Value: [ [ <<family-name>> | <<generic-family>> ] [, <<family-name>> | <<generic-family>>]* ] | inherit
Initial: depends on user agent
Applies to: *
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p>The property value is a prioritized list of font family names
and/or <a href="#generic-font-families">generic family names.</a>
Unlike most other CSS properties, component values are separated
by a comma to indicate that they are alternatives:
</p>
<pre class="lang-css">
body { font-family: Gill, Helvetica, sans-serif }
</pre>

<p>Although many fonts provide the "missing character" glyph,
  typically an open box, as its name implies this should not be
  considered a match
  for characters that cannot be found in the font. (It should,
however, be considered a match for U+FFFD, the "missing character"
character's code point).
</p>
<p>There are two types of font family names:
</p>
<dl>

<dt><dfn id="value-def-family-name" dfn-type="type">&lt;family-name&gt;</dfn>
</dt>
<dd>The name of a font family of choice. In the last example, "Gill"
and "Helvetica" are font families.
</dd>
<dt><dfn id="value-def-generic-family" dfn-type="type">&lt;generic-family&gt;</dfn>
</dt>
<dd>In the example above, the last value is a generic family name. The
following generic families are defined:

<ul>

<li><dfn class="css" dfn-for="&lt;generic-family&gt;" dfn-type="value" id="valdef-generic-family-serif">serif</dfn> (e.g., Times)</li>

<li><dfn class="css" dfn-for="&lt;generic-family&gt;" dfn-type="value" id="valdef-generic-family-sans-serif">sans-serif</dfn> (e.g., Helvetica)</li>

<li><dfn class="css" dfn-for="&lt;generic-family&gt;" dfn-type="value" id="valdef-generic-family-cursive">cursive</dfn> (e.g., Zapf-Chancery)</li>

<li><dfn class="css" dfn-for="&lt;generic-family&gt;" dfn-type="value" id="valdef-generic-family-fantasy">fantasy</dfn> (e.g., Western)</li>

<li><dfn class="css" dfn-for="&lt;generic-family&gt;" dfn-type="value" id="valdef-generic-family-monospace">monospace</dfn> (e.g., Courier)</li>

</ul>

<p>Style sheet designers are encouraged to offer a generic font family
as a last alternative.  Generic font family names are keywords and must NOT be quoted.
</p>
</dd>
</dl>

<p>Font family names must either be given quoted as <a href="#strings">strings,</a> or unquoted as a sequence of
one or more <a href="#value-def-identifier">identifiers.</a> This means
most punctuation characters and digits at the start of each token must
be escaped in unquoted font family names.

<p>For example, the following declarations are invalid:

<pre>
font-family: Red/Black, sans-serif;
font-family: "Lucida" Grande, sans-serif;
font-family: Ahem!, sans-serif;
font-family: test@foo, sans-serif;
font-family: #POUND, sans-serif;
font-family: Hawaii 5-0, sans-serif;
</pre>

<p>If a sequence of identifiers is given as a font family name, the
computed value is the name converted to a string by joining all the
identifiers in the sequence by single spaces.

<p>To avoid mistakes in escaping, it is recommended to quote font
family names that contain white space, digits, or punctuation
characters other than hyphens:

<pre>
body { font-family: "New Century Schoolbook", serif }

&lt;BODY STYLE="font-family: '21st Century', fantasy"&gt;
</pre>

<p>Font family <em>names</em> that happen to be the same as a keyword
value (''inherit'', ''serif'', ''sans-serif'', ''monospace'', ''fantasy'', and
''cursive'') must be quoted to prevent confusion with the keywords with
the same names. The keywords <css>initial</css> and ''default'' are reserved for
future use and must also be quoted when used as font names. UAs must
not consider these keywords as matching the <<family-name>>
type.
</p>


<h4 id="generic-font-families">Generic font families</h4>

<p>Generic font families are a fallback mechanism, a means of
preserving some of the style sheet author's intent in the worst case
when none of the specified fonts can be selected. For optimum
typographic control, particular named fonts should be used in
style sheets.


<p><span id="defined-to-exist">All five generic font families are defined to exist</span> in all
CSS implementations (they need not necessarily map to five distinct
actual fonts). User agents should provide reasonable
default choices for the generic font families, which express the
characteristics of each family as well as possible within the limits
allowed by the underlying technology.

<p>User agents are encouraged to allow users to select alternative
choices for the generic fonts.

<h5><dfn id="serif-def">serif</dfn></h5>

<p>Glyphs of serif fonts, as the term is used in CSS, tend to have finishing
strokes, flared or tapering ends, or have actual serifed endings
(including slab serifs). Serif fonts are typically
proportionately-spaced. They often display a greater variation between
thick and thin strokes than fonts from the ''sans-serif'' generic font
family. CSS uses the term ''serif'' to apply to a font for any script,
although other names may be more familiar for particular scripts, such
as Mincho (Japanese), Sung or Song (Chinese), Totum or Kodig (Korean).
Any font that is so described may be used to represent the
generic ''serif'' family.

<p>Examples of fonts that fit this description include:</p>

<table>
<tr><td>Latin fonts
  <td>Times New Roman, Bodoni,
Garamond, Minion Web, ITC Stone Serif, MS Georgia, Bitstream Cyberbit
<tr><td>Greek fonts
  <td>Bitstream Cyberbit
<tr><td>Cyrillic fonts
  <td>Adobe Minion Cyrillic, Excelsior Cyrillic Upright,
Monotype Albion 70, Bitstream Cyberbit, ER Bukinist
<tr><td>Hebrew fonts
  <td>New Peninim, Raanana, Bitstream Cyberbit
<tr><td>Japanese fonts
  <td>Ryumin Light-KL, Kyokasho ICA, Futo Min A101
<tr><td>Arabic fonts
  <td>Bitstream Cyberbit
<tr><td>Cherokee fonts
  <td>Lo Cicero Cherokee
</table>

<h5><dfn id="sans-serif-def">
sans-serif</dfn></h5>

<p>Glyphs in sans-serif fonts, as the term is used in CSS, tend to have stroke
endings that are plain -- with little or no flaring, cross stroke, or other
ornamentation. Sans-serif fonts are typically
proportionately-spaced. They often have little variation between thick
and thin strokes, compared to fonts from the ''serif'' family. CSS uses
the term ''sans-serif'' to apply to a font for any script, although
other names may be more familiar for particular scripts, such as
Gothic (Japanese), Kai (Chinese), or Pathang (Korean). Any font that
is so described may be used to represent the generic ''sans-serif''
family.

<p>Examples of fonts that fit this description include:</p>

<table>
<tr><td>Latin fonts
  <td>MS Trebuchet, ITC Avant Garde Gothic, MS Arial, MS Verdana, Univers,
Futura, ITC Stone Sans, Gill Sans, Akzidenz Grotesk, Helvetica
<tr><td>Greek fonts
  <td>Attika, Typiko New Era, MS Tahoma, Monotype Gill Sans 571, Helvetica Greek
<tr><td>Cyrillic fonts
  <td>Helvetica Cyrillic, ER Univers, Lucida Sans Unicode, Bastion
<tr><td>Hebrew fonts
  <td>Arial Hebrew, MS Tahoma
<tr><td>Japanese fonts
  <td>Shin Go, Heisei Kaku Gothic W5
<tr><td>Arabic fonts
  <td>MS Tahoma
</table>

<h5><dfn id="cursive-def">
cursive</dfn></h5>

<p>Glyphs in cursive fonts, as the term is used in CSS, generally have
either joining strokes or other cursive characteristics beyond those
of italic typefaces. The glyphs are partially or completely
connected, and the result looks more like handwritten pen or brush
writing than printed letterwork. Fonts for some scripts, such as
Arabic, are almost always cursive. CSS uses the term ''cursive'' to
apply to a font for any script, although other names such as Chancery,
Brush, Swing and Script are also used in font names.

<p>Examples of fonts that fit this description include:</p>

<table>
<tr><td>Latin fonts
  <td>Caflisch Script, Adobe Poetica, Sanvito, Ex Ponto, Snell Roundhand,
Zapf-Chancery
<tr><td>Cyrillic fonts
  <td>ER Architekt
<tr><td>Hebrew fonts
  <td>Corsiva
<tr><td>Arabic fonts
  <td>DecoType Naskh, Monotype Urdu 507
</table>

<h5><dfn id="fantasy-def">
fantasy</dfn></h5>


<p>Fantasy fonts, as used in CSS, are primarily decorative while
still containing representations of characters (as opposed to Pi or
Picture fonts, which do not represent characters). Examples include:</p>

<table>
<tr><td>Latin fonts
  <td>Alpha Geometrique, Critter, Cottonwood, FB Reactor, Studz
</table>


<h5><dfn id="monospace-def">
monospace</dfn></h5>


<p>The sole criterion of a monospace font is that all glyphs have the same fixed width. (This can make some scripts,
such as Arabic, look most peculiar.) The effect is similar to a manual
typewriter, and is often used to set samples of computer code.

<p>Examples of fonts which fit this description include:

<table>
<tr><td>Latin fonts
  <td>Courier, MS Courier New, Prestige, Everson Mono
<tr><td>Greek Fonts
  <td>MS Courier New, Everson Mono
<tr><td>Cyrillic fonts
  <td>ER Kurier, Everson Mono
<tr><td>Japanese fonts
  <td>Osaka Monospaced
<tr><td>Cherokee fonts
  <td>Everson Mono
</table>


<h3 id="font-styling">Font styling: the
'font-style' property</h3>

<xmp class="propdef">
Name: font-style
Value: normal | italic | oblique | inherit
Initial: normal
Applies to: *
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p>The 'font-style' property selects between normal (sometimes
referred to as "roman" or "upright"), italic and oblique faces within
a font family.
</p>
<p>A value of <dfn class="css" dfn-for="font-style" dfn-type="value" id="valdef-font-style-normal">normal</dfn> selects a font that is classified as ''font-style/normal''
in the UA's font database, while <dfn class="css" dfn-for="font-style" dfn-type="value" id="valdef-font-style-oblique">oblique</dfn> selects a font that is
labeled ''oblique''. A value of <dfn class="css" dfn-for="font-style" dfn-type="value" id="valdef-font-style-italic">italic</dfn> selects a font that is labeled
''italic'', or, if that is not available, one labeled ''oblique''.
</p>
<p>The font that is labeled ''oblique'' in the UA's font database may
actually have been generated by electronically slanting a normal font.
</p>
<p>Fonts with Oblique, Slanted or Incline in their names will
typically be labeled ''oblique'' in the UA's font database. Fonts with
<em>Italic, Cursive</em> or <em>Kursiv</em> in their names will
typically be labeled ''italic''.
</p>
<pre class="lang-css">
h1, h2, h3 { font-style: italic }
h1 em { font-style: normal }
</pre>

<p>In the example above, emphasized text within ''H1'' will appear in a
normal face.
</p>
<h3 id="small-caps">Small-caps: the
'font-variant' property</h3>

<xmp class="propdef">
Name: font-variant
Value: normal | small-caps | inherit
Initial: normal
Applies to: *
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p>Another type of variation within a font family is the small-caps.
In a small-caps font the lowercase letters look similar to the
uppercase ones, but in a smaller size and with slightly different
proportions. The 'font-variant' property selects that font.
</p>
<p>A value of <dfn class="css" dfn-for="font-variant" dfn-type="value" id="valdef-font-variant-normal">normal</dfn> selects a font that is not a small-caps font,
<dfn class="css" dfn-for="font-style" dfn-type="value" id="valdef-font-style-small-caps">small-caps</dfn> selects a small-caps font. It is acceptable (but not
required) in CSS&nbsp;2 if the small-caps font is a created by taking a
normal font and replacing the lowercase letters by scaled uppercase
characters. As a last resort, uppercase letters will be used as
replacement for a small-caps font.
</p>
<p>The following example results in an ''H3'' element in small-caps,
with any emphasized words in oblique, and any emphasized words within
an ''H3'' oblique small-caps:
</p>
<pre class="lang-css">
h3 { font-variant: small-caps }
em { font-style: oblique }
</pre>

<p>There may be other variants in the font family as well, such as
fonts with old-style numerals, small-caps numerals, condensed or
expanded letters, etc. CSS&nbsp;2 has no properties that select those.
</p>
<p><em>Note:</em> insofar as this property causes text to be
transformed to uppercase, the same considerations as for 'text-transform' apply.
</p>
<h3 id="font-boldness">Font boldness: the
'font-weight' property</h3>

<xmp class="propdef">
Name: font-weight
Value: normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit
Initial: normal
Applies to: *
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: see text
Animation type: by computed value type
</xmp>



<p>The 'font-weight' property selects the weight of the font. The
values ''100'' to ''900'' form an ordered sequence, where each number
indicates a weight that is at least as dark as its predecessor. The
keyword <dfn class="css" dfn-for="font-weight" dfn-type="value" id="valdef-font-weight-normal">normal</dfn> is synonymous with ''400'', and <dfn class="css" dfn-for="font-weight" dfn-type="value" id="valdef-font-weight-bold">bold</dfn> is synonymous
with ''700''. Keywords other than ''font-weight/normal'' and ''bold'' have been shown to
be often confused with font names and a numerical scale was therefore
chosen for the 9-value list.
</p>
<pre class="lang-css">
p { font-weight: normal }   /* 400 */
h1 { font-weight: 700 }     /* bold */
</pre>

<p>The <dfn class="css" dfn-for="font-weight" dfn-type="value" id="valdef-font-weight-bolder">bolder</dfn> and <dfn class="css" dfn-for="font-weight" dfn-type="value" id="valdef-font-weight-lighter">lighter</dfn> values select font weights that are
relative to the weight inherited from the parent:
</p>
<pre class="lang-css">
strong { font-weight: bolder }
</pre>

<p>Fonts (the font data) typically have one or more properties whose
values are names that are descriptive of the "weight" of a font. There
is no accepted, universal meaning to these weight names. Their primary
role is to distinguish faces of differing darkness within a single
font family. Usage across font families is quite variant; for example,
a font that one might think of as being bold might be described as
being <em>Regular, Roman, Book, Medium, Semi-</em> or <em>DemiBold,
Bold,</em> or <em>Black,</em> depending on how black the "normal" face
of the font is within the design. Because there is no standard usage
of names, the weight property values in CSS&nbsp;2 are given on a numerical
scale in which the value ''400'' (or ''font-weight/normal'') corresponds to the
"normal" text face for that family. The weight name associated with
that face will typically be <em>Book, Regular, Roman, Normal</em> or
sometimes <em>Medium</em>.
</p>

<p>The association of other weights within a family to the numerical
weight values is intended only to preserve the ordering of darkness
within that family. However, the following heuristics tell how the
assignment is done in this case:

<ul>
<li>If the font family already uses a numerical scale with nine values
(like e.g., <em>OpenType</em> does), the font weights should be mapped
directly.

<li>If there is both a face labeled <em>Medium</em> and one labeled
<em>Book, Regular, Roman</em> or <em>Normal,</em> then the
<em>Medium</em> is normally assigned to the ''500''.

<li>The font labeled "Bold" will often correspond to the weight value ''700''.
</ul>

<p>Once the font family's weights are mapped onto the CSS scale,
missing weights are selected as follows:

<ul>
<li>If the desired weight is less than 400, weights below the desired
weight are checked in descending order followed by weights above the
desired weight in ascending order until a match is found.

<li>If the desired weight is greater than 500, weights above desired
weight are checked in ascending order followed by weights below the
desired weight in descending order until a match is found.

<li>If the desired weight is 400, 500 is checked first and then the
rule for desired weights less than 400 is used.

<li>If the desired weight is 500, 400 is checked first and then the
rule for desired weights less than 400 is used.
</ul>

<p>The following two examples show typical mappings.</p>

<div class="lang-html example">
<p>Assume four weights in the "Rattlesnake" family, from lightest to
darkest: <em>Regular, Medium, Bold, Heavy.</em></p>
<table>
<caption>First example of font-weight mapping</caption>
<!-- rattlesnake, ostrich and more at the Austin meeting -->
<thead>
<tr><th>Available faces <th>Assignments <th>Filling the holes</tr>
</thead>
<tr><td>"Rattlesnake Regular"<td> 400     <td> 100, 200, 300</tr>
<tr><td>"Rattlesnake Medium" <td> 500     <td>&nbsp;</tr>
<tr><td>"Rattlesnake Bold"   <td> 700     <td> 600</tr>
<tr><td>"Rattlesnake Heavy"  <td> 800     <td> 900</tr>
</table>
</div>

<div class="lang-html example">
<p>Assume six weights in the
"Ice Prawn" family: <em>Book, Medium, Bold, Heavy, Black,
ExtraBlack.</em> Note that in this instance the user agent
has decided <em>not</em> to assign a numeric
value to "Ice Prawn ExtraBlack".</p>

<table>
<caption>Second example of font-weight mapping</caption>
<thead>
<tr><th>Available faces <th>Assignments <th>Filling the holes</tr>
</thead>
<tr><td>"Ice Prawn Book"  <td> 400     <td> 100, 200, 300</tr>
<tr><td>"Ice Prawn Medium"<td> 500     <td>&nbsp;</tr>
<tr><td>"Ice Prawn Bold"  <td> 700     <td> 600</tr>
<tr><td>"Ice Prawn Heavy" <td> 800     <td>&nbsp;</tr>
<tr><td>"Ice Prawn Black" <td> 900     <td>&nbsp;</tr>
<tr><td>"Ice Prawn ExtraBlack"<td> (none)  <td>&nbsp;</tr>
</table>
</div>

<p>Values of ''bolder'' and ''lighter'' indicate values relative to the
weight of the parent element.  Based on the inherited weight value,
the weight used is calculated using the chart below.  Child elements
inherit the calculated weight, not a value of ''bolder'' or ''lighter''.

<table>
<caption>The meaning of ''bolder'' and ''lighter''</caption>
<thead>
<tr><th>Inherited value   <th>bolder  <th>lighter
<tbody>
<tr><td>100               <td>400     <td>100
<tr><td>200               <td>400     <td>100
<tr><td>300               <td>400     <td>100
<tr><td>400               <td>700     <td>100
<tr><td>500               <td>700     <td>100
<tr><td>600               <td>900     <td>400
<tr><td>700               <td>900     <td>400
<tr><td>800               <td>900     <td>700
<tr><td>900               <td>900     <td>700
</table>

<p>The table above is equivalent to selecting the next relative bolder
or lighter face, given a font family containing normal and bold faces
along with a thin and a heavy face. Authors who desire finer control
over the exact weight values used for a given element should use
numerical values instead of relative weights.

<p>There is no guarantee that there will be a darker face for each of
the 'font-weight' values; for example, some fonts may have only a
normal and a bold face, while others may have eight face weights.
There is no guarantee on how a UA will map font faces within a family
to weight values. The only guarantee is that a face of a given value
will be no less dark than the faces of lighter values.
</p>

<!--
<div id="compute-font-weight">
<p class=note>Note: A set of nested elements that mix 'bolder' and
'lighter' will
give unpredictable results depending on the UA, OS, and font
availability. This behavior will be more precisely defined in CSS3.

<p>
  CSS&nbsp;2 does not specify how the computed value of font-weight is
  represented internally or externally.
</p>
</div>
-->

<h3 id="font-size-props">Font size: the 'font-size'
property</h3>

<xmp class="propdef">
Name: font-size
Value: <<absolute-size>> | <<relative-size>> | <<length>> | <<percentage>> | inherit
Initial: medium
Applies to: *
Inherited: yes
Percentages: refer to inherited font size
Media: visual
Computed Value: absolute length
Animation type: by computed value type
</xmp>



<p>The font size corresponds to the em square, a concept used in typography.
Note that certain glyphs may bleed outside their em squares. Values
have the following meanings:</p>

<dl>
<dt><b><dfn id="value-def-absolute-size" dfn-type="type">&lt;absolute-size&gt;</dfn></b>
</dt>
<dd>An &lt;absolute-size&gt; keyword is an index to a table of font
sizes computed and kept by the UA. Possible values are:
<p> [ <dfn class="css" dfn-for="font-size" dfn-type="value" id="valdef-font-size-xx-small">xx-small</dfn> | <dfn class="css" dfn-for="font-size" dfn-type="value" id="valdef-font-size-x-small">x-small</dfn> | <dfn class="css" dfn-for="font-size" dfn-type="value" id="valdef-font-size-small">small</dfn> | <dfn class="css" dfn-for="font-size" dfn-type="value" id="valdef-font-size-medium">medium</dfn> | <dfn class="css" dfn-for="font-size" dfn-type="value" id="valdef-font-size-large">large</dfn> | <dfn class="css" dfn-for="font-size" dfn-type="value" id="valdef-font-size-x-large">x-large</dfn> | <dfn class="css" dfn-for="font-size" dfn-type="value" id="valdef-font-size-xx-large">xx-large</dfn> ]</p>
<p>The following table provides user agent guidelines for the absolute-size
 mapping to HTML heading and absolute font-sizes. The ''font-size/medium'' value is
 the user's preferred font size and is used as the reference middle value.</p>

<table style="table-layout: fixed; width: 100%" id="AutoNumber2">
  <tr>
    <th style="width: 15em">CSS absolute-size values</th>
    <td>xx-small</td>
    <td>x-small</td>
    <td>small</td>
    <td>medium</td>
    <td>large</td>
    <td>x-large</td>
    <td>xx-large</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <th>HTML font sizes</th>
    <td>1</td>
    <td>&nbsp;</td>
    <td>2</td>
    <td>3</td>
    <td>4</td>
    <td>5</td>
    <td>6</td>
    <td>7</td>
  </tr>
</table>

<p>Implementors should build a table of scaling factors for absolute-size keywords relative to the ''<absolute-size>/medium'' font size and the particular device and its characteristics (e.g., the resolution of the device).
</p>

<p>
Different media may need different scaling factors. Also, the UA
should take the quality and availability of fonts into account when
computing the table. The table may be different from one font family
to another.
</p>

<p class="note"><em><strong>Note 1.</strong> To preserve readability, a UA applying
these guidelines should nevertheless avoid creating font-size resulting
 in less than 9 pixels per EM unit on a computer display.</em></p>

<p class="note"><em><strong>Note 2.</strong> In CSS1, the suggested
scaling factor between adjacent indexes was 1.5, which user experience
proved to be too large. In CSS2&nbsp;(1998), the suggested scaling factor for a
computer screen between adjacent indexes was 1.2, which still created
issues for the small sizes. Implementation experience has demonstrated
that a fixed ratio between adjacent absolute-size keywords is
problematic, and this specification does <em>not</em> recommend such a
fixed ratio.</em></p>

</dd>
<dt><b><dfn id="value-def-relative-size" dfn-type="type">&lt;relative-size&gt;</dfn></b>
</dt>
<dd>A &lt;relative-size&gt; keyword is interpreted relative to the
table of font sizes and the font size of the parent element. Possible
values are: [ larger | smaller ]. For example, if the parent element
has a font size of ''<absolute-size>/medium'', a value of ''larger'' will make the font
size of the current element be ''large''. If the parent element's size
is not close to a table entry, the UA is free to interpolate between
table entries or round off to the closest one. The UA may have to
extrapolate table values if the numerical value goes beyond the
keywords.
</dd>
</dl>

<p>Length and percentage values should not take the font size table
into account when calculating the font size of the element.
</p>
<p>Negative values are not allowed.
</p>
<p>On all other properties, ''em'' and ''ex'' length values refer to the
computed font size of the current element. On the 'font-size' property, these
length units refer to the computed font size of the parent element.
</p>
<p>Note that an application may reinterpret an explicit size,
depending on the context. E.g., inside a VR scene a font may get a
different size because of perspective distortion.
</p>
<p>Examples:
</p>
<pre class="lang-css">
p { font-size: 16px; }
@media print {
  p { font-size: 12pt; }
}
blockquote { font-size: larger }
em { font-size: 150% }
em { font-size: 1.5em }
</pre>

<h3 id="font-shorthand">Shorthand font property: the 'font' property</h3>

<xmp class="propdef shorthand">
Name: font
Value: [ [ <<'font-style'>> || <<'font-variant'>> || <<'font-weight'>> ]? <<'font-size'>> [ / <<'line-height'>> ]? <<'font-family'>> ] | caption | icon | menu | message-box | small-caption | status-bar | inherit
Initial: see individual properties
Applies to: *
Inherited: yes
Percentages: see individual properties
Media: visual
Computed Value: see individual properties
</xmp>



<p>
The 'font' property is,
except as described <a href="#almost">below</a>, a shorthand property for
setting
'font-style',
'font-variant',
'font-weight',
'font-size',
'line-height' and
'font-family' at the same
place in the style
sheet. The syntax of this property is based on a traditional
typographical shorthand notation to set multiple properties related to
fonts.
</p>
<p>All font-related properties are first reset to their initial values,
including those listed in the preceding paragraph.
Then, those properties that are given explicit values in the
'font' shorthand are set to those values.
For a definition of allowed and initial values, see the previously defined properties.
</p>
<pre class="lang-css">
p { font: 12px/14px sans-serif }
p { font: 80% sans-serif }
p { font: x-large/110% "New Century Schoolbook", serif }
p { font: bold italic large Palatino, serif }
p { font: normal small-caps 120%/120% fantasy }
</pre>

<p>In the second rule, the font size percentage value (''80%'') refers
to the font size of the parent element. In the third rule, the line
height percentage refers to the font size of the element itself.
</p>
<p>In the first three rules above, the 'font-style', 'font-variant'
and 'font-weight' are not explicitly mentioned, which means they are
all three set to their initial value (<css>normal</css>). The fourth rule sets
the 'font-weight' to ''bold'', the 'font-style' to ''italic'' and
implicitly sets 'font-variant' to ''font-variant/normal''.
</p>
<p>The fifth rule sets the 'font-variant' (''small-caps''), the
'font-size' (120% of the parent's font), the 'line-height' (120% times
the font size) and the 'font-family' (''fantasy''). It follows that the
keyword <css>normal</css> applies to the two remaining properties: 'font-style'
and 'font-weight'.
</p>
<p>The following values refer to <dfn>system fonts</dfn>:</p>

<dl>
<dt><dfn class="css" dfn-for="font" dfn-type="value" id="valdef-font-caption">caption</dfn></dt>
<dd>The font used for captioned controls (e.g., buttons, drop-downs, etc.).</dd>
<dt><dfn class="css" dfn-for="font" dfn-type="value" id="valdef-font-icon">icon</dfn></dt>
<dd>The font used to label icons.</dd>
<dt><dfn class="css" dfn-for="font" dfn-type="value" id="valdef-font-menu">menu</dfn></dt>
<dd>The font used in menus (e.g., dropdown menus and menu lists).</dd>
<dt><dfn class="css" dfn-for="font" dfn-type="value" id="valdef-font-message-box">message-box</dfn></dt>
<dd>The font used in dialog boxes.</dd>
<dt><dfn class="css" dfn-for="font" dfn-type="value" id="valdef-font-small-caption">small-caption</dfn></dt>
<dd>The font used for labeling small controls.</dd>
<dt><dfn class="css" dfn-for="font" dfn-type="value" id="valdef-font-status-bar">status-bar</dfn></dt>
<dd>The font used in window status bars.</dd>
</dl>

<p>System fonts may only be set as a whole; that is, the font
family, size, weight, style, etc. are all set at the same time.
These values may then be altered individually if desired.  If no
font with the indicated characteristics exists on a given platform,
the user agent should either intelligently substitute (e.g., a smaller
version of the ''caption'' font might be used for the ''small-caption''
font), or substitute a user agent default font. As for regular fonts,
if, for a system font, any of the individual properties are not part
of the operating system's available user preferences, those properties
should be set to their initial values.
</p>
<p id="almost">That is why this property is "almost" a shorthand property: system
fonts can only be specified with this property, not with 'font-family' itself, so 'font' allows authors to do more than the
sum of its subproperties. However, the individual properties such as 'font-weight' are still given values taken from the system font, which can be independently varied.</p>

<div class="example">
<pre class="lang-css">
button { font: 300 italic 1.3em/1.7em "FB Armada", sans-serif }
button p { font: menu }
button p em { font-weight: bolder }
</pre>

<p>If the font used for dropdown menus on a particular system
happened to be, for example, 9-point Charcoal, with a weight of 600, then P
elements that were descendants of BUTTON would be displayed as if
this rule were in effect:
</p>
<pre class="lang-css">
button p { font: 600 9px Charcoal }
</pre>

<p>Because the 'font' shorthand
property resets any property not explicitly given a value
to its initial value, this has the same effect as this declaration:
</p>
<pre class="lang-css">
button p {
  font-family: Charcoal;
  font-style: normal;
  font-variant: normal;
  font-weight: 600;
  font-size: 9px;
  line-height: normal;
}
</pre>

</div>





<h2 id="text"><span id="q16.0">Text</span></h2>

<p>The properties defined in the following sections affect the visual
presentation of characters, spaces, words, and paragraphs.
</p>

<h3 id="indentation-prop">Indentation: the 'text-indent' property</h3>

<xmp class="propdef">
Name: text-indent
Value: <<length>> | <<percentage>> | inherit
Initial: 0
Applies to: block containers
Inherited: yes
Percentages: refer to width of containing block
Media: visual
Computed Value: the percentage as specified or the absolute length
Animation type: by computed value type
</xmp>



<p>This property specifies the indentation of the first line of text
in a block container. More precisely, it specifies the indentation of the
first box that flows into the block's first <a href="#line-box">line box</a>.  The box is indented with
respect to the left (or right, for right-to-left layout) edge of the
line box. User agents must render this indentation as blank space.
</p>

<p>'text-indent' only affects a line if it is the <a href="#first-line-pseudo">first formatted line</a> of an
element. For example, the first line of an anonymous block box is only
affected if it is the first child of its parent element.

<p>Values have the following meanings:</p>

<dl>
<dt><<length>></dt>
<dd>The indentation is a fixed length.</dd>
<dt><<percentage>>
</dt>
<dd>The indentation is a percentage of the containing
block width.</dd>
</dl>

<p>The value of 'text-indent' may be negative, but
there may be implementation-specific limits.
If the value of 'text-indent' is either negative or
exceeds the width of the block, that <em>first box</em>, described above,
can overflow the block.
The value of 'overflow' will affect
whether such text that overflows the block is visible.
</p>


<div class="example"><p>
The following example causes a ''3em'' text indent.
</p>
<pre class="lang-css">
p { text-indent: 3em }
</pre>
</div>

<p class="note">
Note: Since the 'text-indent' property inherits, when specified on
a block element, it will affect descendant inline-block elements.
For this reason, it is often wise to specify '<code>text-indent: 0</code>'
on elements that are specified '<code>display:inline-block</code>'.
</p>

<h3 id="alignment-prop">Alignment: the 'text-align' property</h3>

<xmp class="propdef">
Name: text-align
Value: left | right | center | justify | inherit
Initial: a nameless value that acts as 'left' if 'direction' is ''direction/ltr'',
  'right' if 'direction' is ''direction/rtl''
Applies to: block containers
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: the initial value or as specified
Animation type: discrete
</xmp>



<p>This property describes how inline-level content of a block
container is aligned. Values
have the following meanings:</p>

<dl>
<dt><dfn class="css" dfn-for="text-align" dfn-type="value" id="valdef-text-align-left">left</dfn>, <dfn class="css" dfn-for="text-align" dfn-type="value" id="valdef-text-align-right">right</dfn>, <dfn class="css" dfn-for="text-align" dfn-type="value" id="valdef-text-align-center">center</dfn>, <dfn class="css" dfn-for="text-align" dfn-type="value" id="valdef-text-align-justify">justify</dfn></dt>
<dd>Left, right, center, and justify text, respectively, as described in <a href="#inline-formatting">the section on inline formatting</a>.</dd>
</dl>

<p>A block of text is a stack of <a href="#line-box">line
boxes</a>.  In the case of ''text-align/left'', ''text-align/right'' and ''text-align/center'', this property specifies
how the inline-level boxes within each line box align with respect to the line
box's left and right sides; alignment is not with respect to the <a href="#viewport">viewport</a>.  In the case of ''justify'',
this property specifies that the inline-level boxes are to be made flush
with both sides of the line box if possible, by expanding or contracting
the contents of inline boxes, else aligned as for the initial
value. (See also 'letter-spacing' and 'word-spacing'.)
</p>
<p>
If an element has a computed value for 'white-space' of ''pre'' or
''pre-wrap'', then neither the glyphs of that element's text content nor
its white space may be altered for the purpose of justification.
</p>
<!-- issue http://wiki.csswg.org/spec/css2.1#issue-53 -->
<p class="note">Note: CSS may add a way to justify text with
'white-space: pre-wrap' in the future.

<div class="example"><p>
In this example, note that since 'text-align' is inherited, all
block-level elements inside DIV elements with a class name of ''important'' will
have their inline content centered.
</p>
<pre class="lang-css">
div.important { text-align: center }
</pre>
</div>

<div class="note"><p>
<em><strong>Note.</strong>
The actual justification algorithm used depends on the user-agent and the language/script
of the text.</em>
</p>
</div>
<p><em><a data-lt="conformance" href="#conformance">Conforming user agents</a> may
interpret the value ''justify'' as 'left' or 'right', depending on
whether the element's default writing direction is left-to-right or
right-to-left, respectively.</em>
</p>

<h3 id="decoration">Decoration</h3>

<h4 id="lining-striking-props">Underlining, overlining, striking, and
blinking: the 'text-decoration'
property</h4>

<xmp class="propdef">
Name: text-decoration
Value: none | [ underline || overline || line-through || blink ] | inherit
Initial: none
Applies to: *
Inherited: no (see prose)
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p>
This property describes decorations that are added
to the text of an element using the element's color.
When specified on or propagated to an inline element, it
affects all the boxes generated by that element, and is further
propagated to any in-flow block-level boxes that split the inline (see
<a href="#anonymous-block-level">section&nbsp;9.2.1.1</a>).
But, in CSS&nbsp;2, it is undefined whether the decoration
propagates into block-level tables.
For block containers that establish an
<a href="#inline-formatting">inline formatting
context,</a> the decorations are propagated to an anonymous inline
element that wraps all the in-flow inline-level children of the block
container. For all other elements it is propagated to any in-flow
children. Note that text decorations are not propagated to floating
and absolutely positioned descendants, nor to the contents of atomic
inline-level descendants such as inline blocks and inline tables.
<p>
Underlines, overlines, and line-throughs are applied only to text
(including white space, letter spacing, and word spacing): margins,
borders, and padding are skipped.
User agents must not render these text decorations on content that is
not text. For example, images and inline blocks must not be underlined.

<div class="note">
<p><em><strong>Note.</strong> If an element E has both 'visibility:
hidden' and 'text-decoration: underline', the underline is invisible
(although any decoration of E's parent <strong>is</strong> visible.)
However, CSS&nbsp;2 does not specify if the underline is visible or
invisible in E's children:</em>
<pre class="lang-html example">
&lt;span style="visibility: hidden; text-decoration: underline"&gt;
 &lt;span style="visibility: visible"&gt;
  underlined or not?
 &lt;/span&gt;
&lt;/span&gt;
</pre>
<p><em>This is expected to be specified in level&nbsp;3 of CSS.</em>
</div>

<p>
The 'text-decoration' property on descendant elements cannot have any
effect on the decoration of the ancestor. In determining the position
of and thickness of text decoration lines, user agents may consider the
font sizes of and dominant baselines of descendants, but must use the
same baseline and thickness on each line. Relatively positioning a
descendant moves all text decorations affecting it along with the
descendant's text; it does not affect calculation of the decoration's
initial position on that line.
</p>

<p>Values have the following meanings:</p>

<dl>
<dt><dfn class="css" dfn-for="text-decoration" dfn-type="value" id="valdef-text-decoration-none">none</dfn></dt>
<dd>Produces no text decoration.</dd>
<dt><dfn class="css" dfn-for="text-decoration" dfn-type="value" id="valdef-text-decoration-underline">underline</dfn></dt>
<dd>Each line of text is underlined.</dd>
<dt><dfn class="css" dfn-for="text-decoration" dfn-type="value" id="valdef-text-decoration-overline">overline</dfn></dt>
<dd>Each line of text has a line above it.</dd>
<dt><dfn class="css" dfn-for="text-decoration" dfn-type="value" id="valdef-text-decoration-line-through">line-through</dfn></dt>
<dd>Each line of text has a line through the middle.</dd>
<dt><dfn class="css" dfn-for="text-decoration" dfn-type="value" id="valdef-text-decoration-blink">blink</dfn></dt>
<dd>Text blinks (alternates between visible and invisible).
<a href="#conformance">Conforming user agents</a>
may simply not blink the text. Note that not blinking the text
is one technique to satisfy
<a href="https://www.w3.org/TR/UAAG/guidelines.html#tech-on-off-blinking-text">checkpoint 3.3 of WAI-UAAG</a>.</dd>
</dl>
<p>
The color(s) required for the text decoration must be derived from
the 'color' property value of the element on which 'text-decoration'
is set. The color of decorations must remain the same even if
descendant elements have different 'color' values.
</p>
<p>
Some user agents have implemented text-decoration by
propagating the decoration to the descendant elements as opposed to
preserving a constant thickness and line position as described
above. This was arguably allowed by the looser wording in CSS2&nbsp;(1998). SVG1,
CSS1-only, and CSS2&nbsp;(1998)-only user agents may implement the older model
and still claim conformance to this part of CSS&nbsp;2. (This does not
apply to UAs developed after this specification was released.)
</p>

<div class="example"><p>
In the following example for HTML, the text content of all
A elements acting as hyperlinks (whether visited or not) will be underlined:</p>

<pre class="lang-css">
a:visited,a:link { text-decoration: underline }
</pre>
</div>

<div class="example"><p>
In the following style sheet and document fragment:
</p>
<pre class="lang-css">
   blockquote { text-decoration: underline; color: blue; }
   em { display: block; }
   cite { color: fuchsia; }
</pre>
<pre class="lang-html">
   &lt;blockquote&gt;
    &lt;p&gt;
     &lt;span&gt;
      Help, help!
      &lt;em&gt; I am under a hat! &lt;/em&gt;
      &lt;cite&gt; &mdash;GwieF &lt;/cite&gt;
     &lt;/span&gt;
    &lt;/p&gt;
   &lt;/blockquote&gt;
</pre>
<p>
...the underlining for the blockquote element is propagated to an
anonymous inline element that surrounds the span element, causing
the text "Help, help!" to be blue, with the blue underlining from
the anonymous inline underneath it, the color being taken from the
blockquote element. The <code class="lang-xml">&lt;em&gt;text&lt;/em&gt;</code>
in the em block is also underlined,
as it is in an in-flow block to which the underline is propagated. The final line of text is fuchsia, but the underline
underneath it is still the blue underline from the anonymous inline
element.
</p>
<p><img src="images/underline-example.png" alt="Sample rendering of the above underline example" id="img-underline-example">
</p>
<p>
This diagram shows the boxes involved in the example above. The rounded
aqua line represents the anonymous inline element wrapping the inline
contents of the paragraph element, the rounded blue line represents
the span element, and the orange lines represent the blocks.
</p>
</div>

<h3 id="spacing-props">Letter and word spacing: the 'letter-spacing' and 'word-spacing' properties</h3>

<xmp class="propdef">
Name: letter-spacing
Value: normal | <<length>> | inherit
Initial: normal
Applies to: *
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: ''normal'' or absolute length
Animation type: by computed value type
</xmp>



<p>This property specifies spacing behavior between
text characters. Values have the following meanings:</p>

<dl>
<dt><dfn class="css" dfn-for="letter-spacing" dfn-type="value" id="valdef-letter-spacing-normal">normal</dfn></dt>
<dd>The spacing is the normal spacing for the current font.
This value allows the user agent to alter the space
between characters in order to justify text.</dd>
<dt><<length>></dt>
<dd>This value indicates inter-character space <em>in
addition to</em> the default space between
characters.  Values may be negative, but there may be
implementation-specific limits.
User agents may not further increase or decrease the inter-character
space in order to justify text.</dd>
</dl>

<p>Character spacing algorithms are user agent-dependent.
</p>
<div class="example"><p>
In this example, the space between characters in
BLOCKQUOTE elements is increased by ''0.1em''.
</p>
<pre class="lang-css">
blockquote { letter-spacing: 0.1em }
</pre>

<p>In the following example, the user agent is not permitted
to alter inter-character space:</p>

<pre class="lang-css">
blockquote { letter-spacing: 0cm }   /* Same as '0' */
</pre>
</div>

<p> When the resultant space between two characters is not the same as
the default space, user agents should not use
ligatures.
</p>

<xmp class="propdef">
Name: word-spacing
Value: normal | <<length>> | inherit
Initial: normal
Applies to: *
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: for ''normal'' the value ''0''; otherwise the absolute length
Animation type: by computed value type
</xmp>



<p>This property specifies spacing behavior between words.
Values have the following meanings:</p>

<dl>
<dt><dfn class="css" dfn-for="word-spacing" dfn-type="value" id="valdef-word-spacing-normal">normal</dfn></dt>
<dd>The normal inter-word space, as defined by the current font and/or
the <abbr title="user agent">UA</abbr>.</dd>
<dt><<length>></dt>
<dd>This value indicates inter-word space <em>in
addition to</em> the default space between
words.  Values may be negative, but there may be
implementation-specific limits. </dd>
</dl>

<p>Word spacing algorithms are user agent-dependent.  Word spacing is
also influenced by justification (see the 'text-align' property).
Word spacing affects each space (U+0020) and non-breaking space
(U+00A0), left in the text after the white space processing rules have
been applied. The effect of the property on other word-separator
characters is undefined. However general punctuation, characters with
zero advance width (such as the zero with space U+200B) and
fixed-width spaces (such as U+3000 and U+2000 through U+200A) are not
affected.

<div class="example"><p>
In this example, the word-spacing between each word in H1 elements is
increased by ''1em''.
</p>
<pre class="lang-css">
h1 { word-spacing: 1em }
</pre>
</div>

<h3 id="caps-prop">Capitalization: the 'text-transform' property</h3>

<xmp class="propdef">
Name: text-transform
Value: capitalize | uppercase | lowercase | none | inherit
Initial: none
Applies to: *
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p>This property controls capitalization effects of
an element's text. Values have the following meanings:</p>

<dl>
  <dt><dfn class="css" dfn-for="text-transform" dfn-type="value" id="valdef-text-transform-capitalize">capitalize</dfn></dt>
  <dd>Puts the first character of each word in uppercase; other characters are unaffected.</dd>
  <dt><dfn class="css" dfn-for="text-transform" dfn-type="value" id="valdef-text-transform-uppercase">uppercase</dfn></dt>
  <dd>Puts all characters of each word in uppercase.</dd>
  <dt><dfn class="css" dfn-for="text-transform" dfn-type="value" id="valdef-text-transform-lowercase">lowercase</dfn></dt>
  <dd>Puts all characters of each word in lowercase.</dd>
  <dt><dfn class="css" dfn-for="text-transform" dfn-type="value" id="valdef-text-transform-none">none</dfn></dt>
  <dd>No capitalization effects.</dd>
</dl>

<p> The actual transformation in each case is written language
dependent. See BCP&nbsp;47 ([[BCP47]]) for ways to find the language of
an element.
</p>
<p>Only characters belonging to "bicameral scripts" [[!UNICODE]] are
affected.
</p>
<div class="example"><p>
In this example, all text in an H1 element is transformed to uppercase
text.
</p>
<pre class="lang-css">
h1 { text-transform: uppercase }
</pre>
</div>

<h3 id="white-space-prop">White space: the 'white-space' property</h3>

<xmp class="propdef">
Name: white-space
Value: normal | pre | nowrap | pre-wrap | pre-line | inherit
Initial: normal
Applies to: *
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p> This property declares how white space inside the element is
handled. Values have the following meanings:</p>


<!-- See the HTML definition of white space -IJ -->
<dl>
<dt><dfn class="css" dfn-for="white-space" dfn-type="value" id="valdef-white-space-normal">normal</dfn></dt>
<dd>This value directs user agents to collapse sequences
of white space, and break lines as necessary to fill line boxes.</dd>
<dt><dfn class="css" dfn-for="white-space" dfn-type="value" id="valdef-white-space-pre">pre</dfn></dt>
<dd>This value prevents user agents from collapsing sequences
of white space. Lines are only broken at preserved newline characters.</dd>
<dt><dfn class="css" dfn-for="white-space" dfn-type="value" id="valdef-white-space-nowrap">nowrap</dfn></dt>
<dd>This value collapses white space as for ''white-space/normal'', but suppresses
line breaks within text.</dd>
<dt><dfn class="css" dfn-for="white-space" dfn-type="value" id="valdef-white-space-pre-wrap">pre-wrap</dfn></dt>
<dd>This value prevents user agents from collapsing sequences
of white space. Lines are broken at preserved newline characters,
and as necessary to fill line boxes.</dd>
<dt><dfn class="css" dfn-for="white-space" dfn-type="value" id="valdef-white-space-pre-line">pre-line</dfn></dt>
<dd>This value directs user agents to collapse sequences of white
space. Lines are broken at preserved newline characters, and as
necessary to fill line boxes.</dd>
</dl>
<p>
Newlines in the source can be represented by a carriage return
(U+000D), a linefeed (U+000A) or both (U+000D U+000A) or by some other
mechanism that identifies the beginning and end of document segments,
such as the SGML RECORD-START and RECORD-END tokens. The CSS
'white-space' processing model assumes all newlines have been
normalized to line feeds.
UAs that recognize other newline representations must apply the white
space processing rules as if this normalization has taken place. If no
newline rules are specified for the document language, each carriage
return (U+000D) and CRLF sequence (U+000D U+000A) in the document text
is treated as single line feed character.
This default normalization rule also applies to generated
content.

<p>UAs must recognize line feeds (U+000A) as newline characters. UAs
may additionally treat other forced break characters as newline
characters per UAX14.

<div class="example"><p> The following examples show what <a href="#whitespace">white space</a> behavior is expected
from the PRE and P elements and the "nowrap" attribute in HTML.
<pre class="lang-css">
pre        { white-space: pre }
p          { white-space: normal }
td[nowrap] { white-space: nowrap }
</pre>
<p>In addition, the effect of an HTML PRE element with the <em>non-standard</em> "wrap" attribute  is demonstrated by the following example:
</p>
<pre class="lang-css">
pre[wrap]  { white-space: pre-wrap }
</pre>
</div>

<h4 id="white-space-model">The 'white-space' processing model</h4>
<p>
For each inline element (including anonymous inline elements), the
following steps are performed, treating bidi formatting characters as if
they were not there:
</p>
<ol>
<li>
Each tab (U+0009), carriage return (U+000D), or space (U+0020)
character surrounding a linefeed (U+000A) character is removed if
'white-space' is set to ''white-space/normal'', ''nowrap'', or ''pre-line''.
     </li>
<li>If 'white-space' is set to ''pre'' or ''pre-wrap'', any sequence of
     spaces (U+0020) unbroken by an element boundary is treated as a
     sequence of non-breaking spaces. However, for ''pre-wrap'', a line breaking
     opportunity exists at the end of the sequence.
     </li>
<li>If 'white-space' is set to ''white-space/normal'' or ''nowrap'', linefeed
     characters are transformed for rendering purpose into one of the
     following characters: a space character, a zero width space
     character (U+200B), or no character (i.e., not rendered),
     according to UA-specific algorithms based on the content script.
     </li>
<li>If 'white-space' is set to ''white-space/normal'', ''nowrap'', or ''pre-line'',
 <ol><li> every tab (U+0009) is converted to a space (U+0020)</li>
     <li> any space (U+0020) following another space (U+0020) &mdash; even
          a space before the inline, if that space also has
          'white-space' set to ''white-space/normal'', ''nowrap'' or ''pre-line'' &mdash; is removed.</li>
 </ol>
 </li>
</ol>
<p>
Then, the block container's inlines are laid out. Inlines are laid
out, taking bidi
reordering into account, and wrapping as specified by the
'white-space' property.
When wrapping, line breaking opportunities are determined based
on the text prior to the white space collapsing steps above.
</p>
<p>
As each line is laid out,
</p>
<ol>
<li>If a space (U+0020) at the beginning of a line has 'white-space'
     set to ''white-space/normal'', ''nowrap'', or ''pre-line'', it is removed.
     </li>
<li>All tabs (U+0009) are rendered as a horizontal shift that lines
     up the start edge of the next glyph with the next tab stop. Tab
     stops occur at points that are multiples of 8 times the width of
     a space (U+0020) rendered in the block's font from the block's
     starting content edge.
     </li>
<li>If a space (U+0020) at the end of a line has 'white-space' set to
     ''white-space/normal'', ''nowrap'', or ''pre-line'', it is also removed.
     </li>
<li>If spaces (U+0020) or tabs (U+0009) at the end of a line have
     'white-space' set to ''pre-wrap'', UAs may visually collapse them.
</ol>

<p>Floated and absolutely-positioned elements do not introduce a line
breaking opportunity.

<div class="note"><p>
<em><strong>Note.</strong>
CSS&nbsp;2 does not fully define where line breaking opportunities occur.</em>
</div>

<h4 id="egbidiwscollapse">Example of bidirectionality with white space collapsing</h4>
<p>
Given the following markup fragment, taking special note of spaces (with varied backgrounds and borders for emphasis and identification):
</p>
<pre class="lang-xml"><code>

     &lt;ltr&gt;A<span class="egbidiwsaA">&nbsp;</span>&lt;rtl&gt;<span class="egbidiwsbB">&nbsp;</span>B<span class="egbidiwsaB">&nbsp;</span>&lt;/rtl&gt;<span class="egbidiwsbC">&nbsp;</span>C&lt;/ltr&gt;

</code></pre>
<p>
...where the <code>&lt;ltr&gt;</code> element represents a left-to-right embedding and
the <code>&lt;rtl&gt;</code> element represents a right-to-left embedding, and
assuming that the 'white-space' property is set to ''white-space/normal'', the
above processing model would result in the following:
</p>
<ul style="line-height:1.3">
<li>The space before the B (<span class="egbidiwsbB">&nbsp;</span>) would collapse with the space after the A (<span class="egbidiwsaA">&nbsp;</span>).</li>
<li>The space before the C (<span class="egbidiwsbC">&nbsp;</span>) would collapse with the space after the B (<span class="egbidiwsaB">&nbsp;</span>).</li>
</ul>
<p>
This would leave two spaces, one after the A in the left-to-right
embedding level, and one after the B in the right-to-left embedding
level. This is then rendered according to the Unicode bidirectional
algorithm, with the end result being:
</p>
<pre>
     A<span class="egbidiwsaA">&nbsp;</span><span class="egbidiwsaB">&nbsp;</span>BC

</pre>
<p>
Note that there are two spaces between A and B, and none between B
and C. This can sometimes be avoided by using the natural bidirectionality
of characters instead of explicit embedding levels. Also, it is good
to avoid spaces immediately inside start and end tags, as these tend
to do weird things when dealing with white space collapsing.
</p>

<h4 id="ctrlchars">Control and combining characters' details</h4>

<p>Control characters other than U+0009 (tab), U+000A (line feed),
U+0020 (space), and U+202x (bidi formatting characters) are treated as
characters to render in the same way as any normal character.</p>

<p>Combining characters should be treated as part of the character
with which they are supposed to combine. For example, :first-letter
styles the entire glyph if you have content like
"<code>o&lt;span&gt;&amp;#x308;&lt;/span&gt;</code>"; it does not just
match the base character.</p>





<h2 id="tables"><span id="q17.0">Tables</span></h2>
<h3 id="tables-intro">Introduction to tables</h3>

<p>This chapter defines the processing model for tables in CSS. Part
of this processing model is the layout. For the layout, this chapter
introduces two algorithms; the first, the fixed table layout
algorithm, is well-defined, but the second, the automatic table layout
algorithm, is not fully defined by this specification.

<p>For the automatic table layout algorithm, some widely deployed
implementations have achieved relatively close interoperability.

<p><dfn>Table</dfn> layout can be
used to represent tabular relationships between data. Authors specify
these relationships in the <a href="#doclanguage">document
language</a> and can specify their <em>presentation</em> using
CSS&nbsp;2.

<p>In a visual medium, CSS tables can also be used to achieve specific
layouts. In this case, authors should not use table-related elements
in the document language, but should apply the CSS to the relevant
structural elements to achieve the desired layout.

<p>Authors may specify the visual formatting of a table as a
rectangular grid of cells. Rows and columns of cells may be organized
into row groups and column groups. Rows, columns, row groups, column
groups, and cells may have borders drawn around them (there are two
border models in CSS&nbsp;2). Authors may align data vertically or
horizontally within a cell and align data in all cells of a row or
column.

<div class="example"><p>
Here is a simple three-row, three-column
table described in HTML 4:

<pre class="lang-html example">
&lt;TABLE&gt;
&lt;CAPTION&gt;This is a simple 3x3 table&lt;/CAPTION&gt;
&lt;TR id="row1"&gt;
   &lt;TH&gt;Header 1  &lt;TD&gt;Cell 1  &lt;TD&gt;Cell 2
&lt;TR id="row2"&gt;
   &lt;TH&gt;Header 2  &lt;TD&gt;Cell 3  &lt;TD&gt;Cell 4
&lt;TR id="row3"&gt;
   &lt;TH&gt;Header 3  &lt;TD&gt;Cell 5  &lt;TD&gt;Cell 6
&lt;/TABLE&gt;
</pre>

<p>This code creates one table (the TABLE element), three
rows (the TR elements), three header cells (the TH elements),
and six data cells (the TD elements). Note that the three columns
of this example are specified implicitly: there are as many
columns in the table as required by header and data cells.

<p>The following CSS rule centers the text horizontally in the header
cells and presents the text in the header cells with a bold font
weight:

<pre class="lang-css">
th { text-align: center; font-weight: bold }
</pre>

<p>The next rules align the text of the header cells on their baseline
and vertically center the text in each data cell:

<pre class="lang-css">
th { vertical-align: baseline }
td { vertical-align: middle }
</pre>

<p>The next rules specify that the top row will be surrounded by a 3px
solid blue border and each of the other rows will be surrounded by a
1px solid black border:

<pre class="lang-css">
table   { border-collapse: collapse }
tr#row1 { border: 3px solid blue }
tr#row2 { border: 1px solid black }
tr#row3 { border: 1px solid black }
</pre>

<p>Note, however, that the borders around the rows overlap where the
rows meet. What color (black or blue) and thickness (1px or 3px) will
the border between row1 and row2 be? We discuss this in the section on
<a href="#border-conflict-resolution">border conflict resolution.</a>

<p>The following rule puts the table caption above the table:

<pre class="lang-css">
caption { caption-side: top }
</pre>

</div>

<p>The preceding example shows how CSS works with HTML 4 elements;
in HTML 4, the semantics of the various table elements (TABLE,
CAPTION, THEAD, TBODY, TFOOT, COL, COLGROUP, TH, and TD) are
well-defined. In other document languages (such as XML applications),
there may not be pre-defined table elements. Therefore, CSS&nbsp;2 allows
authors to <a data-lt="map document language elements to table elements">"map"</a> document language elements to table elements via
the 'display' property. For
example, the following rule makes the FOO element act like an HTML
TABLE element and the BAR element act like a CAPTION element:</p>

<pre class="example lang-css">
FOO { display : table }
BAR { display : table-caption }
</pre>

<p id="internal"> We discuss the various table elements in the
following section. In
this specification, the term <dfn>table element</dfn> refers to any element
involved in the creation of a table. An <dfn id="internal-table-element">internal
table element</dfn> is one that produces a row, row group, column,
column group, or cell.

<h3 id="table-display">The CSS table model</h3>

<p>The CSS table model is based on the HTML4 table model, in
which the structure of a table closely parallels the visual layout of
the table. In this model, a table consists of an optional caption and
any number of rows of cells. The table model is said to be "row
primary" since authors specify rows, not columns, explicitly in the
document language. Columns are derived once all the rows have been
specified -- the first cell of each row belongs to the first column,
the second to the second column, etc.). Rows and columns may be
grouped structurally and this grouping reflected in presentation
(e.g., a border may be drawn around a group of rows).

<p>Thus, the table model consists of tables, captions, rows, <dfn>row groups</dfn> (including header groups and footer
groups), columns, column groups, and cells.

<p>The CSS model does not require that the <a href="#doclanguage">document language</a> include elements
that correspond to each of these components.  For document languages
(such as XML applications) that do not have pre-defined table
elements, authors must <dfn>map document language elements to table
elements</dfn>; this is done with the 'display' property. The following
'display' values assign table
formatting rules to an arbitrary element:

<dl>
  <dt>''display/table''
  (In HTML: TABLE) <dd>Specifies that an element defines a <a href="#block-level">block-level</a> table: it is a
  rectangular block that participates in a <a href="#block-formatting">block formatting context</a>.

  <dt>''display/inline-table'' (In
  HTML: TABLE) <dd>Specifies that an element defines an <a href="#inline-level">inline-level</a> table: it is a
  rectangular block that participates in an <a href="#inline-formatting">inline formatting
  context</a>).

  <dt>''display/table-row'' (In HTML:
  TR) <dd>Specifies that an element is a row of cells.

  <dt>''display/table-row-group''
  (In HTML: TBODY) <dd>Specifies that an element groups one or more
  rows.

  <dt>''display/table-header-group''
  (In HTML: THEAD) <dd>Like ''display/table-row-group'', but for visual
  formatting, the row group is always displayed before all other rows
  and row groups and after any top captions. Print user agents may
  repeat header rows on each page spanned by a table. If a table
  contains multiple elements with 'display: table-header-group', only
  the first is rendered as a header; the others are treated as if they
  had 'display: table-row-group'.

  <dt>''display/table-footer-group''
  (In HTML: TFOOT) <dd>Like ''display/table-row-group'', but for visual
  formatting, the row group is always displayed after all other rows
  and row groups and before any bottom captions. Print user agents may
  repeat footer rows on each page spanned by a table. If a table
  contains multiple elements with 'display: table-footer-group', only
  the first is rendered as a footer; the others are treated as if they
  had 'display: table-row-group'.

  <dt>''display/table-column'' (In
  HTML: COL) <dd>Specifies that an element describes a column of
  cells.

  <dt>''display/table-column-group''
  (In HTML: COLGROUP) <dd>Specifies that an element groups one or more
  columns.

  <dt>''display/table-cell'' (In HTML:
  TD, TH) <dd>Specifies that an element represents a table cell.

  <dt>''display/table-caption'' (In
  HTML: CAPTION) <dd>Specifies a caption for the table. All elements
  with 'display: table-caption' must be rendered, as described in
  <a href="#model">section 17.4.</a>
</dl>

<p>Replaced elements with these 'display' values are treated as their
given display types during layout. For example, an image that is set
to 'display: table-cell' will fill the available cell space, and its
dimensions might contribute towards the table sizing algorithms, as
with an ordinary cell.

<p>Elements with 'display' set
to ''display/table-column'' or ''display/table-column-group'' are not rendered (exactly as
if they had 'display: none'), but they are useful, because they may
have attributes which induce a certain style for the columns they
represent.

<p>The <a href="#html-stylesheet">default style sheet for HTML4</a>
in the appendix illustrates the use of these values for HTML4:

<pre class="example lang-css">
table    { display: table }
tr       { display: table-row }
thead    { display: table-header-group }
tbody    { display: table-row-group }
tfoot    { display: table-footer-group }
col      { display: table-column }
colgroup { display: table-column-group }
td, th   { display: table-cell }
caption  { display: table-caption }
</pre>

<p>User agents may <a href="#ignore">ignore</a> these
'display' property values for
HTML table elements, since HTML tables may be rendered using other
algorithms intended for backwards compatible rendering. However, this
is not meant to discourage the use of 'display: table' on other,
non-table elements in HTML.

<h4 id="anonymous-boxes">Anonymous table objects</h4>

<p>Document languages other than HTML may not contain all the elements
in the CSS&nbsp;2 table model. In these cases, the "missing"
elements must be assumed in order for the table model to work. Any
table element will automatically generate necessary anonymous table
objects around itself, consisting of at least three nested objects
corresponding to a ''display/table''/''display/inline-table'' element, a ''display/table-row''
element, and a ''display/table-cell'' element. Missing elements generate <a href="#anonymous">anonymous</a> objects (e.g., anonymous
boxes in visual table layout) according to the following <dfn data-lt="rules on anonymous table objects">rules</dfn>:

<p>For the purposes of these rules, the following terms are defined:
<dl>
  <dt><dfn>row group box</dfn>
    <dd>A ''display/table-row-group'', ''display/table-header-group'', or
    ''display/table-footer-group''

  <dt><dfn>proper table child</dfn>
    <dd>A ''display/table-row'' box, row group box, ''display/table-column'' box,
    ''display/table-column-group'' box, or ''display/table-caption'' box.

  <dt><dfn>proper table row parent</dfn>
    <dd>A ''display/table'' or ''display/inline-table'' box or row group box
  <dt><dfn>internal table box</dfn>
    <dd>A ''display/table-cell'' box, ''display/table-row'' box, row group box,
    ''display/table-column'' box, or ''display/table-column-group'' box.

  <dt><dfn id="tabular-container">tabular container</dfn>
    <dd>A ''display/table-row'' box or proper table row parent
  <dt><dfn>consecutive</dfn>
    <dd>Two sibling boxes are consecutive if they have no intervening
    siblings other than, optionally, an anonymous inline containing
    only white spaces. A sequence of sibling boxes is consecutive if
    each box in the sequence is consecutive to the one before it in
    the sequence.
</dl>
<p>For the purposes of these rules, out-of-flow elements are
represented as inline elements of zero width and height. Their
containing blocks are chosen accordingly.

<p>The following steps are performed in three stages.
<ol>
  <li>Remove irrelevant boxes:
    <ol>
      <li>All child boxes of a ''display/table-column'' parent are treated as if
          they had 'display: none'.

      <li>If a child <var>C</var> of a ''display/table-column-group'' parent is
          not a ''display/table-column'' box, then it is treated as if it had
          'display: none'.

      <li>If a child <var>C</var> of a tabular container <var>P</var>
          is an anonymous inline box that contains only white space,
          and its immediately preceding and following siblings, if
          any, are proper table descendants of <var>P</var> and are
          either ''display/table-caption'' or internal table boxes, then it is
          treated as if it had 'display: none'. A box <var>D</var> is
          a proper table descendant of <var>A</var> if <var>D</var>
          can be a descendant of <var>A</var> without causing the
          generation of any intervening ''display/table'' or ''display/inline-table''
          boxes.

      <li>If a box <var>B</var> is an anonymous inline containing only
          white space, and is between two immediate siblings each of
          which is either an internal table box or a ''display/table-caption''
          box then <var>B</var> is treated as if it had 'display:
          none'.
    </ol>

  <li>Generate missing child wrappers:
    <ol>
      <li>If a child <var>C</var> of a ''display/table'' or ''display/inline-table'' box
          is not a proper table child, then generate an anonymous
          ''display/table-row'' box around <var>C</var> and all consecutive
          siblings of <var>C</var> that are not proper table children.

      <li>If a child <var>C</var> of a row group box is not a
          ''display/table-row'' box, then generate an anonymous ''display/table-row'' box
          around <var>C</var> and all consecutive siblings
          of <var>C</var> that are not ''display/table-row'' boxes.

      <li>If a child <var>C</var> of a ''display/table-row'' box is not a
          ''display/table-cell'', then generate an anonymous ''display/table-cell'' box
          around <var>C</var> and all consecutive siblings
          of <var>C</var> that are not ''display/table-cell'' boxes.
    </ol>

  <li>Generate missing parents:
    <ol>
       <li>For each ''display/table-cell'' box <var>C</var> in a sequence of
           consecutive internal table and ''display/table-caption'' siblings,
           if <var>C</var>'s parent is not a ''display/table-row'' then generate
           an anonymous ''display/table-row'' box around <var>C</var> and all
           consecutive siblings of <var>C</var> that are ''display/table-cell''
           boxes.

       <li>For each proper table child <var>C</var> in a sequence of
           consecutive proper table children, if <var>C</var> is
           misparented then generate an anonymous ''display/table'' or
           ''display/inline-table'' box <var>T</var> around <var>C</var> and all
           consecutive siblings of <var>C</var> that are proper table
           children. (If C's parent is an ''inline'' box,
           then <var>T</var> must be an ''display/inline-table'' box; otherwise
           it must be a ''display/table'' box.)
           <ul>
             <li>A ''display/table-row'' is misparented if its parent is neither
               a row group box nor a ''display/table'' or ''display/inline-table'' box.
             <li>A ''display/table-column'' box is misparented if its parent is
               neither a ''display/table-column-group'' box nor a ''display/table'' or
               ''display/inline-table'' box.
             <li>A row group box, ''display/table-column-group'' box, or
               ''display/table-caption'' box is misparented if its parent is
               neither a ''display/table'' box nor an ''display/inline-table'' box.
           </ul>
    </ol>
</ol>

<div class="example">
<p>In this XML example, a ''display/table'' element is assumed to contain the
HBOX element:

<pre class="lang-xml example">
&lt;HBOX&gt;
  &lt;VBOX&gt;George&lt;/VBOX&gt;
  &lt;VBOX&gt;4287&lt;/VBOX&gt;
  &lt;VBOX&gt;1998&lt;/VBOX&gt;
&lt;/HBOX&gt;
</pre>

<p>because the associated style sheet is:

<pre class="example lang-css">
HBOX { display: table-row }
VBOX { display: table-cell }
</pre>
</div>

<div class="example">
<p>In this example, three ''display/table-cell'' elements are assumed to contain
the text in the ROWs. Note that the text is further encapsulated in
anonymous inline boxes, as explained in <a href="#anonymous">visual formatting model</a>:

<pre class="lang-xml example">
&lt;STACK&gt;
  &lt;ROW&gt;This is the &lt;D&gt;top&lt;/D&gt; row.&lt;/ROW&gt;
  &lt;ROW&gt;This is the &lt;D&gt;middle&lt;/D&gt; row.&lt;/ROW&gt;
  &lt;ROW&gt;This is the &lt;D&gt;bottom&lt;/D&gt; row.&lt;/ROW&gt;
&lt;/STACK&gt;
</pre>

<p>The style sheet is:

<pre class="example lang-css">
STACK { display: inline-table }
ROW   { display: table-row }
D     { display: inline; font-weight: bolder }
</pre>
</div>

<h3 id="columns">Columns</h3>

<p>Table cells may belong to two contexts: rows and columns. However,
in the source document cells are descendants of rows, never of
columns. Nevertheless, some aspects of cells can be influenced by
setting properties on columns.

<p>The following properties apply to column and column-group elements:

<dl>
  <dt>'border'

    <dd>The various border properties apply to columns only if 'border-collapse' is set
    to ''border-collapse/collapse'' on the table element. In that case, borders set on
    columns and column groups are input to the <a href="#border-conflict-resolution">conflict resolution
    algorithm</a> that selects the border styles at every cell edge.

  <dt>'background'

    <dd>The background properties set the background for cells in the
    column, but only if both the cell and row have transparent
    backgrounds. See <a href="#table-layers">"Table layers and
    transparency."</a>

  <dt>'width'

    <dd>The 'width' property gives
    the minimum width for the column.

  <dt>'visibility'

    <dd>If the 'visibility' of a column is set to ''visibility/collapse'', none of
    the cells in the column are rendered, and cells that span into
    other columns are clipped. In addition, the width of the table is
    diminished by the width the column would have taken up. See <a href="#dynamic-effects">"Dynamic effects"</a> below. Other values
    for 'visibility' have no effect.
</dl>

<div class="example">
<p>Here are some examples of style rules that set properties on
columns. The first two rules together implement the "rules" attribute
of HTML 4 with a value of "cols". The third rule makes the "totals"
column blue, the final two rules shows how to make a column a fixed
size, by using the <a href="#fixed-table-layout">fixed layout
algorithm</a>.

<pre class="lang-css">
col { border-style: none solid }
table { border-style: hidden }
col.totals { background: blue }
table { table-layout: fixed }
col.totals { width: 5em }
</pre>
</div>

<h3 id="model">Tables in the visual formatting model</h3>

<p>In terms of the visual formatting model, a table can behave like a
<a href="#block-level">block-level</a> (for 'display:
table') or <a href="#inline-level">inline-level</a> (for
'display: inline-table') element.

<p>In both cases, the table generates a principal block box called the
<dfn>table wrapper box</dfn> that
contains the table grid box itself and any caption boxes (in document
order).
The <dfn>table grid box</dfn> is a block-level box that contains the
table's internal table boxes.
The caption boxes are block-level boxes that retain their own
content, padding, margin, and border areas, and are rendered as normal
block boxes inside the table wrapper box. Whether the caption boxes are placed
before or after the table grid box is decided by the 'caption-side'
property, as described below.

<p>The table wrapper box is a ''display/block'' box if the table is block-level, and
an ''display/inline-block'' box if the table is inline-level. The table wrapper box
establishes a block formatting context. The table grid box (not the
table wrapper box) is used when doing baseline
vertical alignment for an ''display/inline-table''. The width of the table wrapper
box is the border-edge width of the table grid box inside it, as described
by section 17.5.2. Percentages on 'width' and 'height' on the table are
relative to the table wrapper box's containing block, not the table wrapper box
itself.

<p>The computed values of properties 'position', 'float', ''margin-*'',
'top', 'right', 'bottom', and 'left' on the table element are used on
the table wrapper box and not the table grid box; all other values of
non-inheritable properties are used on the table grid box and not the table
wrapper box. (Where the table element's values are not used on the
table and table wrapper boxes, the initial values are used instead.)

<div class="figure">
<p><img src="images/table_container.png" alt="A table with a caption above it" id="img-table_container">

<p class="caption">Diagram of a table with a caption above it.
</div>

<h4 id="caption-position">Caption position and alignment</h4>

<xmp class="propdef">
Name: caption-side
Value: top | bottom | inherit
Initial: top
Applies to: ''display/table-caption'' elements
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p>This property specifies the position of the caption box with
respect to the table grid box. Values have the following meanings:

<dl>
  <dt><dfn class="css" dfn-for="caption-side" dfn-type="value" id="valdef-caption-side-top">top</dfn> <dd>Positions the caption box above the
  table grid box.

  <dt><dfn class="css" dfn-for="caption-side" dfn-type="value" id="valdef-caption-side-bottom">bottom</dfn> <dd>Positions the caption box below the
  table grid box.
</dl>

<div class="note">
<p><em><strong>Note:</strong> CSS2&nbsp;(1998) described a different width and
horizontal alignment behavior. That behavior will be introduced in
CSS3 using the values ''top-outside'' and ''bottom-outside'' on this
property.</em>
</div>

<p>To align caption content horizontally within the caption box, use
the 'text-align' property.

<div class="example">
<p>In this example, the 'caption-side' property places
captions below tables.  The caption will be as wide as the parent of
the table, and caption text will be left-justified.

<pre class="lang-css">
caption { caption-side: bottom;
          width: auto;
          text-align: left }
</pre>
</div>

<h3 id="table-layout">Visual layout of table contents</h3>

<p>Internal table elements generate rectangular <a href="#box-dimensions">boxes</a> with content and borders.
Cells have padding as well. Internal table elements do not have
margins.

<p>The visual layout of these boxes is governed by a rectangular,
irregular grid of rows and columns. Each box occupies a whole number
of grid cells, determined according to the following rules. These
rules do not apply to HTML 4 or earlier HTML versions; HTML imposes
its own limitations on row and column spans.

<ol>
  <li>Each row box occupies one row of grid cells. Together, the row
  boxes fill the table from top to bottom in the order they occur in
  the source document (i.e., the table occupies exactly as many grid
  rows as there are row elements).

  <li>A row group occupies the same grid cells as the rows it
  contains.

  <li>A column box occupies one or more columns of grid cells. Column
  boxes are placed next to each other in the order they occur. The
  first column box may be either on the left or on the right,
  depending on the value of the 'direction' property of the table.

  <li>A column group box occupies the same grid cells as the columns
  it contains.

  <li>Cells may span several rows or columns. (Although CSS&nbsp;2
  does not define how the number of spanned rows or columns is
  determined, a user agent may have special knowledge about the source
  document; a future update of CSS may provide a way to express this
  knowledge in CSS syntax.) Each cell is thus a rectangular box, one
  or more grid cells wide and high. The top row of this rectangle is
  in the row specified by the cell's parent. The rectangle must be as
  far to the left as possible, but the part of the cell in the first
  column it occupies must not overlap with any other cell box (i.e., a
  row-spanning cell starting in a prior row), and the cell must be to
  the right of all cells in the same row that are earlier in the
  source document. If this position would cause a column-spanning cell
  to overlap a row-spanning cell from a prior row, CSS does not define
  the results: implementations may either overlap the cells (as is
  done in many HTML implementations) or may shift the later cell to
  the right to avoid such overlap. (This constraint holds if the
  'direction' property of the table is ''direction/ltr''; if the 'direction' is
  ''direction/rtl'', interchange "left" and "right" in the previous two
  sentences.)

  <li>A cell box cannot extend beyond the last row box of a table or
  row group; the user agents must shorten it until it fits.
</ol>

<p>The edges of the rows, columns, row groups and column groups in the
<a href="#collapsing-borders">collapsing borders model</a> coincide
with the hypothetical grid lines on which the borders of the cells are
centered. (And thus, in this model, the rows together exactly cover
the table, leaving no gaps; ditto for the columns.) In the <a>separated borders model</a>, the edges
coincide with the <a href="#border-edge">border edges</a> of
cells. (And thus, in this model, there may be gaps between the rows,
columns, row groups or column groups, corresponding to the 'border-spacing' property.)

<div class="note">
<p><em><strong>Note.</strong> Positioning and floating of table cells
can cause them not to be table cells anymore, according to the rules
in <a href="#dis-pos-flo">section 9.7</a>. When floating
is used, the <a>rules on anonymous table objects</a> may cause an
anonymous cell object to be created as well.</em>
</div>

<div class="lang-html example">
<p>Here is an example illustrating rule 5. The following illegal
  (X)HTML snippet defines conflicting cells:

<pre class="lang-xml">
&lt;table&gt;
&lt;tr&gt;&lt;td&gt;1 &lt;/td&gt;&lt;td rowspan="2"&gt;2 &lt;/td&gt;&lt;td&gt;3 &lt;/td&gt;&lt;td&gt;4 &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan="2"&gt;5 &lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
</pre>

<p>User agents are free to visually overlap the cells, as in the
figure on the left, or to shift the cell to avoid the visual
overlap, as in the figure on the right.

<div class="figure">
<p><img src="images/table-overlap.png" alt="One table with overlapping cells and one without" id="img-table-overlap"> <p class="caption">Two possible
renderings of an erroneous HTML table.
</div>
</div>

<h4 id="table-layers">Table layers and transparency</h4>

<p>For the purposes of finding the background of each table cell, the
different table elements may be thought of as being on six
superimposed layers. The background set on an element in one of the
layers will only be visible if the layers above it have a transparent
background.

<div class="figure">
<p><img src="images/tbl-layers.png" alt="schema of table layers" id="img-tbl-layers">

<p class="caption">Schema of table layers.
</div>

<ol>
  <li>The lowest layer is a single plane, representing the table grid box
  itself. Like all boxes, it may be transparent.

  <li>The next layer contains the column groups. Each column group
  extends from the top of the cells in the top row to the bottom of
  the cells on the bottom row and from the left edge of its leftmost
  column to the right edge of its rightmost column. The background
  covers exactly the full area of all cells that originate in the
  column group, even if they span outside the column group, but this
  difference in area does not affect background image positioning.

  <li>On top of the column groups are the areas representing the
  column boxes. Each column is as tall as the column groups and as
  wide as a normal (single-column-spanning) cell in the column. The
  background covers exactly the full area of all cells that originate
  in the column, even if they span outside the column, but this
  difference in area does not affect background image positioning.

  <li>Next is the layer containing the row groups. Each row group
  extends from the top left corner of its topmost cell in the first
  column to the bottom right corner of its bottommost cell in the last
  column.

  <li>The next to last layer contains the rows. Each row is as wide as
  the row groups and as tall as a normal (single-row-spanning) cell in
  the row. As with columns, the background covers exactly the full
  area of all cells that originate in the row, even if they span
  outside the row, but this difference in area does not affect
  background image positioning.

  <li>The topmost layer contains the cells themselves. As the figure
  shows, although all rows contain the same number of cells, not every
  cell may have specified content.
  In the <a>separated borders model</a>
  ('border-collapse' is
  ''separate''), if the value of their 'empty-cells' property is ''hide''
  these "empty" cells are transparent through the cell, row, row
  group, column and column group backgrounds, letting the table
  background show through.
</ol>

<p>A "missing cell" is a cell in the row/column grid that is not
occupied by an element or pseudo-element. Missing cells are rendered
as if an anonymous table-cell box occupied their position in the grid.

<div class="lang-html example">
<p>In the following example, the first row contains four non-empty
cells, but the second row contains only one non-empty cell, and thus
the table background shines through, except where a cell from the
first row spans into this row. The following HTML code and style rules

<pre>
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
&lt;HTML&gt;
  &lt;HEAD&gt;
    &lt;TITLE&gt;Table example&lt;/TITLE&gt;
    &lt;STYLE type="text/css"&gt;
      TABLE  { background: #ff0; border: solid black;
               empty-cells: hide }
      TR.top { background: red }
      TD     { border: solid black }
    &lt;/STYLE&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
    &lt;TABLE&gt;
      &lt;TR CLASS="top"&gt;
        &lt;TD&gt; 1
        &lt;TD rowspan="2"&gt; 2
        &lt;TD&gt; 3
        &lt;TD&gt; 4
      &lt;TR&gt;
        &lt;TD&gt; 5
        &lt;TD&gt;
    &lt;/TABLE&gt;
  &lt;/BODY&gt;
&lt;/HTML&gt;
</pre>

<p>might be formatted as follows:

<div class="figure">
  <p><img src="images/tbl-empty.png" alt="Table with three empty cells in bottom row" id="img-tbl-empty">

  <p class="caption">Table with empty cells in the bottom row.
</div>
</div>

<p>Note that if the table has 'border-collapse: separate', the
background of the area given by the 'border-spacing' property is
always the background of the table element. See the <a>separated borders model</a>.

<h4 id="width-layout">Table width algorithms:
the 'table-layout'
property</h4>

<p>CSS does not define an "optimal" layout for tables since, in many
cases, what is optimal is a matter of taste. CSS does define
constraints that user agents must respect when laying out a table.
User agents may use any algorithm they wish to do so, and are free to
prefer rendering speed over precision, except when the "fixed layout
algorithm" is selected.

<p>Note that this section overrides the rules that apply to
calculating widths as described in <a href="#Computing_widths_and_margins">section 10.3</a>. In
particular, if the margins of a table are set to ''0'' and the width to
''width/auto'', the table will not automatically size to fill its containing
block. However, once the calculated value of 'width' for the table is
found (using the algorithms given below or, when appropriate, some
other UA dependent algorithm) then the other parts of section 10.3 do
apply. Therefore a table <em>can</em> be centered using left and right
''margin/auto'' margins, for instance.

<p>Future updates of CSS may introduce ways of making tables
automatically fit their containing blocks.


</p>
<xmp class="propdef">
Name: table-layout
Value: auto | fixed | inherit
Initial: auto
Applies to: ''display/table'' and ''display/inline-table'' elements
Inherited: no
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p>The 'table-layout'
property controls the algorithm used to lay out the table cells, rows,
and columns. Values have the following meaning:

<dl>
  <dt><dfn class="css" dfn-for="table-layout" dfn-type="value" id="valdef-table-layout-fixed">fixed</dfn> <dd>Use the fixed table layout algorithm

  <dt><dfn class="css" dfn-for="table-layout" dfn-type="value" id="valdef-table-layout-auto">auto</dfn> <dd>Use any automatic table layout
  algorithm
</dl>

<p>The two algorithms are described below.

<h5 id="fixed-table-layout">Fixed table layout</h5>

<p>With this (fast) algorithm, the horizontal layout of the table does
not depend on the contents of the cells; it only depends on the
table's width, the width of the columns, and borders or cell spacing.

<p>The table's width may be specified explicitly with the 'width' property. A value of ''width/auto'' (for
both 'display: table' and 'display: inline-table') means use the <a href="#auto-table-layout">automatic table layout</a> algorithm.
However, if the table is a block-level table ('display: table') in
normal flow, a UA may (but does not have to) use the algorithm of <a href="#blockwidth">10.3.3</a> to compute a width and apply
fixed table layout even if the specified width is ''width/auto''.

<div class="example">
<p>If a UA supports fixed table layout when 'width' is ''width/auto'', the
following will create a table that is 4em narrower than its containing
block:

<pre class="lang-css">
table { table-layout: fixed;
        margin-left: 2em;
        margin-right: 2em }
</pre>
</div>

<p>In the fixed table layout algorithm, the width of each column is
determined as follows:

<ol>
  <li>A column element with a value other than ''width/auto'' for the 'width' property sets the width for
  that column.

  <li>Otherwise, a cell in the first row with a value other than
  ''width/auto'' for the 'width' property
  determines the width for that column. If the cell spans more than
  one column, the width is divided over the columns.

  <li>Any remaining columns equally divide the remaining horizontal
  table space (minus borders or cell spacing).
</ol>

<p>The width of the table is then the greater of the value of the
'width' property for the table
element and the sum of the column widths (plus cell spacing or
borders). If the table is wider than the columns, the extra space
should be distributed over the columns.

<p>If a subsequent row has more columns than the greater of the number
determined by the table-column elements and the number determined by
the first row, then
additional columns may not be rendered. CSS&nbsp;2 does not define
the width of the columns and the table if they <em>are</em> rendered.
When using 'table-layout:
fixed', authors should not omit columns from the first row.

<p>In this manner, the user agent can begin to lay out the table once
the entire first row has been received. Cells in subsequent rows do
not affect column widths. Any cell that has content that overflows
uses the 'overflow' property to
determine whether to clip the overflow content.

<h5 id="auto-table-layout">Automatic table layout</h5>

<p>In this algorithm (which generally requires no more than two
passes), the table's width is given by the width of its columns (and
intervening <a href="#borders">borders</a>). This algorithm reflects
the behavior of several popular HTML user agents at the writing of
this specification. UAs are not required to implement this algorithm
to determine the table layout in the case that 'table-layout' is ''table-layout/auto''; they
can use any other algorithm even if it results in different behavior.

<p>Input to the automatic table layout must only include the width of
the containing block and the content of, and any CSS properties set
on, the table and any of its descendants.

<div class="note">
<p><em><strong>Note.</strong> This may be defined in more detail in
CSS3.</em>
</div>

<p><em>The remainder of this section is non-normative.</em>
<div class="non-normative">

<p>This algorithm may be inefficient since it requires the user agent
to have access to all the content in the table before determining the
final layout and may demand more than one pass.

<p>Column widths are determined as follows:

<ol>
  <li><p>Calculate the minimum content width (MCW) of each cell: the
  formatted content may span any number of lines but may not overflow
  the cell box. If the specified 'width' (W) of the cell is greater
  than MCW, the minimum cell width is set to W. A value of ''width/auto'' means that
  MCW is the minimum cell width.

  <p>Also, calculate the "maximum" cell width of each cell: formatting
  the content without breaking lines other than where explicit line
  breaks occur.

  <li><p>For each column, determine a maximum and minimum column width
  from the cells that span only that column. The minimum is that
  required by the cell with the largest minimum cell width (or the
  column 'width', whichever is
  larger). The maximum is that required by the cell with the largest
  maximum cell width (or the column 'width', whichever is larger).

  <li><p>For each cell that spans more than one column, increase the
  minimum widths of the columns it spans so that together, they are at
  least as wide as the cell. Do the same for the maximum widths. If
  possible, widen all spanned columns by approximately the same
  amount.

  <li><p>For each column group element with a 'width' other than
  ''width/auto'', increase the minimum widths of the columns it spans, so that
  together they are at least as wide as the column group's 'width'.

</ol>

<p>This gives a maximum and minimum width for each column.

<p>The caption width minimum (CAPMIN) is determined by calculating for
each caption the minimum caption outer width as the MCW of a
hypothetical table cell that contains the caption formatted as
"display: block". The greatest of the minimum caption outer widths is
CAPMIN.

<p>Column and caption
widths influence the final table width as follows:

<ol>
  <li>If the ''display/table'' or ''display/inline-table'' element's 'width' property has a computed value
  (W) other than ''width/auto'', the used width is
  the greater of W, CAPMIN, and the minimum width required by all the
  columns plus cell spacing or borders (MIN). If the used width is
  greater than MIN, the
  extra width should be distributed over the columns.

  <li>If the ''display/table'' or ''display/inline-table'' element has 'width: auto',
  the used width is the greater of the table's containing block width,
  CAPMIN, and MIN. However, if either CAPMIN or the maximum width
  required by the columns plus cell spacing or borders (MAX) is less
  than that of the containing block, use max(MAX, CAPMIN).
</ol>

<p>A percentage value for a column width is relative to the table
width. If the table has 'width: auto', a percentage represents a
constraint on the column's width, which a UA should try to satisfy.
(Obviously, this is not always possible: if the column's width is
''110%'', the constraint cannot be satisfied.)

<div class="note">
<p><em><strong>Note.</strong> In this algorithm, rows (and row
groups) and columns (and column groups) both constrain and are
constrained by the dimensions of the cells they contain. Setting the
width of a column may indirectly influence the height of a row, and
vice versa.</em>
</div>
</div>

<h4 id="height-layout">Table height algorithms</h4>

<p>The height of a table is given by the 'height' property for the ''display/table'' or
''display/inline-table'' element. A value of ''height/auto'' means that the height is the
sum of the row heights plus any cell spacing or borders. Any other
value is treated as a minimum height. CSS&nbsp;2 does not define how
extra space is distributed when the 'height' property causes the table
to be taller than it otherwise would be.

<p class="note"><em><strong>Note.</strong> Future
updates of CSS may specify this further.</em>

<p>The height of a ''display/table-row'' element's box is calculated once the
user agent has all the cells in the row available: it is the maximum
of the row's computed 'height',
the computed 'height' of each
cell in the row,
and the minimum height (MIN) required by the cells. A 'height' value of ''height/auto'' for a
''display/table-row'' means the row height used for layout is MIN. MIN depends
on cell box heights and cell box alignment (much like the calculation
of a <a href="#line-height">line box</a> height).
CSS&nbsp;2 does not define how the height of table cells and table
rows is calculated when their height is specified using percentage
values. CSS&nbsp;2 does not define the meaning of 'height' on row groups.

<p>In CSS&nbsp;2, the height of a cell box is the minimum height
required by the content. The table cell's 'height' property can influence the
height of the row (see above), but it does not increase the height of
the cell box.

<p>CSS&nbsp;2 does not specify how cells that span more than one row
affect row height calculations except that the sum of the row heights
involved must be great enough to encompass the cell spanning the rows.

<p>The 'vertical-align'
property of each table cell determines its alignment within the row.
Each cell's content has a baseline, a top, a middle, and a bottom, as
does the row itself. In the context of tables, values for 'vertical-align' have the
following meanings:

<dl>
  <dt><strong>baseline</strong>

    <dd>The baseline of the cell is put at the same height as the
    baseline of the first of the rows it spans (see below for the
    definition of baselines of cells and rows).

  <dt><strong>top</strong>

    <dd>The top of the cell box is aligned with the top of the first
    row it spans.

  <dt><strong>bottom</strong>

    <dd>The bottom of the cell box is aligned with the bottom of the
    last row it spans.

  <dt><strong>middle</strong>

    <dd>The center of the cell is aligned with the center of the rows
    it spans.

  <dt><strong>sub, super, text-top, text-bottom, <<length>>,
  <<percentage>></strong>

    <dd>These values do not apply to cells; the cell is aligned at the
    baseline instead.
</dl>

<p>The baseline of a cell is the baseline of the first in-flow <a href="#line-box">line box</a> in the cell, or the first
in-flow table-row in the cell, whichever comes first. If there is no
such line box or table-row, the baseline is the bottom of content edge
of the cell box. For the purposes of finding a baseline, in-flow boxes
with a scrolling mechanisms (see the 'overflow' property) must be
considered as if scrolled to their origin position. Note that the
baseline of a cell may end up below its bottom border, see the <a href="#baseline-below">example</a> below.

<p>The maximum
distance between the top of the cell box and the baseline over all
cells that have 'vertical-align: baseline' is used to set the baseline
of the row. Here is an example:

<div class="figure">
  <p><img src="images/cell-align.png" alt="Example of vertically aligning the cells" id="img-cell-align">

  <p class="caption">Diagram showing the effect of various values of
  'vertical-align' on table cells.
</div>

<p>Cell boxes 1 and 2 are aligned at their baselines. Cell box 2 has
the largest height above the baseline, so that determines the baseline
of the row.

<p>If a row has no cell box aligned to its baseline, the baseline of
that row is the bottom content edge of the lowest cell in the row.

<p>To avoid ambiguous situations, the alignment of cells proceeds in
the following order:

<ol>
  <li>First the cells that are aligned on their baseline are
  positioned. This will establish the baseline of the row. Next the
  cells with 'vertical-align: top' are positioned.

  <li>The row now has a top, possibly a baseline, and a provisional
  height, which is the distance from the top to the lowest bottom of
  the cells positioned so far. (See conditions on the cell padding
  below.)

  <li>If any of the remaining cells, those aligned at the bottom or
  the middle, have a height that is larger than the current height of
  the row, the height of the row will be increased to the maximum of
  those cells, by lowering the bottom.

  <li>Finally the remaining cells are positioned.
</ol>

<p>Cell boxes that are smaller than the height of the row receive
extra top or bottom padding.

<div class="example" id="baseline-below">
<p>The cell in this example has a baseline below its bottom border:

<pre>
div { height: 0; overflow: hidden; }

&lt;table&gt;
 &lt;tr&gt;
  &lt;td&gt;
   &lt;div&gt; Test &lt;/div&gt;
  &lt;/td&gt;
 &lt;/tr&gt;
&lt;/table&gt;
</pre>
</div>


<h4 id="column-alignment">Horizontal alignment in a column</h4>

<p>The horizontal alignment of inline-level content within a cell
box can be specified by the value of
the 'text-align' property on
the cell.

<!-- dynamic effect -->

<h4 id="dynamic-effects">Dynamic row and column effects</h4>

<p>The 'visibility' property
takes the value ''visibility/collapse'' for row, row group, column, and column
group elements. This value causes the entire row or column to be
removed from the display, and the space normally taken up by the row
or column to be made available for other content. Contents of spanned
rows and columns that intersect the collapsed column or row are
clipped. The suppression of the row or column, however, does not
otherwise affect the layout of the table. This allows dynamic effects
to remove table rows or columns without forcing a re-layout of the
table in order to account for the potential change in column
constraints.

<h3 id="borders">Borders</h3>

<p>There are two distinct models for setting borders on table cells in
CSS. One is most suitable for so-called <a data-lt="separated borders model">separated borders</a> around individual
cells, the other is suitable for borders that are continuous from one
end of the table to the other. Many border styles can be achieved with
either model, so it is often a matter of taste which one is used.

</p>
<xmp class="propdef">
Name: border-collapse
Value: collapse | separate | inherit
Initial: separate
Applies to: ''display/table'' and ''display/inline-table'' elements
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p>This property selects a table's border model. The value <dfn class="css" dfn-for="border-collapse" dfn-type="value" id="valdef-border-collapse-separate">separate</dfn>
selects the separated borders border model. The value <dfn class="css" dfn-for="border-collapse" dfn-type="value" id="valdef-border-collapse-collapse">collapse</dfn>
selects the collapsing borders model. The models are described below.

<h4 id="separated-borders">The <dfn>separated borders model</dfn></h4>

<xmp class="propdef">
Name: border-spacing
Value: <<length>> <<length>>? | inherit
Initial: 0
Applies to: ''display/table'' and ''display/inline-table'' elements*
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: two absolute lengths
Animation type: by computed value type
</xmp>



<p class="note">*) Note: user agents may also apply the
'border-spacing' property to ''frameset'' elements. Which elements are
''frameset'' elements is not defined by this specification and is up to
the document language. For example, HTML4 defines a &lt;FRAMESET&gt;
element, and XHTML 1.0 defines a &lt;frameset&gt; element. The
'border-spacing' property on a ''frameset'' element can be thus used as
a valid substitute for the non-standard ''framespacing'' attribute.

<p>The lengths specify the distance that separates adjoining cell
borders. If one length is specified, it gives both the horizontal and
vertical spacing. If two are specified, the first gives the horizontal
spacing and the second the vertical spacing. Lengths may not be
negative.

<p>The distance between the table border and the borders of the cells
on the edge of the table is the table's padding for that side, plus
the relevant border spacing distance. For example, on the right hand
side, the distance is <var>padding-right</var> + <var>horizontal
border-spacing</var>.

<p>The width of the table is the distance from the left inner padding
edge to the right inner padding edge (including the border spacing but
excluding padding and border).

<p>However, in HTML and XHTML1, the width of the &lt;table&gt;
element is the distance from the left border edge to the right border
edge.

<p class="note"><strong>Note:</strong> In CSS3 this peculiar requirement
will be defined in terms of UA style sheet rules and the ''box-sizing''
property.

<p>In this model, each cell has an individual border. The 'border-spacing' property
specifies the distance between the borders of adjoining cells. In this
space, the row, column, row group, and column group backgrounds are
invisible, allowing the table background to show through. Rows,
columns, row groups, and column groups cannot have borders (i.e., user
agents must <a data-lt="ignore" href="#ignore">ignore</a> the border properties for
those elements).

<div class="example">
<p>The table in the figure below could be the result of a style sheet
like this:

<pre class="lang-css">
table      { border: outset 10pt;
             border-collapse: separate;
             border-spacing: 15pt }
td         { border: inset 5pt }
td.special { border: inset 10pt }  /* The top-left cell */
</pre>

<div class="figure">
  <p><img src="images/tbl-spacing.png" alt="A table with border-spacing" id="img-tbl-spacing">

  <p class="caption"> A table with 'border-spacing' set to a
  length value. Note that each cell has its own border, and the table
  has a separate border as well.
</div>
</div>

<h5 id="empty-cells">Borders and Backgrounds around empty cells: the 'empty-cells' property</h5>

<xmp class="propdef">
Name: empty-cells
Value: show | hide | inherit
Initial: show
Applies to: ''display/table-cell'' elements
Inherited: yes
Percentages: N/A
Media: visual
Computed Value: as specified
Animation type: discrete
</xmp>



<p>In the separated borders model, this property controls the
rendering of borders and backgrounds around cells that have no visible
content. Empty cells and cells with the 'visibility' property set to
''visibility/hidden'' are considered to have no visible content.
Cells are empty unless they contain one or more of the following:
<ul>
<li>floating content (including empty elements),
<li>in-flow content (including empty elements) other than white space
that has been collapsed away by the 'white-space' property handling.
</ul>

<p>When this property has the value <dfn class="css" dfn-for="empty-cells" dfn-type="value" id="valdef-empty-cells-show">show</dfn>, borders and backgrounds
are drawn around/behind empty cells (like normal cells).

<p>A value of <dfn class="css" dfn-for="empty-cells" dfn-type="value" id="valdef-empty-cells-hide">hide</dfn> means that no borders or backgrounds are drawn
around/behind empty cells (see point 6 in <a href="#table-layers">17.5.1</a>). Furthermore, if all the cells in a
row have a value of ''hide'' and have no visible content, then the row
has zero height and there is vertical border-spacing on only one side
of the row.

<div class="example">
<p>The following rule causes borders and backgrounds to be drawn
around all cells:

<pre class="lang-css">
table { empty-cells: show }
</pre>
</div>

<h4 id="collapsing-borders">The collapsing border model</h4>

<p>In the collapsing border model, it is possible to specify borders
that surround all or part of a cell, row, row group, column, and
column group. Borders for HTML's "rules" attribute can be specified
this way.

<p>Borders are centered on the grid lines between the cells. User
agents must find a consistent rule for rounding off in the case of an
odd number of discrete units (screen pixels, printer dots).

<p>The diagram below shows how the width of the table, the widths of
the borders, the padding, and the cell width interact. Their relation
is given by the following equation, which holds for every row of the
table:

<blockquote>
<p><var>row-width</var> = (0.5 * <var>border-width</var><sub>0</sub>)
\+ <var>padding-left</var><sub>1</sub> + <var>width</var><sub>1</sub> +
<var>padding-right</var><sub>1</sub> +
<var>border-width</var><sub>1</sub> +
<var>padding-left</var><sub>2</sub> +...+
<var>padding-right</var><sub><var>n</var></sub> + (0.5 *
<var>border-width</var><sub><var>n</var></sub>)
</blockquote>

<p>Here <var>n</var> is the number of cells in the row,
<var>padding-left</var><sub><var>i</var></sub> and
<var>padding-right</var><sub><var>i</var></sub> refer to the left
(resp., right) padding of cell <var>i</var>, and
<var>border-width</var><sub><var>i</var></sub> refers to the border
between cells <var>i</var> and <var>i</var> + 1.

<p>UAs must compute an initial left and right border width for the
table by examining the first and last cells in the first row of the
table. The left border width of the table is half of the first cell's
collapsed left border, and the right border width of the table is half
of the last cell's collapsed right border. If subsequent rows have
larger collapsed left and right borders, then any excess spills into
the margin area of the table.

<p>The top border width of the table is computed by examining all
cells who collapse their top borders with the top border of the table.
The top border width of the table is equal to half of the maximum
collapsed top border. The bottom border width is computed by examining
all cells whose bottom borders collapse with the bottom of the table.
The bottom border width is equal to half of the maximum collapsed
bottom border.

<p>Any borders that spill into the margin are taken into account when
determining if the table overflows some ancestor (see 'overflow').</p>

<div class="figure">
  <p><img src="images/tbl-width.png" alt="Schema showing the widths of cells and borders and the padding of cells" id="img-tbl-width">

  <p class="caption">Schema showing the widths of cells and borders
  and the padding of cells.
</div>

<p>Note that in this model, the width of the table includes half the
table border. Also, in this model, a table does not have padding (but
does have margins).

<p>CSS&nbsp;2 does not define where the edge of a background on a
table element lies.

<h5 id="border-conflict-resolution">Border conflict resolution</h5>

<p>In the collapsing border model, borders at every edge of every cell
may be specified by border properties on a variety of elements that
meet at that edge (cells, rows, row groups, columns, column groups,
and the table itself), and these borders may vary in width, style, and
color. The rule of thumb is that at each edge the most "eye catching"
border style is chosen, except that any occurrence of the style
''border-style/hidden'' unconditionally turns the border off.

<p>The following rules determine which border style "wins" in case of
a conflict:

<ol>
  <li>Borders with the 'border-style' of ''border-style/hidden'' take
  precedence over all other conflicting borders. Any border with this
  value suppresses all borders at this location.

  <li>Borders with a style of ''border-style/none'' have the lowest priority. Only if
  the border properties of all the elements meeting at this edge are
  ''border-style/none'' will the border be omitted (but note that ''border-style/none'' is the
  default value for the border style.)

  <li>If none of the styles are ''border-style/hidden'' and at least one of them is
  not ''border-style/none'', then narrow borders are discarded in favor of wider
  ones. If several have the same 'border-width' then styles are
  preferred in this order: ''border-style/double'', ''border-style/solid'', ''border-style/dashed'', ''border-style/dotted'',
  ''border-style/ridge'', ''border-style/outset'', ''border-style/groove'', and the lowest: ''border-style/inset''.

  <li>If border styles differ only in color, then a style set on a
  cell wins over one on a row, which wins over a row group, column,
  column group and, lastly, table. When two elements of the same type
  conflict, then the one further to the left (if the table's
  'direction' is ''direction/ltr''; right, if it is ''direction/rtl'') and further to the top
  wins.
</ol>

<div class="example">
<p>The following example illustrates the application of these
precedence rules. This style sheet:

<pre class="lang-css">
table          { border-collapse: collapse;
                 border: 5px solid yellow; }
*#col1         { border: 3px solid black; }
td             { border: 1px solid red; padding: 1em; }
td.cell5       { border: 5px dashed blue; }
td.cell6       { border: 5px solid green; }
</pre>

<p>with this HTML source:

<pre class="lang-html example">
&lt;TABLE&gt;
&lt;COL id="col1"&gt;&lt;COL id="col2"&gt;&lt;COL id="col3"&gt;
&lt;TR id="row1"&gt;
    &lt;TD&gt; 1
    &lt;TD&gt; 2
    &lt;TD&gt; 3
&lt;/TR&gt;
&lt;TR id="row2"&gt;
    &lt;TD&gt; 4
    &lt;TD class="cell5"&gt; 5
    &lt;TD class="cell6"&gt; 6
&lt;/TR&gt;
&lt;TR id="row3"&gt;
    &lt;TD&gt; 7
    &lt;TD&gt; 8
    &lt;TD&gt; 9
&lt;/TR&gt;
&lt;TR id="row4"&gt;
    &lt;TD&gt; 10
    &lt;TD&gt; 11
    &lt;TD&gt; 12
&lt;/TR&gt;
&lt;TR id="row5"&gt;
    &lt;TD&gt; 13
    &lt;TD&gt; 14
    &lt;TD&gt; 15
&lt;/TR&gt;
&lt;/TABLE&gt;
</pre>

<p>would produce something like this:

<div class="figure">
  <p><img src="images/tbl-border-conflict.png" alt="An example of a table with collapsed borders" id="img-tbl-border-conflict">

  <p class="caption">An example of a table with collapsed borders.
</div>
</div>

<div class="example">
<p>Here is an example of hidden collapsing borders:

<div class="figure">
  <p><img src="images/CSStbl3.png" alt="Table with two omitted borders" id="img-CSStbl3">

  <p class="caption"> Table with two omitted internal borders.
</div>

<p>HTML source:

<pre class="lang-html example">
&lt;TABLE style="border-collapse: collapse; border: solid;"&gt;
&lt;TR&gt;&lt;TD style="border-right: hidden; border-bottom: hidden"&gt;foo&lt;/TD&gt;
    &lt;TD style="border: solid"&gt;bar&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD style="border: none"&gt;foo&lt;/TD&gt;
    &lt;TD style="border: solid"&gt;bar&lt;/TD&gt;&lt;/TR&gt;
&lt;/TABLE&gt;
</pre>
</div>

<h4 id="table-border-styles">Border styles</h4>

<p>Some of the values of the <<border-style>> have
different meanings in tables than for other elements. In the list
below they are marked with an asterisk.

<dl>
  <dt><a data-link-type="value" data-link-for="&lt;border-style&gt;" class="value-inst-bo-none"><strong>none</strong></a>

    <dd><a data-link-type="value" data-link-for="&lt;border-style&gt;" class="value-inst-bo-none" data-lt="none">No
    border.</a>

  <dt><strong>*<a data-link-type="value" data-link-for="&lt;border-style&gt;" class="value-inst-hidden">hidden</a></strong>

    <dd>Same as ''<border-style>/none'', but in the <a href="#collapsing-borders">collapsing border model</a>, also
    inhibits any other border (see the section on <a href="#border-conflict-resolution">border conflicts</a>).

  <dt><strong><a data-link-type="value" data-link-for="&lt;border-style&gt;" class="value-inst-dotted">dotted</a></strong>

    <dd>The border is a series of dots.

  <dt><strong><a data-link-type="value" data-link-for="&lt;border-style&gt;" class="value-inst-dashed">dashed</a></strong>

    <dd>The border is a series of short line segments.

  <dt><strong><a data-link-type="value" data-link-for="&lt;border-style&gt;" class="value-inst-solid">solid</a></strong>

    <dd>The border is a single line segment.

   <dt><strong><a data-link-type="value" data-link-for="&lt;border-style&gt;" class="value-inst-double">double</a></strong>

    <dd>The border is two solid lines. The sum of the two lines and
    the space between them equals the value of 'border-width'.

  <dt><strong><a data-link-type="value" data-link-for="&lt;border-style&gt;" class="value-inst-groove">groove</a></strong>

    <dd>The border looks as though it were carved into the canvas.

  <dt><strong><a data-link-type="value" data-link-for="&lt;border-style&gt;" class="value-inst-ridge">ridge</a></strong>

    <dd>The opposite of ''<border-style>/groove'': the border looks as though it were
    coming out of the canvas.

  <dt><strong>*<a data-link-type="value" data-link-for="&lt;border-style&gt;" class="value-inst-inset">inset</a></strong>

    <dd>In the <a>separated borders
    model</a>, the border makes the entire box look as though it were
    embedded in the canvas. In the <a href="#collapsing-borders">collapsing border model</a>, drawn the same as
    ''<border-style>/ridge''.

  <dt><strong>*<a data-link-type="value" data-link-for="&lt;border-style&gt;" class="value-inst-outset">outset</a></strong>

    <dd>In the <a>separated borders
    model</a>, the border makes the entire box look as though it were
    coming out of the canvas. In the <a href="#collapsing-borders">collapsing border model</a>, drawn the same as
    ''<border-style>/groove''.
</dl>





<h2 id="ui"><span id="q18.0">User interface</span></h2>

<h3 id="cursor-props">Cursors: the 'cursor' property</h3>

<xmp class="propdef">
Name: cursor
Value: [ [<<uri>> ,]* [ auto | crosshair | default | pointer | move | e-resize | ne-resize | nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize | text | wait | help | progress ] ] | inherit
Initial: auto
Applies to: *
Inherited: yes
Percentages: N/A
Media: visual, interactive
Computed Value: as specified, except with any relative URLs converted to absolute
Animation type: by computed value type
</xmp>



<p>This property specifies the type of cursor to be displayed for the
  pointing device. Values have the following meanings:
</p>

<dl>
<dt><dfn class="css" dfn-for="cursor" dfn-type="value" id="valdef-cursor-auto">auto</dfn></dt>
<dd>The UA determines the cursor to display based on the current
context.</dd>

<dt><dfn class="css" dfn-for="cursor" dfn-type="value" id="valdef-cursor-crosshair">crosshair</dfn></dt>
<dd>A simple crosshair (e.g., short line segments resembling a "+" sign).
</dd>
<dt><dfn class="css" dfn-for="cursor" dfn-type="value" id="valdef-cursor-default">default</dfn></dt>
<dd>The platform-dependent default cursor. Often rendered as an arrow.
</dd>
<dt><dfn class="css" dfn-for="cursor" dfn-type="value" id="valdef-cursor-pointer">pointer</dfn></dt>
<dd>The cursor is a pointer that indicates a link.
</dd>
<dt><dfn class="css" dfn-for="cursor" dfn-type="value" id="valdef-cursor-move">move</dfn></dt>
<dd>Indicates something is to be moved.
</dd>
<dt><dfn class="css" dfn-for="cursor" dfn-type="value" id="valdef-cursor-e-resize">e-resize</dfn>, <dfn class="css" dfn-for="cursor" dfn-type="value" id="valdef-cursor-ne-resize">ne-resize</dfn>, <dfn class="css" dfn-for="cursor" dfn-type="value" id="valdef-cursor-nw-resize">nw-resize</dfn>, <dfn class="css" dfn-for="cursor" dfn-type="value" id="valdef-cursor-n-resize">n-resize</dfn>, <dfn class="css" dfn-for="cursor" dfn-type="value" id="valdef-cursor-se-resize">se-resize</dfn>,
<dfn class="css" dfn-for="cursor" dfn-type="value" id="valdef-cursor-sw-resize">sw-resize</dfn>, <dfn class="css" dfn-for="cursor" dfn-type="value" id="valdef-cursor-s-resize">s-resize</dfn>, <dfn class="css" dfn-for="cursor" dfn-type="value" id="valdef-cursor-w-resize">w-resize</dfn></dt>

<dd>Indicate that some edge is to be moved. For example, the
''se-resize'' cursor is used when the movement starts from the
south-east corner of the box.
</dd>
<dt><dfn class="css" dfn-for="cursor" dfn-type="value" id="valdef-cursor-text">text</dfn></dt>
<dd>Indicates text that may be selected. Often rendered as an I-beam.
</dd>
<dt><dfn class="css" dfn-for="cursor" dfn-type="value" id="valdef-cursor-wait">wait</dfn></dt>
<dd>Indicates that the program is busy and the user should
  wait. Often rendered as a watch or hourglass.
</dd>
<dt><dfn class="css" dfn-for="cursor" dfn-type="value" id="valdef-cursor-progress">progress</dfn></dt>
<dd>A progress indicator.  The program is performing some processing,
but is different from ''wait'' in that the user may still interact with the program.
Often rendered as a spinning beach ball,
or an arrow with a watch or hourglass.
</dd>
<dt><dfn class="css" dfn-for="cursor" dfn-type="value" id="valdef-cursor-help">help</dfn></dt>
<dd>Help is available for the object under the cursor. Often rendered
  as a question mark or a balloon.
</dd>
<dt><<uri>></dt>
<dd>The user agent retrieves the cursor from the resource
designated by the URI. If the user agent cannot handle
the first cursor of a list of cursors, it should attempt
to handle the second, etc. If the user agent cannot handle
any user-defined cursor, it must use the generic cursor
at the end of the list.
Intrinsic sizes for cursors are calculated as for <a href="#background-properties">background images,</a> except
that a UA-defined rectangle is used in place of the rectangle that
establishes the coordinate system for the 'background-image' property.
This UA-defined rectangle should be based on the size of a typical
cursor on the UA's operating system. If the resulting cursor size does
not fit within this rectangle, the UA may proportionally scale the
resulting cursor down until it fits within the rectangle.</dd> </dl>

<div class="example">
<pre class="lang-css">
:link,:visited { cursor: url(example.svg#linkcursor), url(hyper.cur), pointer }
</pre>
<p>This example sets the cursor on all hyperlinks (whether visited or not)
to an external <a href="https://www.w3.org/TR/SVG/interact.html#CursorElement">SVG cursor</a>.
User agents that do not support SVG cursors would simply skip to the
next value and attempt to use the "hyper.cur" cursor.
If that cursor format was also not supported, the UA would skip to the next value and simply render the ''pointer'' cursor.
</p>
</div>




<h3 id="system-colors">System Colors</h3>

<div class="note"><p><em><strong>Note.</strong>
The System Colors are deprecated in the CSS3 Color Module [[CSS3COLOR]].
</em></p>
</div>

<p>In addition to being able to assign pre-defined <a href="#color-units">color values</a> to text, backgrounds, etc., CSS2&nbsp;(1998) introduced a set of named color values that allows authors to specify colors in a manner that integrates them into the operating system's graphic environment.
</p>

<p>For systems that do not have a corresponding value, the
specified value should be mapped to the nearest system value, or to a default color.</p>

<p>The following lists additional values for color-related CSS properties and their general meaning. Any color property (e.g., 'color' or 'background-color') can take
one of the following names. Although these are case-insensitive, it is
recommended that the mixed capitalization shown below be used, to
make the names more legible.</p>

<dl>
<dt>ActiveBorder</dt>
<dd>Active window border.</dd>
<dt>ActiveCaption</dt>
<dd>Active window caption.</dd>
<dt>AppWorkspace</dt>
<dd>Background color of multiple document interface.</dd>
<dt>Background</dt>
<dd>Desktop background.</dd>
<dt>ButtonFace</dt>
<dd>Face color for three-dimensional display elements.</dd>
<dt>ButtonHighlight</dt>
<dd>Highlight color for three-dimensional display elements (for
    edges facing away from the light source).</dd>
<dt>ButtonShadow</dt>
<dd>Shadow color for three-dimensional display elements.</dd>
<dt>ButtonText</dt>
<dd>Text on push buttons.</dd>
<dt>CaptionText</dt>
<dd>Text in caption, size box, and scrollbar arrow box.</dd>
<dt>GrayText</dt>
<dd>Grayed (disabled) text. This color is set to #000 if
the current display driver does not support a solid gray color.</dd>
<dt>Highlight</dt>
<dd>Item(s) selected in a control.</dd>
<dt>HighlightText</dt>
<dd>Text of item(s) selected in a control.</dd>
<dt>InactiveBorder</dt>
<dd>Inactive window border.</dd>
<dt>InactiveCaption</dt>
<dd>Inactive window caption.</dd>
<dt>InactiveCaptionText</dt>
<dd>Color of text in an inactive caption.</dd>
<dt>InfoBackground</dt>
<dd>Background color for tooltip controls.</dd>
<dt>InfoText</dt>
<dd>Text color for tooltip controls.</dd>
<dt>Menu</dt>
<dd>Menu background.</dd>
<dt>MenuText</dt>
<dd>Text in menus.</dd>
<dt>Scrollbar</dt>
<dd>Scroll bar gray area.</dd>
<dt>ThreeDDarkShadow</dt>
<dd>Dark shadow for three-dimensional display elements.</dd>
<dt>ThreeDFace</dt>
<dd>Face color for three-dimensional display elements.</dd>
<dt>ThreeDHighlight</dt>
<dd>Highlight color for three-dimensional display elements.</dd>
<dt>ThreeDLightShadow</dt>
<dd>Light color for three-dimensional display elements
(for edges facing the light source).</dd>
<dt>ThreeDShadow</dt>
<dd>Dark shadow for three-dimensional display elements.</dd>
<dt>Window</dt>
<dd>Window background.</dd>
<dt>WindowFrame</dt>
<dd>Window frame.</dd>
<dt>WindowText</dt>
<dd>Text in windows.</dd>
</dl>

<div class="example"><p>
For example, to set the foreground and background colors of a paragraph
to the same foreground and background colors of the user's window,
write the following:
</p>
<pre class="lang-css">
p { color: WindowText; background-color: Window }
</pre>
</div>

<h3 id="system-fonts">User preferences for fonts</h3>

<p>As for colors, authors may specify fonts in a way that makes use of
a user's system resources. Please consult the 'font' property for details.
</p>
<h3 id="dynamic-outlines">Dynamic outlines: the 'outline' property</h3>

<p>At times, style sheet authors may want to create outlines around
visual objects such as buttons, active form fields, image maps, etc.,
to make them stand out. CSS&nbsp;2 outlines differ from <a href="#border-properties">borders</a> in the following
ways:</p>

<ol>
<li>Outlines do not take up space. </li>
<li>Outlines may be non-rectangular. </li>
</ol>

<p>The outline properties control the style of these dynamic outlines.
</p>
<xmp class="propdef shorthand">
Name: outline
Value: [ <<'outline-color'>> || <<'outline-style'>> || <<'outline-width'>> ] | inherit
Initial: see individual properties
Applies to: *
Inherited: no
Percentages: N/A
Media: visual, interactive
Computed Value: see individual properties
</xmp>


<xmp class="propdef">
Name: outline-width
Value: <<border-width>> | inherit
Initial: medium
Applies to: *
Inherited: no
Percentages: N/A
Media: visual, interactive
Computed Value: absolute length; ''0'' if the outline style is ''border-style/none''
Animation type: by computed value type
</xmp>


<xmp class="propdef">
Name: outline-style
Value: <<border-style>> | inherit
Initial: none
Applies to: *
Inherited: no
Percentages: N/A
Media: visual, interactive
Computed Value: as specified
Animation type: by computed value type
</xmp>


<xmp class="propdef">
Name: outline-color
Value: <<color>> | invert | inherit
Initial: invert
Applies to: *
Inherited: no
Percentages: N/A
Media: visual, interactive
Computed Value: as specified
Animation type: by computed value type
</xmp>



<p>The outline created with the outline properties is drawn "over" a
box, i.e., the outline is always on top, and does not influence the
position or size of the box, or of any other boxes. Therefore,
displaying or suppressing outlines does not cause reflow or overflow.
</p>
<p>The outline may be drawn starting just outside the <a href="#border-edge">border edge</a>.
</p>
<p>Outlines may be non-rectangular. For example, if the element is
broken across several lines, the outline is the minimum outline that
encloses all the element's boxes. In contrast to <a href="#border-properties">borders</a>, the outline is not
open at the line box's end or start, but is always fully connected if possible.
</p>
<p>The 'outline-width'
property accepts the same values as 'border-width'.
</p>
<p>The 'outline-style'
property accepts the same values as 'border-style',
except that ''border-style/hidden'' is not a legal outline style.
</p>
<p>The 'outline-color'
accepts all colors, as well as the keyword <dfn id="value-def-invert" dfn-type="value" dfn-for="outline-color">invert</dfn>. ''outline-color/invert'' is expected to
perform a color inversion on the pixels on the screen. This is a
common trick to ensure the focus border is visible, regardless of
color background.
</p>
<p>
Conformant UAs may ignore the ''outline-color/invert'' value on platforms that do not
support color inversion of the pixels on the screen.  If the UA does not
support the ''outline-color/invert'' value then the initial value of the 'outline-color'
property is the value of the 'color' property, similar to the initial value
of the 'border-top-color' property.
</p>
<p>The 'outline' property is a
shorthand property, and sets all three of 'outline-style', 'outline-width', and 'outline-color'.
</p>
<div class="note"><p><em><strong>Note.</strong>
The outline is the same on all sides. In
contrast to borders, there is no ''outline-top'' or ''outline-left''
property.
</em></p>
</div>
<p>This specification does not define how multiple overlapping
outlines are drawn, or how outlines are drawn for boxes that are
partially obscured behind other elements.
</p>
<div class="note"><p>
<em><strong>Note.</strong>
Since the outline does not affect formatting (i.e., no
space is left for it in the box model), it may well overlap
other elements on the page.
</em></p>
</div>

<div class="example"><p>
Here's an example of drawing a
thick outline around a BUTTON element:
</p>
<pre class="lang-css">
button { outline : thick solid}
</pre>

<p>Scripts may be used to dynamically change the width
of the outline, without provoking a reflow.
</p>
</div>

<h4 id="outline-focus">Outlines and the focus</h4>

<p>Graphical user interfaces may use outlines around elements to tell
the user which element on the page has the <dfn>focus</dfn>. These outlines are in addition
to any borders, and switching outlines on and off should not cause
the document to reflow. The focus is the subject of user interaction
in a document (e.g., for entering text, selecting a button,
etc.). User agents supporting the <a href="#interactive-media-group">interactive media group</a>
must keep track of where the focus lies and must also represent the
focus. This may be done by using dynamic outlines in conjunction with
the :focus pseudo-class.
</p>
<div class="example">
<p>For example, to draw a thick black line around an element when it
has the focus, and a thick red line when it is active, the following
rules can be used:
</p>
<pre class="lang-css">
:focus  { outline: thick solid black }
:active { outline: thick solid red }
</pre>
</div>

<h3 id="magnification">Magnification</h3>

<p>The CSS working group considers that the magnification of a
document or portions of a document should not be specified through
style sheets. User agents may support such magnification in different ways
(e.g., larger images, louder sounds, etc.)
</p>

<p>When magnifying a page, UAs should preserve the relationships
between positioned elements. For example, a comic strip may be
composed of images with overlaid text elements. When magnifying this
page, a user agent should keep the text within the comic strip balloon.
</p>




<section class="non-normative">
<h2 id="aural" class="no-toc"><span id="q19.0">Appendix A: Aural style sheets</span></h2>

<p>
  <span id="angles"></span>
  <span id="aural-intro"></span>
  <span id="aural-media-group"></span>
  <span id="aural-tables"></span>
  <span id="cue-props"></span>
  <span id="Emacspeak"></span>
  <span id="frequencies"></span>
  <span id="img-table1"></span>
  <span id="mixing-props"></span>
  <span id="pause-props"></span>
  <span id="propdef-azimuth"></span>
  <span id="propdef-cue"></span>
  <span id="propdef-cue-after"></span>
  <span id="propdef-cue-before"></span>
  <span id="propdef-elevation"></span>
  <span id="propdef-pause"></span>
  <span id="propdef-pause-after"></span>
  <span id="propdef-pause-before"></span>
  <span id="propdef-pitch"></span>
  <span id="propdef-pitch-range"></span>
  <span id="propdef-play-during"></span>
  <span id="propdef-richness"></span>
  <span id="propdef-speak"></span>
  <span id="propdef-speak-header"></span>
  <span id="propdef-speak-numeral"></span>
  <span id="propdef-speak-punctuation"></span>
  <span id="propdef-speech-rate"></span>
  <span id="propdef-stress"></span>
  <span id="propdef-voice-family"></span>
  <span id="propdef-volume"></span>
  <span id="sample"></span>
  <span id="spatial-props"></span>
  <span id="speak-headers"></span>
  <span id="speaking-props"></span>
  <span id="speech-props"></span>
  <span id="times"></span>
  <span id="value-def-angle"></span>
  <span id="value-def-frequency"></span>
  <span id="value-def-generic-voice"></span>
  <span id="value-def-specific-voice"></span>
  <span id="value-def-time"></span>
  <span id="voice-char-props"></span>
  <span id="volume-props"></span>
  Earlier revisions of CSS2 defined an ''aural'' media type and various properties that applied to it. [[CSS-SPEECH-1]]
  represents more recent work for the same use-cases.
</p>

</section>





<h2 id="references"><span id="q20.0">Appendix B: Bibliography</span></h2>
<div data-fill-with="references">

</div>





<section class="non-normative">
<h2 id="app-changes"><span id="q21.0">Appendix C: Changes</span></h2>
<p><em>This appendix is informative, not normative.</em></p>

<p>CSS&nbsp;2.2 is an updated revision of CSS&nbsp;2. The changes between
the CSS&nbsp;2.1 specification (see [[!CSS21]]) and this specification fall into
five groups: <a href="#known-errors">known errors,</a> typographical
errors, <a href="#clarifications">clarifications,</a> <a href="#changes">changes</a> and <a href="#new">additions.</a>
Typographical errors are not listed here.</p>

<!--
<p>In addition, this chapter lists the <a href="#errata">errata
(part&nbsp;1</a> and <a href="#errata2">part&nbsp;2)</a>
that were subsequently applied to CSS&nbsp;2.1 since it became a
Candidate Recommendation in July 2007.
-->

<p>This chapter is not a complete list of changes. Minor editorial
changes are not listed here.</p>



<h3 id="new">Additional property values</h3>

<!--
<h3 id="a4.3.6"><a href="syndata.html#color-units">Section 4.3.6
Colors</a></h3>

<p>New color value: 'orange'
-->


<h3 id="changes">Changes</h3>

<h4 id="drop-aural">Appendix A: Aural style sheets</h4>

The informative appendix on the [[CSS20]] ''aural'' media type and related properties has been removed.

Note: there are no tests for this change as all the removed text is informative.

<h4 id="inherit-computed-value">Specified value of inherit</h4>

The [=specified value=] of ''inherit'' now comes from the [=computed value=] instead of the [=specified value=].

<wpt>
  css/CSS2/borders/border-width-011.xht
</wpt>

<h3 id="known-errors">Errors</h3>
<!--

<h3 id="x-shorthand-inherit">Shorthand properties</h3>

<p>Shorthand properties take a list of subproperty values <em>or</em>
the value 'inherit'. One cannot mix 'inherit' with other subproperty
values as it would not be possible to specify the subproperty to which
'inherit' applied. The definitions of a number of shorthand properties
did not enforce this rule: 'border-top', 'border-right',
'border-bottom', 'border-left', 'border', 'background', 'font',
'list-style', 'cue', and 'outline'.
-->

<h3 id="clarifications">Clarifications</h3>

<!--
<h3 id="r2.1"><a href="intro.html#html-tutorial">Section 2.1
A brief CSS&nbsp;2.1 tutorial for HTML</a></h3>

<p>This section has been marked non-normative.</p>
-->

<!--
<h2><span id=errata>Errata since the Candidate Recommendation of July
2007</span></h2>

<p>Errata to CSS&nbsp;2.1 since <a href="/TR/2007/CR-CSS21-20070719">CR version of July 19, 2007.</a>
-->
</section>





<section class="non-normative">
<h2 id="html-stylesheet"><span id="q22.0">Appendix D: Default style sheet for HTML 4</span></h2>
<p><em>This appendix is informative, not normative.</em></p>

<p>This style sheet describes the typical formatting of all HTML 4
([[HTML401]]) elements based on extensive research into current UA
practice. Developers are encouraged to use it as a default style sheet
in their implementations.

<p>The full presentation of some HTML elements cannot be expressed in
CSS&nbsp;2, including <a href="#replaced-element">replaced</a>
elements ("img", "object"), scripting elements ("script", "applet"), form
control elements, and frame elements.

<p>For other elements, the legacy presentation can be described in CSS
but the solution removes the element. For example, the FONT element
can be replaced by attaching CSS declarations to other elements (e.g.,
DIV). Likewise, legacy presentation of presentational attributes
(e.g., the "border" attribute on TABLE) can be described in CSS, but
the markup in the source document must be changed.

<pre class="example lang-css">
html, address,
blockquote,
body, dd, div,
dl, dt, fieldset, form,
frame, frameset,
h1, h2, h3, h4,
h5, h6, noframes,
ol, p, ul, center,
dir, hr, menu, pre   { display: block; unicode-bidi: embed }
li              { display: list-item }
head            { display: none }
table           { display: table }
tr              { display: table-row }
thead           { display: table-header-group }
tbody           { display: table-row-group }
tfoot           { display: table-footer-group }
col             { display: table-column }
colgroup        { display: table-column-group }
td, th          { display: table-cell }
caption         { display: table-caption }
th              { font-weight: bolder; text-align: center }
caption         { text-align: center }
body            { margin: 8px }
h1              { font-size: 2em; margin: .67em 0 }
h2              { font-size: 1.5em; margin: .75em 0 }
h3              { font-size: 1.17em; margin: .83em 0 }
h4, p,
blockquote, ul,
fieldset, form,
ol, dl, dir,
menu            { margin: 1.12em 0 }
h5              { font-size: .83em; margin: 1.5em 0 }
h6              { font-size: .75em; margin: 1.67em 0 }
h1, h2, h3, h4,
h5, h6, b,
strong          { font-weight: bolder }
blockquote      { margin-left: 40px; margin-right: 40px }
i, cite, em,
var, address    { font-style: italic }
pre, tt, code,
kbd, samp       { font-family: monospace }
pre             { white-space: pre }
button, textarea,
input, select   { display: inline-block }
big             { font-size: 1.17em }
small, sub, sup { font-size: .83em }
sub             { vertical-align: sub }
sup             { vertical-align: super }
table           { border-spacing: 2px; }
thead, tbody,
tfoot           { vertical-align: middle }
td, th, tr      { vertical-align: inherit }
s, strike, del  { text-decoration: line-through }
hr              { border: 1px inset }
ol, ul, dir,
menu, dd        { margin-left: 40px }
ol              { list-style-type: decimal }
ol ul, ul ol,
ul ul, ol ol    { margin-top: 0; margin-bottom: 0 }
u, ins          { text-decoration: underline }
br:before       { content: "\A"; white-space: pre-line }
center          { text-align: center }
:link, :visited { text-decoration: underline }
:focus          { outline: thin dotted invert }

<span id="bidi">/* Begin bidirectionality settings (do not change) */
BDO[DIR="ltr"]  { direction: ltr; unicode-bidi: bidi-override }
BDO[DIR="rtl"]  { direction: rtl; unicode-bidi: bidi-override }

*[DIR="ltr"]    { direction: ltr; unicode-bidi: embed }
*[DIR="rtl"]    { direction: rtl; unicode-bidi: embed }</span>

@media print {
  h1            { page-break-before: always }
  h1, h2, h3,
  h4, h5, h6    { page-break-after: avoid }
  ul, ol, dl    { page-break-before: avoid }
}


</pre>
</section>




<h2 id="elaborate-stacking-contexts"><span id="q23.0">Appendix E: Elaborate description of Stacking Contexts</span></h2>

<p>This chapter defines the CSS&nbsp;2 painting order in more detail than
described in the rest of the specification.</p>

<h3 id="stacking-defs">Definitions</h3>

<dl>

<dt>Tree Order</dt>

<dd>Preorder depth-first traversal of the <em>rendering</em> tree, in
logical (not visual) order for bidirectional content, after taking
into account properties that move boxes around.</dd>

<dt>Element</dt>

<dd>In this description, "element" refers to actual elements,
pseudo-elements, and anonymous boxes. Pseudo-elements and anonymous
boxes are treated as descendants in the appropriate places. For
example, an outside list marker comes before an adjoining '':before''
box in the line box, which comes before the content of the box, and so
forth.</dd>

</dl>

<h3 id="painting-order">Painting order</h3>

    <p>The bottom of the stack is the furthest from the user, the top
    of the stack is the nearest to the user:

<pre>
	     |	   |	     |	  |
	     |		|    |	  |	&#x21e6; &#x263b;
	     |		|	  |	user
z-index:  canvas  -1	0    1	  2
</pre>

    <p>The stacking context background and most negative positioned
    stacking contexts are at the bottom of the stack, while the most
    positive positioned stacking contexts are at the top of the stack.

    <p>The canvas is transparent if contained within another, and
    given a UA-defined color if it is not. It is infinite in extent
    and contains the root element. Initially, the viewport is anchored
    with its top left corner at the canvas origin.

    <p>The painting order for the descendants of an element generating
    a stacking context (see the 'z-index' property) is:

    <ol class="stack">
      <li>
        <p>If the element is a root element:
        <ol>
          <li>background color of element over the entire canvas.

          <li>background image of element, over the entire canvas,
          anchored at the origin that would be used if it was painted
          for the root element.
        </ol>

      <li>
        <p>If the element is a block, list-item, or other block
        equivalent:
        <ol>
          <li>background color of element unless it is the root
          element.

          <li>background image of element unless it is the root
          element.

          <li>border of element.
        </ol>

        <p>Otherwise, if the element is a block level table:
        <ol>
          <li>table backgrounds (color then image) unless it is the
          root element.
          <li>column group backgrounds (color then image).
          <li>column backgrounds (color then image).
          <li>row group backgrounds (color then image).
          <li>row backgrounds (color then image).
          <li>cell backgrounds (color then image).
          <li>all table borders (in tree order for separated borders).
        </ol>

      <li>
        <p>Stacking contexts formed by positioned descendants with
        negative z-indices (excluding 0) in z-index order (most
        negative first) then tree order.

      <li>
        <p>For all its in-flow, non-positioned, block-level
        descendants in tree order: If the element is a block,
        list-item, or other block equivalent:
        <ol>
          <li>background color of element.
          <li>background image of element.
          <li>border of element.
        </ol>

        <p>Otherwise, the element is a table:
        <ol>
          <li>table backgrounds (color then image).
          <li>column group backgrounds (color then image).
          <li>column backgrounds (color then image).
          <li>row group backgrounds (color then image).
          <li>row backgrounds (color then image).
          <li>cell backgrounds (color then image).
          <li>all table borders (in tree order for separated borders).
        </ol>

      <li>
        <p>All non-positioned floating descendants, in tree order. For
        each one of these, treat the element as if it created a new
        stacking context, but any positioned descendants and
        descendants which actually create a new stacking context
        should be considered part of the parent stacking context, not
        this new one.

      <li>
        <p>If the element is an inline element that generates a
        stacking context, then:
        <ol>
          <li>
            <p>For each line box that the element is in:
            <ol>
              <li>Jump to <a href="#each-box">7.2.1</a> for the
              box(es) of the element in that line box (in tree order).
            </ol>
        </ol>

      <li>
        <p>Otherwise: first for the element, then for all its in-flow,
        non-positioned, block-level descendants in tree order:
        <ol>
          <li>
            <p>If the element is a block-level replaced element, then:
            the replaced content, atomically.

          <li>
            <p>Otherwise, for each line box of that element:
            <ol>
              <li id="each-box">
                <p>For each box that is a child of that element, in
                that line box, in tree order:
                <ol>
                  <li>
                    <p>background color of element.
                  <li>
                    <p>background image of element.
                  <li>
                    <p>border of element.
                  <li>
                    <p>For inline elements:
                    <ol>
                      <li>
                        <p>For all the element's in-flow,
                        non-positioned, inline-level children that are
                        in this line box, and all runs of text inside
                        the element that is on this line box, in tree
                        order:
                        <ol>
                          <li>
                            <p>If this is a run of text, then:
                            <ol>
                              <li>any underlining affecting the text
                              of the element, in tree order of the
                              elements applying the underlining (such
                              that the deepest element's underlining,
                              if any, is painted topmost and the root
                              element's underlining, if any, is drawn
                              bottommost).

                              <li>any overlining affecting the text of
                              the element, in tree order of the
                              elements applying the overlining (such
                              that the deepest element's overlining,
                              if any, is painted topmost and the root
                              element's overlining, if any, is drawn
                              bottommost).

                              <li>the text.

                              <li>any line-through affecting the text
                              of the element, in tree order of the
                              elements applying the line-through (such
                              that the deepest element's line-through,
                              if any, is painted topmost and the root
                              element's line-through, if any, is drawn
                              bottommost).
                            </ol>

                          <li>
                            <p>Otherwise, jump to <a href="#each-box">7.2.1</a> for that
                            element.
                        </ol>
                    </ol>

                    <p>For inline-block and inline-table elements:
                    <ol>
                      <li>For each one of these, treat the element as
                      if it created a new stacking context, but any
                      positioned descendants and descendants which
                      actually create a new stacking context should be
                      considered part of the parent stacking context,
                      not this new one.
                    </ol>

                    <p>For inline-level replaced elements:
                    <ol>
                      <li>the replaced content, atomically.
                    </ol>
                </ol>

                <p class="note">Some of the boxes may have been
                generated by line splitting or the Unicode
                bidirectional algorithm.

              <li>
                <p>Optionally, the outline of the element (see <a href="#outlines">10 below</a>).
            </ol>

          <li>
            <p>Optionally, if the element is block-level, the outline
            of the element (see <a href="#outlines">10 below</a>).
        </ol>

      <li>
        <p>All positioned descendants with 'z-index: auto' or
        'z-index: 0', in tree order. For those with 'z-index: auto',
        treat the element as if it created a new stacking context, but
        any positioned descendants and descendants which actually
        create a new stacking context should be considered part of the
        parent stacking context, not this new one. For those with
        'z-index: 0', treat the stacking context generated atomically.

      <li>
        <p>Stacking contexts formed by positioned descendants with
        z-indices greater than or equal to 1 in z-index order
        (smallest first) then tree order.

      <li id="outlines">
        <p>Finally, implementations that do not draw outlines in steps
        above must draw outlines from this stacking context at this
        stage. (It is recommended to draw outlines in this step and
        not in the steps above.)
    </ol>

    <h3 id="stacking-notes">Notes</h3>

    <p>The background of the root element is only painted once, over
    the whole canvas.

    <p>While the backgrounds of bidirectional inlines are painted in
    tree order, they are positioned in visual order. Since the
    positioning of inline backgrounds is unspecified in CSS&nbsp;2,
    the exact result of these two requirements is UA-defined. CSS3 may
    define this in more detail.




</p>
<h2 id="property-index"><span id="q24.0">Appendix F: Full property table</span></h2>

<p><em>This appendix is informative, not normative.</em></p>

<div data-fill-with="property-index">

</div>




<section class="non-normative">
<h2 id="app-grammar"><span id="q25.0">Appendix G: Grammar of CSS&nbsp;2</span></h2>

<p>This appendix is non-normative.

<p>The grammar below defines the syntax of CSS&nbsp;2. It is in some sense,
however, a superset of CSS&nbsp;2 as this specification imposes additional
semantic constraints not expressed in this grammar. A conforming UA
must also adhere to the <a href="#syntax">
forward-compatible parsing rules</a>, the selectors notation, the <a href="#property-defs">property and value notation</a>,
and the unit notation. However, not all syntactically correct CSS can take
effect, since the document language may impose restrictions that are
not in CSS, e.g., HTML imposes restrictions on the possible values of
the "class" attribute.

<h3 id="grammar">Grammar</h3>

<p> The grammar below is LALR(1) (but note that most UA's should not use it
directly, since it does not express the <a href="#parsing-errors">parsing conventions</a>, only the
CSS&nbsp;2 syntax). The format of the productions is optimized for human
consumption and some shorthand notation beyond Yacc (see [[!YACC]]) is
used:</p>

<ul>
<li><strong>*</strong>: 0 or more
<li><strong>+</strong>: 1 or more
<li><strong>?</strong>: 0 or 1
<li><strong>|</strong>: separates alternatives
<li><strong>[&nbsp;]</strong>: grouping
</ul>

<p>The productions are:

<pre>
stylesheet
  : [ CHARSET_SYM STRING ';' ]?
    [S|CDO|CDC]* [ import [ CDO S* | CDC S* ]* ]*
    [ [ ruleset | media | page ] [ CDO S* | CDC S* ]* ]*
  ;
import
  : IMPORT_SYM S*
    [STRING|URI] S* media_list? ';' S*
  ;
media
  : MEDIA_SYM S* media_list '{' S* ruleset* '}' S*
  ;
media_list
  : medium [ COMMA S* medium]*
  ;
medium
  : IDENT S*
  ;
page
  : PAGE_SYM S* pseudo_page?
    '{' S* declaration? [ ';' S* declaration? ]* '}' S*
  ;
pseudo_page
  : ':' IDENT S*
  ;
operator
  : '/' S* | ',' S*
  ;
combinator
  : '+' S*
  | '&gt;' S*
  ;
unary_operator
  : '-' | '+'
  ;
property
  : IDENT S*
  ;
ruleset
  : selector [ ',' S* selector ]*
    '{' S* declaration? [ ';' S* declaration? ]* '}' S*
  ;
selector
  : simple_selector [ combinator selector | S+ [ combinator? selector ]? ]?
  ;
simple_selector
  : element_name [ HASH | class | attrib | pseudo ]*
  | [ HASH | class | attrib | pseudo ]+
  ;
class
  : '.' IDENT
  ;
element_name
  : IDENT | '*'
  ;
attrib
  : '[' S* IDENT S* [ [ '=' | INCLUDES | DASHMATCH ] S*
    [ IDENT | STRING ] S* ]? ']'
  ;
pseudo
  : ':' [ IDENT | FUNCTION S* [IDENT S*]? ')' ]
  ;
declaration
  : property ':' S* expr prio?
  ;
prio
  : IMPORTANT_SYM S*
  ;
expr
  : term [ operator? term ]*
  ;
term
  : unary_operator?
    [ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* | ANGLE S* |
      TIME S* | FREQ S* ]
  | STRING S* | IDENT S* | URI S* | hexcolor | function
  ;
function
  : FUNCTION S* expr ')' S*
  ;
/*
 * There is a constraint on the color that it must
 * have either 3 or 6 hex-digits (i.e., [0-9a-fA-F])
 * after the "#"; e.g., "#000" is OK, but "#abcd" is not.
 */
hexcolor
  : HASH S*
  ;
</pre>

<h3 id="scanner">Lexical scanner</h3>

<p> The following is the <dfn>tokenizer</dfn>, written in Flex (see [[!FLEX]])
notation. The tokenizer is case-insensitive.

<p>The "\377" represents the highest character
number that current versions of Flex can deal with (decimal 255). It
should be read as "\4177777" (decimal 1114111), which is the highest
possible code point in [[!UNICODE]]/[[!ISO10646]].

<pre>
%option case-insensitive

h		[0-9a-f]
nonascii	[\240-\377]
unicode		\\{h}{1,6}(\r\n|[ \t\r\n\f])?
escape		{unicode}|\\[^\r\n\f0-9a-f]
nmstart		[_a-z]|{nonascii}|{escape}
nmchar		[_a-z0-9-]|{nonascii}|{escape}
string1		\"([^\n\r\f\\"]|\\{nl}|{escape})*\"
string2		\'([^\n\r\f\\']|\\{nl}|{escape})*\'
badstring1      \"([^\n\r\f\\"]|\\{nl}|{escape})*\\?
badstring2      \'([^\n\r\f\\']|\\{nl}|{escape})*\\?
badcomment1     \/\*[^*]*\*+([^/*][^*]*\*+)*
badcomment2     \/\*[^*]*(\*+[^/*][^*]*)*
baduri1         url\({w}([!#$%&amp;*-\[\]-~]|{nonascii}|{escape})*{w}
baduri2         url\({w}{string}{w}
baduri3         url\({w}{badstring}
comment		\/\*[^*]*\*+([^/*][^*]*\*+)*\/
ident		-?{nmstart}{nmchar}*
name		{nmchar}+
num		[0-9]+|[0-9]*"."[0-9]+
string		{string1}|{string2}
badstring       {badstring1}|{badstring2}
badcomment      {badcomment1}|{badcomment2}
baduri          {baduri1}|{baduri2}|{baduri3}
url		([!#$%&amp;*-~]|{nonascii}|{escape})*
s		[ \t\r\n\f]+
w		{s}?
nl		\n|\r\n|\r|\f

A		a|\\0{0,4}(41|61)(\r\n|[ \t\r\n\f])?
C		c|\\0{0,4}(43|63)(\r\n|[ \t\r\n\f])?
D		d|\\0{0,4}(44|64)(\r\n|[ \t\r\n\f])?
E		e|\\0{0,4}(45|65)(\r\n|[ \t\r\n\f])?
G		g|\\0{0,4}(47|67)(\r\n|[ \t\r\n\f])?|\\g
H		h|\\0{0,4}(48|68)(\r\n|[ \t\r\n\f])?|\\h
I		i|\\0{0,4}(49|69)(\r\n|[ \t\r\n\f])?|\\i
K		k|\\0{0,4}(4b|6b)(\r\n|[ \t\r\n\f])?|\\k
L               l|\\0{0,4}(4c|6c)(\r\n|[ \t\r\n\f])?|\\l
M		m|\\0{0,4}(4d|6d)(\r\n|[ \t\r\n\f])?|\\m
N		n|\\0{0,4}(4e|6e)(\r\n|[ \t\r\n\f])?|\\n
O		o|\\0{0,4}(4f|6f)(\r\n|[ \t\r\n\f])?|\\o
P		p|\\0{0,4}(50|70)(\r\n|[ \t\r\n\f])?|\\p
R		r|\\0{0,4}(52|72)(\r\n|[ \t\r\n\f])?|\\r
S		s|\\0{0,4}(53|73)(\r\n|[ \t\r\n\f])?|\\s
T		t|\\0{0,4}(54|74)(\r\n|[ \t\r\n\f])?|\\t
U               u|\\0{0,4}(55|75)(\r\n|[ \t\r\n\f])?|\\u
X		x|\\0{0,4}(58|78)(\r\n|[ \t\r\n\f])?|\\x
Z		z|\\0{0,4}(5a|7a)(\r\n|[ \t\r\n\f])?|\\z

%%

{s}			{return S;}

\/\*[^*]*\*+([^/*][^*]*\*+)*\/		/* ignore comments */
{badcomment}                         /* unclosed comment at EOF */

"&lt;!--"		{return CDO;}
"--&gt;"			{return CDC;}
"~="			{return INCLUDES;}
"|="			{return DASHMATCH;}

{string}		{return STRING;}
{badstring}             {return BAD_STRING;}

{ident}			{return IDENT;}

"#"{name}		{return HASH;}

@{I}{M}{P}{O}{R}{T}	{return IMPORT_SYM;}
@{P}{A}{G}{E}		{return PAGE_SYM;}
@{M}{E}{D}{I}{A}	{return MEDIA_SYM;}
"@charset "		{return CHARSET_SYM;}

"!"({w}|{comment})*{I}{M}{P}{O}{R}{T}{A}{N}{T}	{return IMPORTANT_SYM;}

{num}{E}{M}		{return EMS;}
{num}{E}{X}		{return EXS;}
{num}{P}{X}		{return LENGTH;}
{num}{C}{M}		{return LENGTH;}
{num}{M}{M}		{return LENGTH;}
{num}{I}{N}		{return LENGTH;}
{num}{P}{T}		{return LENGTH;}
{num}{P}{C}		{return LENGTH;}
{num}{D}{E}{G}		{return ANGLE;}
{num}{R}{A}{D}		{return ANGLE;}
{num}{G}{R}{A}{D}	{return ANGLE;}
{num}{M}{S}		{return TIME;}
{num}{S}		{return TIME;}
{num}{H}{Z}		{return FREQ;}
{num}{K}{H}{Z}		{return FREQ;}
{num}{ident}		{return DIMENSION;}

{num}%			{return PERCENTAGE;}
{num}			{return NUMBER;}

"url("{w}{string}{w}")" {return URI;}
"url("{w}{url}{w}")"    {return URI;}
{baduri}                {return BAD_URI;}

{ident}"("		{return FUNCTION;}

.			{return *yytext;}
</pre>

<h3 id="tokenizer-diffs">Comparison of tokenization in CSS2&nbsp;(1998) and
CSS1</h3>

<p>There are some differences in the syntax specified in the CSS1
recommendation ([[CSS1]]), and the one above. Most of these are due
to new tokens in CSS2 that did not exist in CSS1. Others are because
the grammar has been rewritten to be more readable. However, there are
some incompatible changes, that were felt to be errors in the CSS1
syntax. They are explained below.

<ul>
<li>CSS1 style sheets could only be in 1-byte-per-character
encodings, such as ASCII and ISO-8859-1. CSS&nbsp;2 has no such
limitation. In practice, there was little difficulty in extrapolating
the CSS1 tokenizer, and some UAs have accepted 2-byte encodings.

<li>CSS1 only allowed four hex-digits after the backslash (\) to refer
to Unicode characters, CSS2 <a href="#escaped-characters">allows six</a>. Furthermore,
CSS2 allows a white space character to delimit the escape
sequence. E.g., according to CSS1, the string "\abcdef" has 3 letters
(\abcd, e, and f), according to CSS2 it has only one (\abcdef).

<li>The tab character (ASCII 9) was not allowed in strings. However,
since strings in CSS1 were only used for font names and for URLs, the
only way this can lead to incompatibility between CSS1 and CSS2 is if
a style sheet contains a font family that has a tab in its name.

<li>Similarly, newlines (<a href="#strings">escaped with a
backslash</a>) were not allowed in strings in CSS1.

<li>CSS2 parses a number immediately followed by an identifier as a
DIMENSION token (i.e., an unknown unit), CSS1 parsed it as a number and an
identifier. That means that in CSS1, the declaration 'font:
10pt/1.2serif' was correct, as was 'font: 10pt/12pt serif'; in CSS2, a
space is required before "serif". (Some UAs accepted the first
example, but not the second.)

<li>In CSS1, a class name could start with a digit (".55ft"), unless
it was a dimension (".55in"). In CSS2, such classes are parsed as
unknown dimensions (to allow for future additions of new units). To
make ".55ft" a valid class, CSS2 requires the first digit to be
escaped (".\35 5ft")
</ul>

<h3 id="implementation-note"><span id="q25.4"><span id="q4">Implementation note</span></span></h3>

<p>The lexical scanner for the CSS core syntax in <a href="#tokenization">section&nbsp;4.1.1</a> can be
implemented as a scanner without back-up. In Lex notation, that
requires the addition of the following patterns (which do not change
the returned tokens, only the efficiency of the scanner):

<pre>
{ident}/\\          return IDENT;
#{name}/\\          return HASH;
@{ident}/\\         return ATKEYWORD;
#/\\                return DELIM;
@/\\                return DELIM;
@/-                 return DELIM;
@/-\\               return DELIM;
-/\\                return DELIM;
-/-                 return DELIM;
\&lt;/!                return DELIM;
\&lt;/!-               return DELIM;
{num}{ident}/\\     return DIMENSION;
{num}/\\            return NUMBER;
{num}/-             return NUMBER;
{num}/-\\           return NUMBER;
[0-9]+/\.           return NUMBER;
u/\+                return IDENT;
u\+[0-9a-f?]{1,6}/- return UNICODE_RANGE;
</pre>

</section>






<h2 id="leftblank"><span id="q26.0">Appendix H: Has been intentionally left blank</span></h2>







<h2 id="index"><span id="q27.0">Appendix I: Index</span></h2>
<p><em>This appendix is informative, not normative.</em></p>
<div class="NOPRINT" data-fill-with="index">




</div>
