The DOM Level 2 Cascading Style Sheets (CSS) interfaces are designed with the goal of exposing CSS constructs to object model consumers. Cascading Style Sheets is a declarative syntax for defining presentation rules, properties and ancillary constructs used to format and render Web documents. This document specifies a mechanism to programmatically access and modify the rich style and presentation control provided by CSS (specifically CSS level two [CSS2]). This augments CSS by providing a mechanism to dynamically control the inclusion and exclusion of individual style sheets, as well as manipulate CSS rules and properties.
The CSS interfaces are organized in a logical, rather than physical structure. A collection of all style sheets referenced by or embedded in the document is accessible on the document interface. Each item in this collection exposes the properties common to all style sheets referenced or embedded in HTML and XML documents; this interface is described in the Style Sheets chapter of the DOM Level 2. User style sheets are not accessible through this collection, in part due to potential privacy concerns (and certainly read-write issues).
For each CSS style sheet, an additional interface is exposed - the
CSSStyleSheet interface. This interface allows access to
the collection of rules within a CSS style sheet and methods to modify
that collection. Interfaces are provided for each specific type of rule
in CSS2 (e.g. style declarations, @import rules, or
@font-face rules), as well as a shared generic
CSSRule interface.
The most common type of rule is a style declaration. The
CSSStyleRule interface that represents this type of rule
provides string access to the CSS selector of the rule, and access to the
property declarations through the CSSStyleDeclaration
interface.
Finally, an optional CSS2Properties interface is described;
this interface (if implemented) provides shortcuts to the string
values of all the properties in CSS level 2.
All CSS objects in the DOM are "live", that is, a change in the style sheet is reflected in the computed and actual style.
A DOM application can use the hasFeature method of the
DOMImplementation interface to determine whether the CSS
interfaces are supported or not. The feature string for the CSS Model is
"CSS". The existence within an implementation of the extended interfaces
can also be queried using the hasFeature method.
The interfaces within this section are considered fundamental, and must be supported by all conforming DOM implementations. These interfaces represent CSS style sheets specifically.
The CSSStyleSheet interface is a concrete interface used
to represent a CSS style sheet i.e. a style sheet whose content type
is "text/css".
// Introduced in DOM Level 2:
interface CSSStyleSheet : stylesheets::StyleSheet {
readonly attribute CSSRule ownerRule;
readonly attribute CSSRuleList cssRules;
unsigned long insertRule(in DOMString rule,
in unsigned long index)
raises(DOMException);
void deleteRule(in unsigned long index)
raises(DOMException);
};
ownerRule of type CSSRule, readonly@import rule, the
ownerRule attribute will contain the
CSSImportRule. In that case, the ownerNode
attribute in the StyleSheet interface will be
null. If the style sheet comes from an element or a
processing instruction, the ownerRule attribute will be
null and the ownerNode attribute will contain
the Node.
cssRules of type CSSRuleList, readonly
insertRule
| The parsable text representing the rule. For rule sets this contains both the selector and the style declaration. For at-rules, this specifies both the at-identifier and the rule content. | |||
|
| The index within the style sheet's rule list of the rule before which to insert the specified rule. If the specified index is equal to the length of the style sheet's rule collection, the rule will be added to the end of the style sheet. |
|
The index within the style sheet's rule collection of the newly inserted rule. |
|
HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted
at the specified index e.g. if an INDEX_SIZE_ERR: Raised if the specified index is not a valid insertion point. NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is readonly. SYNTAX_ERR: Raised if the specified rule has a syntax error and is unparsable. |
deleteRule
|
| The index within the style sheet's rule list of the rule to remove. |
|
INDEX_SIZE_ERR: Raised if the specified index does not correspond to a rule in the style sheet's rule list. NO_MODIFICATION_ALLOWED_ERR: Raised if this style sheet is readonly. |
The CSSRuleList interface provides the
abstraction of an ordered collection of CSS rules.
// Introduced in DOM Level 2:
interface CSSRuleList {
readonly attribute unsigned long length;
CSSRule item(in unsigned long index);
};
item
|
| Index into the collection |
|
The style rule at the |
The CSSRule interface is the abstract base interface for any
type of CSS
statement.
This includes both
rule sets
and
at-rules. An
implementation is expected to preserve all rules specified in a CSS style
sheet, even if the rule is not recognized by the parser. Unrecognized
rules are represented using the CSSUnknownRule interface.
// Introduced in DOM Level 2:
interface CSSRule {
// RuleType
const unsigned short UNKNOWN_RULE = 0;
const unsigned short STYLE_RULE = 1;
const unsigned short CHARSET_RULE = 2;
const unsigned short IMPORT_RULE = 3;
const unsigned short MEDIA_RULE = 4;
const unsigned short FONT_FACE_RULE = 5;
const unsigned short PAGE_RULE = 6;
readonly attribute unsigned short type;
attribute DOMString cssText;
// raises(DOMException) on setting
readonly attribute CSSStyleSheet parentStyleSheet;
readonly attribute CSSRule parentRule;
};
An integer indicating which type of rule this is.
| UNKNOWN_RULE |
The rule is a CSSUnknownRule. |
| STYLE_RULE |
The rule is a CSSStyleRule. |
| CHARSET_RULE |
The rule is a CSSCharsetRule. |
| IMPORT_RULE |
The rule is a CSSImportRule. |
| MEDIA_RULE |
The rule is a CSSMediaRule. |
| FONT_FACE_RULE |
The rule is a CSSFontFaceRule. |
| PAGE_RULE |
The rule is a CSSPageRule. |
type of type unsigned short, readonlyCSSRule interface to the specific derived
interface implied by the type.
cssText of type DOMString|
SYNTAX_ERR: Raised if the specified CSS string value has a syntax error and is unparsable. INVALID_MODIFICATION_ERR: Raised if the specified CSS string value represents a different type of rule than the current one. HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at this point in the style sheet. NO_MODIFICATION_ALLOWED_ERR: Raised if the rule is readonly. |
parentStyleSheet of type CSSStyleSheet, readonly
parentRule of type CSSRule, readonlynull.
The CSSStyleRule interface represents a single
rule set
in a CSS style sheet.
// Introduced in DOM Level 2:
interface CSSStyleRule : CSSRule {
attribute DOMString selectorText;
// raises(DOMException) on setting
readonly attribute CSSStyleDeclaration style;
};
selectorText of type DOMString|
SYNTAX_ERR: Raised if the specified CSS string value has a syntax error and is unparsable. NO_MODIFICATION_ALLOWED_ERR: Raised if this rule is readonly. |
style of type CSSStyleDeclaration, readonly
The CSSMediaRule interface represents a
@media
rule in a CSS style sheet. A @media rule can be
used to delimit style rules for specific media types.
// Introduced in DOM Level 2:
interface CSSMediaRule : CSSRule {
readonly attribute stylesheets::MediaList media;
readonly attribute CSSRuleList cssRules;
unsigned long insertRule(in DOMString rule,
in unsigned long index)
raises(DOMException);
void deleteRule(in unsigned long index)
raises(DOMException);
};
media of type stylesheets::MediaList, readonly
cssRules of type CSSRuleList, readonly
insertRule
| The parsable text representing the rule. For rule sets this contains both the selector and the style declaration. For at-rules, this specifies both the at-identifier and the rule content. | |||
|
| The index within the media block's rule collection of the rule before which to insert the specified rule. If the specified index is equal to the length of the media blocks's rule collection, the rule will be added to the end of the media block. |
|
The index within the media block's rule collection of the newly inserted rule. |
|
HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted
at the specified index. e.g. if an INDEX_SIZE_ERR: Raised if the specified index is not a valid insertion point. NO_MODIFICATION_ALLOWED_ERR: Raised if this media rule is readonly. SYNTAX_ERR: Raised if the specified rule has a syntax error and is unparsable. |
deleteRule
|
| The index within the media block's rule collection of the rule to remove. |
|
INDEX_SIZE_ERR: Raised if the specified index does not correspond to a rule in the media rule list. NO_MODIFICATION_ALLOWED_ERR: Raised if this media rule is readonly. |
The CSSFontFaceRule interface represents a
@font-face
rule in a CSS style sheet. The @font-face rule
is used to hold a set of font descriptions.
// Introduced in DOM Level 2:
interface CSSFontFaceRule : CSSRule {
readonly attribute CSSStyleDeclaration style;
};
style of type CSSStyleDeclaration, readonly
The CSSPageRule interface represents a
@page
rule within a CSS style sheet. The @page rule is
used to specify the dimensions, orientation, margins, etc. of a page box
for paged media.
// Introduced in DOM Level 2:
interface CSSPageRule : CSSRule {
attribute DOMString selectorText;
// raises(DOMException) on setting
readonly attribute CSSStyleDeclaration style;
};
selectorText of type DOMString|
SYNTAX_ERR: Raised if the specified CSS string value has a syntax error and is unparsable. NO_MODIFICATION_ALLOWED_ERR: Raised if this rule is readonly. |
style of type CSSStyleDeclaration, readonly
The CSSImportRule interface represents a
@import
rule within a CSS style sheet. The @import rule is
used to import style rules from other style sheets.
// Introduced in DOM Level 2:
interface CSSImportRule : CSSRule {
readonly attribute DOMString href;
readonly attribute stylesheets::MediaList media;
readonly attribute CSSStyleSheet styleSheet;
};
href of type DOMString, readonly"url(...)" specifier around the URI.
media of type stylesheets::MediaList, readonly
styleSheet of type CSSStyleSheet, readonlynull if the style sheet has not
yet been loaded or if it will not be loaded (e.g. if the style sheet is
for a media type not supported by the user agent).
The CSSCharsetRule interface represents a
@charset
rule in a CSS style sheet. The value of the
encoding attribute does not at all affect the encoding of
text data in the DOM objects; this encoding is always UTF-16. After a
stylesheet is loaded, the value of the encoding attribute is
the value found in the @charset rule. If there was no
@charset in the original document, then no
CSSCharsetRule is created. The value of the
encoding attribute may also be used as a hint for the
encoding used on serialization of the style sheet.
// Introduced in DOM Level 2:
interface CSSCharsetRule : CSSRule {
attribute DOMString encoding;
// raises(DOMException) on setting
};
The CSSUnknownRule interface represents an at-rule not
supported by this user agent.
// Introduced in DOM Level 2:
interface CSSUnknownRule : CSSRule {
};
The CSSStyleDeclaration interface represents a single
CSS declaration block. This interface may be used to determine the style properties
currently set in a block or to set style properties explicitly within
the block.
While an implementation may not recognize all CSS properties within
a CSS declaration block, it is expected to provide access to all specified
properties through the CSSStyleDeclaration interface.
Furthermore, implementations that support a specific level of CSS
should correctly handle
CSS shorthand properties for that level. For a further
discussion of shorthand properties, see the CSS2Properties
interface.
// Introduced in DOM Level 2:
interface CSSStyleDeclaration {
attribute DOMString cssText;
// raises(DOMException) on setting
DOMString getPropertyValue(in DOMString propertyName);
CSSValue getPropertyCSSValue(in DOMString propertyName);
DOMString removeProperty(in DOMString propertyName)
raises(DOMException);
DOMString getPropertyPriority(in DOMString propertyName);
void setProperty(in DOMString propertyName,
in DOMString value,
in DOMString priority)
raises(DOMException);
readonly attribute unsigned long length;
DOMString item(in unsigned long index);
readonly attribute CSSRule parentRule;
};
cssText of type DOMString|
SYNTAX_ERR: Raised if the specified CSS string value has a syntax error and is unparsable. NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is readonly or a property is readonly. |
length of type unsigned long, readonly
parentRule of type CSSRule, readonlynull
if this CSSStyleDeclaration is not attached to a
CSSRule.
getPropertyValue
| The name of the CSS property. See the CSS property index. |
|
Returns the value of the property if it has been explicitly set for this declaration block. Returns the empty string if the property has not been set. |
getPropertyCSSValuenull if the property is a
shorthand property. Shorthand
property values can only be accessed and modified as strings, using
the getPropertyValue and setProperty methods.
| The name of the CSS property. See the CSS property index. |
|
Returns the value of the property if it has been explicitly set for
this declaration block. Returns |
removeProperty
| The name of the CSS property. See the CSS property index. |
|
Returns the value of the property if it has been explicitly set for this declaration block. Returns the empty string if the property has not been set or the property name does not correspond to a valid CSS2 property. |
|
NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is readonly or the property is readonly. |
getPropertyPriority"important" qualifier) if the property
has been explicitly set in this declaration block.
| The name of the CSS property. See the CSS property index. |
|
A string representing the priority (e.g. |
setProperty
| The name of the CSS property. See the CSS property index. | |||
| The new value of the property. | |||
|
The new priority of the property (e.g. |
|
SYNTAX_ERR: Raised if the specified value has a syntax error and is unparsable. NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is readonly or the property is readonly. |
item
|
| Index of the property name to retrieve. |
|
The name of the property at this ordinal position. The empty string if no property exists at this position. |
The CSSValue interface represents a simple or a complex
value. A CSSValue object only occurs in a context of a CSS
property.
// Introduced in DOM Level 2:
interface CSSValue {
// UnitTypes
const unsigned short CSS_INHERIT = 0;
const unsigned short CSS_PRIMITIVE_VALUE = 1;
const unsigned short CSS_VALUE_LIST = 2;
const unsigned short CSS_CUSTOM = 3;
attribute DOMString cssText;
// raises(DOMException) on setting
readonly attribute unsigned short valueType;
};
An integer indicating which type of unit applies to the value.
| CSS_INHERIT | The value is inherited. |
| CSS_PRIMITIVE_VALUE |
The value is a primitive value and an instance of the
CSSPrimitiveValue interface can be obtained by using
binding-specific casting methods on this instance of the
CSSValue interface. |
| CSS_VALUE_LIST |
The value is a list CSSValue. |
| CSS_CUSTOM | The value is a custom value. |
cssText of type DOMString|
SYNTAX_ERR: Raised if the specified CSS string value has a syntax error (according to the attached property) or is unparsable. NO_MODIFICATION_ALLOWED_ERR: Raised if this value is readonly. |
valueType of type unsigned short, readonly
The CSSPrimitiveValue interface represents a single
CSS
value. This interface may be used to determine the value of a
specific style property currently set in a block or to set a specific
style property explicitly within the block. An instance of this interface
can be obtained from the getPropertyCSSValue method of the
CSSStyleDeclaration interface. A
CSSPrimitiveValue object only occurs in a context of a CSS
property.
Conversions are allowed between absolute values (from millimeters to
centimeters, from degrees to radians, and so on) but not between relative
values (for example, a pixel value can't be converted to a centimeter
value). Percentage values can't be converted since they are relative to
the parent value (or another property value). There is one exception with
color percentage values; since a color percentage value is relative to
the range 0-255, a color percentage value can be converted to a number
(see also the RGBColor interface).
// Introduced in DOM Level 2:
interface CSSPrimitiveValue : CSSValue {
// UnitTypes
const unsigned short CSS_UNKNOWN = 0;
const unsigned short CSS_NUMBER = 1;
const unsigned short CSS_PERCENTAGE = 2;
const unsigned short CSS_EMS = 3;
const unsigned short CSS_EXS = 4;
const unsigned short CSS_PX = 5;
const unsigned short CSS_CM = 6;
const unsigned short CSS_MM = 7;
const unsigned short CSS_IN = 8;
const unsigned short CSS_PT = 9;
const unsigned short CSS_PC = 10;
const unsigned short CSS_DEG = 11;
const unsigned short CSS_RAD = 12;
const unsigned short CSS_GRAD = 13;
const unsigned short CSS_MS = 14;
const unsigned short CSS_S = 15;
const unsigned short CSS_HZ = 16;
const unsigned short CSS_KHZ = 17;
const unsigned short CSS_DIMENSION = 18;
const unsigned short CSS_STRING = 19;
const unsigned short CSS_URI = 20;
const unsigned short CSS_IDENT = 21;
const unsigned short CSS_ATTR = 22;
const unsigned short CSS_COUNTER = 23;
const unsigned short CSS_RECT = 24;
const unsigned short CSS_RGBCOLOR = 25;
readonly attribute unsigned short primitiveType;
void setFloatValue(in unsigned short unitType,
in float floatValue)
raises(DOMException);
float getFloatValue(in unsigned short unitType)
raises(DOMException);
void setStringValue(in unsigned short stringType,
in DOMString stringValue)
raises(DOMException);
DOMString getStringValue()
raises(DOMException);
Counter getCounterValue()
raises(DOMException);
Rect getRectValue()
raises(DOMException);
RGBColor getRGBColorValue()
raises(DOMException);
};
An integer indicating which type of unit applies to the value.
| CSS_UNKNOWN |
The value is not a recognized CSS2 value. The value can only be
obtained by using the cssText attribute. |
| CSS_NUMBER |
The value is a simple
number.
The value can be obtained by using the getFloatValue method. |
| CSS_PERCENTAGE |
The value is a
percentage.
The value can be obtained by using the getFloatValue method. |
| CSS_EMS |
The value is
length
(ems). The value can be obtained by using the getFloatValue
method. |
| CSS_EXS |
The value is
length
(exs). The value can be obtained by using the getFloatValue
method. |
| CSS_PX |
The value is
length
(px). The value can be obtained by using the getFloatValue
method. |
| CSS_CM |
The value is
length
(cm). The value can be obtained by using the getFloatValue
method. |
| CSS_MM |
The value is
length
(mm). The value can be obtained by using the getFloatValue
method. |
| CSS_IN |
The value is
length
(in). The value can be obtained by using the getFloatValue
method. |
| CSS_PT |
The value is
length
(pt). The value can be obtained by using the getFloatValue
method. |
| CSS_PC |
The value is a
length
(pc). The value can be obtained by using the getFloatValue
method. |
| CSS_DEG |
The value is an
angle
(deg). The value can be obtained by using the getFloatValue
method. |
| CSS_RAD |
The value is an
angle
(rad). The value can be obtained by using the getFloatValue
method. |
| CSS_GRAD |
The value is an
angle
(grad). The value can be obtained by using the getFloatValue
method. |
| CSS_MS |
The value is a
time
(ms). The value can be obtained by using the getFloatValue
method. |
| CSS_S |
The value is a
time (s).
The value can be obtained by using the getFloatValue method. |
| CSS_HZ |
The value is a
frequency
(Hz). The value can be obtained by using the getFloatValue
method. |
| CSS_KHZ |
The value is a
frequency
(kHz). The value can be obtained by using the getFloatValue
method. |
| CSS_DIMENSION |
The value is a number with an unknown dimension.
The value can be obtained by using the getFloatValue method. |
| CSS_STRING |
The value is a
STRING.
The value can be obtained by using the getStringValue method. |
| CSS_URI |
The value is a
URI.
The value can be obtained by using the getStringValue method. |
| CSS_IDENT |
The value is an
identifier.
The value can be obtained by using the getStringValue method. |
| CSS_ATTR |
The value is a
attribute
function. The value can be obtained by using the getStringValue
method. |
| CSS_COUNTER |
The value is a
counter or
counters function. The value can be obtained by using the
getCounterValue method. |
| CSS_RECT |
The value is a
rect
function. The value can be obtained by using the getRectValue
method. |
| CSS_RGBCOLOR |
The value is a
RGB
color. The value can be obtained by using the getRGBColorValue
method. |
primitiveType of type unsigned short, readonly
setFloatValueDOMException will
be raised.
|
|
A unit code as defined above. The unit code can only be a float
unit type (e.g. | ||
|
| The new float value. |
|
INVALID_ACCESS_ERR: Raised if the attached property doesn't support the float value or the unit type. NO_MODIFICATION_ALLOWED_ERR: Raised if this property is readonly. |
getFloatValueDOMException is raised.
|
|
A unit code to get the float value. The unit code can only be a
float unit type (e.g. |
|
The float value in the specified unit. |
|
INVALID_ACCESS_ERR: Raised if the CSS value doesn't contain a float value or if the float value can't be converted into the specified unit. |
setStringValueDOMException will
be raised.
|
|
A string code as defined above. The string code can only be a
string unit type (e.g. | ||
| The new string value. |
|
INVALID_ACCESS_ERR: Raised if the CSS value doesn't contain a string value or if the string value can't be converted into the specified unit. NO_MODIFICATION_ALLOWED_ERR: Raised if this property is readonly. |
getStringValueDOMException
is raised.
Note: Some properties (like 'font-family' or 'voice-family') convert a whitespace separated list of idents to a string.
|
The string value in the current unit. The current
|
|
INVALID_ACCESS_ERR: Raised if the CSS value doesn't contain a string value. |
getCounterValueDOMException is
raised. Modification to the corresponding style property can be
achieved using the Counter interface.
|
The Counter value. |
|
INVALID_ACCESS_ERR: Raised if the CSS value doesn't contain a
Counter value (e.g. this is not |
getRectValueDOMException is
raised. Modification to the corresponding style property can be
achieved using the Rect interface.
|
The Rect value. |
|
INVALID_ACCESS_ERR: Raised if the CSS value doesn't contain a Rect
value. (e.g. this is not |
getRGBColorValueDOMException is
raised. Modification to the corresponding style property can be
achieved using the RGBColor interface.
|
the RGB color value. |
|
INVALID_ACCESS_ERR: Raised if the attached property can't return a
RGB color value (e.g. this is not |
The CSSValueList interface provides the abstraction of an
ordered collection of CSS values.
Some properties allow an empty list into their syntax. In that case,
these properties take the none identifier. So, an empty list
means that the property has the value none.
// Introduced in DOM Level 2:
interface CSSValueList : CSSValue {
readonly attribute unsigned long length;
CSSValue item(in unsigned long index);
};
item
|
| Index into the collection. |
|
The style rule at the |
The RGBColor interface is used to represent any
RGB
color value. This interface reflects the values in the
underlying style property. Hence, modifications made to the
CSSPrimitiveValue objects modify the style property.
A specified RGB color is not clipped (even if the number is outside the range 0-255 or 0%-100%). A computed RGB color is clipped depending on the device.
Even if a style sheet can only contain an integer for a color value, the internal storage of this integer is a float, and this can be used as a float in the specified or the computed style.
A color percentage value can always be converted to a number and vice versa.
// Introduced in DOM Level 2:
interface RGBColor {
readonly attribute CSSPrimitiveValue red;
readonly attribute CSSPrimitiveValue green;
readonly attribute CSSPrimitiveValue blue;
};
red of type CSSPrimitiveValue, readonly
green of type CSSPrimitiveValue, readonly
blue of type CSSPrimitiveValue, readonly
The Rect interface is used to represent any
rect
value. This interface reflects the values in the underlying style
property. Hence, modifications made to the CSSPrimitiveValue
objects modify the style property.
// Introduced in DOM Level 2:
interface Rect {
readonly attribute CSSPrimitiveValue top;
readonly attribute CSSPrimitiveValue right;
readonly attribute CSSPrimitiveValue bottom;
readonly attribute CSSPrimitiveValue left;
};
top of type CSSPrimitiveValue, readonly
right of type CSSPrimitiveValue, readonly
bottom of type CSSPrimitiveValue, readonly
left of type CSSPrimitiveValue, readonly
The Counter interface is used to represent any
counter or
counters function value. This interface reflects the values in
the underlying style property. Hence, modifications made to the
CSSPrimitiveValue objects modify the style property.
// Introduced in DOM Level 2:
interface Counter {
readonly attribute DOMString identifier;
readonly attribute DOMString listStyle;
readonly attribute DOMString separator;
};
This interface represents a CSS view. The getComputedStyle
method provides a read only access to the
computed values of
an element.
The expectation is that an instance of the ViewCSS
interface can be obtained by using binding-specific casting methods on an
instance of the View interface.
Since a computed style is related to an Element node, if
this element is removed from the document, the associated
CSSStyleDeclaration and CSSValue related to
this declaration are no longer valid.
// Introduced in DOM Level 2:
interface ViewCSS : views::AbstractView {
CSSStyleDeclaration getComputedStyle(in Element elt,
in DOMString pseudoElt);
};
getComputedStyle|
The computed style. The |
This interface represents a document with a CSS view.
The getOverrideStyle method provides a mechanism through
which a DOM author could effect immediate change to the style of an
element without modifying the explicitly linked stylesheets of a document
or the inline style of elements in the stylesheets. This style sheet
comes after the author style sheet in the cascade algorithm and is called
override style sheet. The override style sheet takes
precedence over author style sheet. An "!important" declaration still
takes precedence over a normal declaration. Both override and user style
sheets may contain "!important" declarations, and user "!important" rules
take precedence over override "!important" rules. Both author and
override style sheets may contain "!important" declarations, and override
"!important" rules takes precedence over author "!important" rules.
The expectation is that an instance of the DocumentCSS
interface can be obtained by using binding-specific casting methods on an
instance of the Document interface.
// Introduced in DOM Level 2:
interface DocumentCSS : stylesheets::DocumentStyle {
CSSStyleDeclaration getOverrideStyle(in Element elt,
in DOMString pseudoElt);
};
getOverrideStyle|
The override style declaration. |
This interface allows the DOM user to create a CSS style sheet outside the context of a document. There is no way to associate the new CSS style sheet with a document in DOM Level 2.
// Introduced in DOM Level 2:
interface DOMImplementationCSS : DOMImplementation {
CSSStyleSheet createCSSStyleSheet(in DOMString title,
inout DOMString media);
};
createCSSStyleSheet
| The advisory title. See also Style Sheet Interfaces. | |||
| The media associated with the new style sheet. See also Style Sheet Interfaces. |
|
A new CSS style sheet. |
Inline style information attached to elements is exposed through the
style attribute. This represents the contents of the
STYLE
attribute for HTML elements (or elements in other schemas or DTDs which use
the STYLE attribute in the same way).
// Introduced in DOM Level 2:
interface ElementCSSInlineStyle {
readonly attribute CSSStyleDeclaration style;
};
style of type CSSStyleDeclaration, readonly
The interfaces found within this section are not mandatory. A DOM
application can use the hasFeature method of the
DOMImplementation interface to determine whether they are
supported or not. The feature string for all the extended interfaces
listed in this section is "CSS2".
The following table specifies the type of CSSValue used
to represent each property that can be specified in a
CSSStyleDeclaration found in a CSSStyleRule for
a CSS Level 2 style sheet. The expectation is that the
CSSValue returned from the getPropertyCSSValue
method on the CSSStyleDeclaration interface can be
cast down, using binding-specific casting methods, to the specific
derived interface.
For properties that are represented by a custom interface (the
valueType of the CSSValue is
CSS_CUSTOM), the name of the derived interface is specified in
the table.
For properties that consist of lists of values (the valueType
of the CSSValue is CSS_VALUE_LIST), the
derived interface is CSSValueList. For all other
properties (the valueType
of the CSSValue is CSS_PRIMITIVE_VALUE), the
derived interface is CSSPrimitiveValue.
| Property Name | Representation |
| azimuth | CSS2Azimuth |
| background | null |
| background-attachment | ident |
| background-color | rgbcolor, ident |
| background-image | uri, ident |
| background-position | CSS2BackgroundPosition |
| background-repeat | ident |
| border | null |
| border-collapse | ident |
| border-color | null |
| border-spacing | CSS2BorderSpacing |
| border-style | null |
| border-top, border-right, border-bottom, border-left | null |
| border-top-color, border-right-color, border-bottom-color, border-left-color | rgbcolor, ident |
| border-top-style, border-right-style, border-bottom-style, border-left-style | ident |
| border-top-width, border-right-width, border-bottom-width, border-left-width | length, ident |
| border-width | null |
| bottom | length, percentage, ident |
| caption-side | ident |
| clear | ident |
| clip | rect, ident |
| color | rgbcolor, ident |
| content | list of string, uri, counter, attr, ident |
| counter-increment | list of CSS2CounterIncrement |
| counter-reset | list of CSS2CounterReset |
| cue | null |
| cue-after, cue-before | uri, ident |
| cursor | CSS2Cursor |
| direction | ident |
| display | ident |
| elevation | angle, ident |
| empty-cells | ident |
| float | ident |
| font | null |
| font-family | list of strings and idents |
| font-size | ident, length, percentage |
| font-size-adjust | number, ident |
| font-stretch | ident |
| font-style | ident |
| font-variant | ident |
| font-weight | ident |
| height | length, percentage, ident |
| left | length, percentage, ident |
| letter-spacing | ident, length |
| line-height | ident, length, percentage, number |
| list-style | null |
| list-style-image | uri, ident |
| list-style-position | ident |
| list-style-type | ident |
| margin | null |
| margin-top, margin-right, margin-bottom, margin-left | length, percentage, ident |
| marker-offset | length, ident |
| max-height | length, percentage, ident |
| max-width | length, percentage, ident |
| min-height | length, percentage, ident |
| min-width | length, percentage, ident |
| orphans | number |
| outline | null |
| outline-color | rgbcolor, ident |
| outline-style | ident |
| outline-width | length, ident |
| overflow | ident |
| padding | null |
| padding-top, padding-right, padding-bottom, padding-left | length, percentage |
| page | ident |
| page-break-after | ident |
| page-break-before | ident |
| page-break-inside | ident |
| pause | null |
| pause-after, pause-before | time, percentage |
| pitch | frequency, identifier |
| pitch-range | number |
| play-during | CSS2PlayDuring |
| position | ident |
| quotes | list of string or ident |
| richness | number |
| right | length, percentage, ident |
| speak | ident |
| speak-header | ident |
| speak-numeral | ident |
| speak-punctuation | ident |
| speech-rate | number, ident |
| stress | number |
| table-layout | ident |
| text-align | ident, string |
| text-decoration | list of ident |
| text-indent | length, percentage |
| text-shadow | list of CSS2TextShadow |
| text-transform | ident |
| top | length, percentage, ident |
| unicode-bidi | ident |
| vertical-align | ident, percentage, length |
| visibility | ident |
| voice-family | list of strings and idents |
| volume | number, percentage, ident |
| white-space | ident |
| widows | number |
| width | length, percentage, ident |
| word-spacing | length, ident |
| z-index | ident, number |
The CSS2Azimuth interface represents the
azimuth
CSS Level 2 property.
// Introduced in DOM Level 2:
interface CSS2Azimuth : CSSValue {
readonly attribute unsigned short azimuthType;
readonly attribute DOMString identifier;
readonly attribute boolean behind;
void setAngleValue(in unsigned short uType,
in float fValue)
raises(DOMException);
float getAngleValue(in unsigned short uType)
raises(DOMException);
void setIdentifier(in DOMString ident,
in boolean b)
raises(DOMException);
};
azimuthType of type unsigned short, readonlyCSSValue. It would be one of CSS_DEG,
CSS_RAD, CSS_GRAD or
CSS_IDENT.
identifier of type DOMString, readonlyazimuthType is CSS_IDENT,
identifier contains one of left-side, far-left, left,
center-left, center, center-right, right, far-right, right-side,
leftwards, rightwards. The empty string if none is set.
behind of type boolean, readonlybehind indicates whether the behind identifier has been
set.
setAngleValue
|
| The unitType could only be one of | ||
|
| The new float value of the angle. |
|
INVALID_ACCESS_ERR: Raised if the unit type is invalid. NO_MODIFICATION_ALLOWED_ERR: Raised if this property is readonly. |
getAngleValue
|
| The unit type can be only an angle unit type
( |
|
The float value. |
|
INVALID_ACCESS_ERR: Raised if the unit type is invalid. |
setIdentifierazimuthType is set
to CSS_IDENT
| The new identifier. If the identifier is "leftwards" or "rightward", the behind attribute is ignored. | |||
|
| The new value for behind. |
|
SYNTAX_ERR: Raised if the specified NO_MODIFICATION_ALLOWED_ERR: Raised if this property is readonly. |
The CSS2BackgroundPosition interface represents the
background-position
CSS Level 2 property.
// Introduced in DOM Level 2:
interface CSS2BackgroundPosition : CSSValue {
readonly attribute unsigned short horizontalType;
readonly attribute unsigned short verticalType;
readonly attribute DOMString horizontalIdentifier;
readonly attribute DOMString verticalIdentifier;
float getHorizontalPosition(in float hType)
raises(DOMException);
float getVerticalPosition(in float vType)
raises(DOMException);
void setHorizontalPosition(in unsigned short hType,
in float value)
raises(DOMException);
void setVerticalPosition(in unsigned short vType,
in float value)
raises(DOMException);
void setPositionIdentifier(in DOMString hIdentifier,
in DOMString vIdentifier)
raises(DOMException);
};
horizontalType of type unsigned short, readonlyCSS_PERCENTAGE, CSS_EMS,
CSS_EXS, CSS_PX, CSS_CM,
CSS_MM, CSS_IN, CSS_PT,
CSS_PC or CSS_IDENT. If one of horizontal or
vertical is CSS_IDENT, it's guaranteed that the other is
the same.
verticalType of type unsigned short, readonlyCSS_PERCENTAGE,
CSS_EMS, CSS_EXS, CSS_PX,
CSS_CM, CSS_MM, CSS_IN,
CSS_PT, CSS_PC, CSS_IDENT,
CSS_INHERIT. If one of horizontal or vertical is
CSS_IDENT or CSS_INHERIT, it's guaranteed
that the other is the same.
horizontalIdentifier of type DOMString, readonlyhorizontalType is CSS_IDENT or
CSS_INHERIT, this attribute contains the string
representation of the ident, otherwise it contains an empty string.
verticalIdentifier of type DOMString, readonlyverticalType is CSS_IDENT or
CSS_INHERIT, this attribute contains the string
representation of the ident, otherwise it contains an empty string. The
value is "center" if only the horizontalIdentifier has
been set.
getHorizontalPositionhorizontalPosition represents a length or a percentage. If
the float doesn't contain a float value or can't be converted into the
specified unit, a DOMException is raised.
|
| The horizontal unit. |
|
The float value. |
|
INVALID_ACCESS_ERR: Raised if the property doesn't contain a float or the value can't be converted. |
getVerticalPositionverticalPosition represents a length or a percentage. If the
float doesn't contain a float value or can't be converted into the
specified unit, a DOMException is raised. The value is
50% if only the horizontal value has been specified.
|
| The vertical unit. |
|
The float value. |
|
INVALID_ACCESS_ERR: Raised if the property doesn't contain a float or the value can't be converted. |
setHorizontalPosition50%.
|
| The specified unit (a length or a percentage). | ||
|
| The new value. |
|
INVALID_ACCESS_ERR: Raised if the specified unit is not a length or a percentage. NO_MODIFICATION_ALLOWED_ERR: Raised if this property is readonly. |
setVerticalPosition50%.
|
| The specified unit (a length or a percentage). | ||
|
| The new value. |
|
INVALID_ACCESS_ERR: Raised if the specified unit is not a length or a percentage. NO_MODIFICATION_ALLOWED_ERR: Raised if this property is readonly. |
setPositionIdentifier"center").|
SYNTAX_ERR: Raised if the identifiers have a syntax error and is unparsable. NO_MODIFICATION_ALLOWED_ERR: Raised if this property is readonly. |
The CSS2BorderSpacing interface represents the
border-spacing
CSS Level 2 property.
// Introduced in DOM Level 2:
interface CSS2BorderSpacing : CSSValue {
readonly attribute unsigned short horizontalType;
readonly attribute unsigned short verticalType;
float getHorizontalSpacing(in float hType)
raises(DOMException);
float getVerticalSpacing(in float vType)
raises(DOMException);
void setHorizontalSpacing(in unsigned short hType,
in float value)
raises(DOMException);
void setVerticalSpacing(in unsigned short vType,
in float value)
raises(DOMException);
};
horizontalType of type unsigned short, readonlyCSSValue. It would be one of CSS_EMS,
CSS_EXS, CSS_PX, CSS_CM,
CSS_MM, CSS_IN, CSS_PT or
CSS_PC.
verticalType of type unsigned short, readonlyCSSValue. It would be one of CSS_EMS,
CSS_EXS, CSS_PX, CSS_CM,
CSS_MM, CSS_IN, CSS_PT,
CSS_PC or CSS_INHERIT.
getHorizontalSpacinghorizontalSpacing represents a length. If the float doesn't
contain a float value or can't be converted into the specified unit, a
DOMException is raised.
|
| The horizontal unit. |
|
The float value. |
|
INVALID_ACCESS_ERR: Raised if the property doesn't contain a float or the value can't be converted. |
getVerticalSpacingverticalSpacing represents a length. If the float doesn't
contain a float value or can't be converted into the specified unit, a
DOMException is raised. The value is 0 if only
the horizontal value has been specified.
|
| The vertical unit. |
|
The float value. |
|
INVALID_ACCESS_ERR: Raised if the property doesn't contain a float or the value can't be converted. |
setHorizontalSpacing0.
|
| The horizontal unit. | ||
|
| The new value. |
|
INVALID_ACCESS_ERR: Raised if the specified unit is not a length. NO_MODIFICATION_ALLOWED_ERR: Raised if this property is readonly. |
setVerticalSpacing0.
|
| The vertical unit. | ||
|
| The new value. |
|
INVALID_ACCESS_ERR: Raised if the specified unit is not a length or a percentage. NO_MODIFICATION_ALLOWED_ERR: Raised if this property is readonly. |
The CSS2CounterReset interface represents a simple value
for the
counter-reset
CSS Level 2 property.
// Introduced in DOM Level 2:
interface CSS2CounterReset : CSSValue {
attribute DOMString identifier;
// raises(DOMException) on setting
attribute short reset;
// raises(DOMException) on setting
};
identifier of type DOMString|
SYNTAX_ERR: Raised if the specified identifier has a syntax error and is unparsable. NO_MODIFICATION_ALLOWED_ERR: Raised if this identifier is readonly. |
reset of type short|
NO_MODIFICATION_ALLOWED_ERR: Raised if this identifier is readonly. |
The CSS2CounterIncrement interface represents a simple value
for the
counter-increment
CSS Level 2 property.
// Introduced in DOM Level 2:
interface CSS2CounterIncrement : CSSValue {
attribute DOMString identifier;
// raises(DOMException) on setting
attribute short increment;
// raises(DOMException) on setting
};
identifier of type DOMString|
SYNTAX_ERR: Raised if the specified identifier has a syntax error and is unparsable. NO_MODIFICATION_ALLOWED_ERR: Raised if this identifier is readonly. |
increment of type short|
NO_MODIFICATION_ALLOWED_ERR: Raised if this identifier is readonly. |
The CSS2Cursor interface represents the
cursor
CSS Level 2 property.
// Introduced in DOM Level 2:
interface CSS2Cursor : CSSValue {
readonly attribute CSSValueList uris;
attribute DOMString predefinedCursor;
// raises(DOMException) on setting
};
uris of type CSSValueList, readonlyuris represents the list of URIs (CSS_URI)
on the cursor property. The list can be empty.
predefinedCursor of type DOMString|
SYNTAX_ERR: Raised if the specified CSS string value has a syntax error and is unparsable. NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is readonly. |
The CSS2PlayDuring interface represents the
play-during
CSS Level 2 property.
// Introduced in DOM Level 2:
interface CSS2PlayDuring : CSSValue {
readonly attribute unsigned short playDuringType;
attribute DOMString playDuringIdentifier;
// raises(DOMException) on setting
attribute DOMString uri;
// raises(DOMException) on setting
attribute boolean mix;
// raises(DOMException) on setting
attribute boolean repeat;
// raises(DOMException) on setting
};
playDuringType of type unsigned short, readonlyCSSvalue. It would be one of CSS_UNKNOWN or
CSS_IDENT.
playDuringIdentifier of type DOMString"inherit", "auto",
"none" or the empty string if the
playDuringType is CSS_UNKNOWN. On setting, it
will set the uri to the empty string and mix
and repeat to false.
|
SYNTAX_ERR: Raised if the specified CSS string value has a syntax error and is unparsable. NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is readonly. |
uri of type DOMStringuri. It will set the
playDuringType attribute to CSS_UNKNOWN.
|
SYNTAX_ERR: Raised if the specified CSS string value has a syntax error and is unparsable. NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is readonly. |
mix of type booleantrue if the sound should be mixed. It will be ignored if
the attribute doesn't contain a uri.
|
NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is readonly. |
repeat of type booleantrue if the sound should be repeated. It will be ignored
if the attribute doesn't contain a uri.
|
NO_MODIFICATION_ALLOWED_ERR: Raised if this declaration is readonly. |
The CSS2TextShadow interface represents a simple value for
the
text-shadow
CSS Level 2 property.
// Introduced in DOM Level 2:
interface CSS2TextShadow {
readonly attribute CSSValue color;
readonly attribute CSSValue horizontal;
readonly attribute CSSValue vertical;
readonly attribute CSSValue blur;
};
color of type CSSValue, readonly
horizontal of type CSSValue, readonly0 if no
length has been specified.
vertical of type CSSValue, readonly0 if no
length has been specified.
blur of type CSSValue, readonly0 if no
length has been specified.
The following table specifies the type of CSSValue used
to represent each descriptor that can be specified in a