W3C DOM Compatibility - CSS Object Model View

Last major update on 14 November 2008.

Desktop table.

These compatibility tables detail support for the W3C CSSOM View specification in all modern browsers.

  1. WindowView properties.
  2. ScreenView properties.
  3. DocumentView and ElementView methods.
  4. ElementView properties.
  5. Mouse position.

WindowView properties

These properties hold the dimensions of the entire browser window.

Selector Opera Mobile Opera Mini 4.2 S60 WebKit Apple WebKit Other WebKit NetFront Blackberry IE Mobile Skyfire
(VF WM) Nokia E66 (9.5) HTC Touch Diamond (8.65) SE P1i (8.00) Motorola V3xx Nokia E71 Nokia E66 Nokia E71 Nokia N95 Samsung i560 iPhone Android Bolt (E71) Iris (HTC) Samsung F700 Sony Ericsson K770i Sony Ericsson C510 Blackberry 9500 HTC Touch Diamond Nokia E71
innerWidth and innerHeight
The dimensions of the viewport (interior of the browser window)

Test page
To be tested Incorrect To be tested To be tested Yes Yes To be tested To be tested Yes Incorrect Yes To be tested To be tested Yes Incorrect To be tested To be tested
window.innerWidth
window.innerHeight
  • iPhone gives the dimensions of the current zoom area.
  • Blackberry gives an innerHeight that’s larger than the total screen height.
  • Bolt gives weird numbers that are larger than the reported screen.width/height.
outerWidth and outerHeight
The dimensions of the entire browser window (including taskbars and such)

Test page
To be tested Incorrect To be tested To be tested Yes 0 To be tested Incorrect Yes Incorrect To be tested To be tested No No To be tested To be tested
window.outerWidth
window.outerHeight
  • iPhone always gives 320 x 396 independent of orientation
  • Bolt gives weird numbers. The 400 for the outerWidth is definitely incorrect.
pageXOffset and pageYOffset
The amount of pixels the entire pages has been scrolled

Test page
To be tested Incorrect To be tested To be tested 0 Yes To be tested Yes 0 Yes To be tested To be tested Yes No To be tested To be tested
window.pageXOffset
window.pageYOffset
  • iPhone counts a zoom as a scroll.
screenX and screenY
The position of the browser window on the screen

Test page
To be tested 0 To be tested To be tested 0 0 To be tested 0 Incorrect 0 Incorrect To be tested To be tested No No To be tested To be tested
window.screenX
window.screenY

On mobiles we generally expect the value 0 because the browser screen takes the entire screen.

  • Iris’ screenY of 52 is incorrect.
  • Android gives the same values as pageX/YOffset
Selector Opera Mobile Opera Mini 4.2 S60 WebKit Apple WebKit Other WebKit NetFront Blackberry IE Mobile Skyfire
(VF WM) Nokia E66 (9.5) HTC Touch Diamond (8.65) SE P1i (8.00) Motorola V3xx Nokia E71 Nokia E66 Nokia E71 Nokia N95 Samsung i560 iPhone Android Bolt (E71) Iris (HTC) Samsung F700 Sony Ericsson K770i Sony Ericsson C510 Blackberry 9500 HTC Touch Diamond Nokia E71

ScreenView properties

These properties hold information about the screen.

Selector Opera Mobile Opera Mini 4.2 S60 WebKit Apple WebKit Other WebKit NetFront Blackberry IE Mobile Skyfire
(VF WM) Nokia E66 (9.5) HTC Touch Diamond (8.65) SE P1i (8.00) Motorola V3xx Nokia E71 Nokia E66 Nokia E71 Nokia N95 Samsung i560 iPhone Android Bolt (E71) Iris (HTC) Samsung F700 Sony Ericsson K770i Sony Ericsson C510 Blackberry 9500 HTC Touch Diamond Nokia E71
availWidth and availHeight
The available width and height on the screen (excluding OS taskbars and such)

Test page
To be tested Yes To be tested To be tested eq. width/h eq. width/h To be tested Yes eq. width/h Incorrect To be tested To be tested eq. width/h eq. width/h To be tested To be tested
screen.availWidth
screen.availHeight
colorDepth
The color depth (in bits) of the screen

Test page
To be tested 16 To be tested To be tested 32 16 To be tested Yes 16 32 16 To be tested To be tested 16 16 To be tested 32
screen.colorDepth
pixelDepth
Same as colorDepth

Test page
To be tested 16 To be tested To be tested 32 16 To be tested Yes 16 32 16 To be tested To be tested 16 16 To be tested 32
screen.pixelDepth

The difference between colorDepth and pixelDepth is only important on (older?) Unix machines, where old X-clients may allow applications to define their own color scheme. If that’s the case, colorDepth matches the color depth of the application and pixelDepth the color depth of the monitor. In all other cases they’re equal.

width and height
The width and height of the screen

Test page
To be tested Yes To be tested To be tested Yes Yes To be tested Yes Incorrect To be tested To be tested Yes Yes To be tested To be tested
screen.width
screen.height
  • I distrust Bolt’s 800x800, because the screen is not square and these numbers don’t agree with the page width and height.
  • I also distrust Iris’ 640x480.
Selector Opera Mobile Opera Mini 4.2 S60 WebKit Apple WebKit Other WebKit NetFront Blackberry IE Mobile Skyfire
(VF WM) Nokia E66 (9.5) HTC Touch Diamond (8.65) SE P1i (8.00) Motorola V3xx Nokia E71 Nokia E66 Nokia E71 Nokia N95 Samsung i560 iPhone Android Bolt (E71) Iris (HTC) Samsung F700 Sony Ericsson K770i Sony Ericsson C510 Blackberry 9500 HTC Touch Diamond Nokia E71

DocumentView and ElementView methods

Selector Opera Mobile Opera Mini 4.2 S60 WebKit Apple WebKit Other WebKit NetFront Blackberry IE Mobile Skyfire
(VF WM) Nokia E66 (9.5) HTC Touch Diamond (8.65) SE P1i (8.00) Motorola V3xx Nokia E71 Nokia E66 Nokia E71 Nokia N95 Samsung i560 iPhone Android Bolt (E71) Iris (HTC) Samsung F700 Sony Ericsson K770i Sony Ericsson C510 Blackberry 9500 HTC Touch Diamond Nokia E71
elementFromPoint()
Returns the element located at the given coordinates

Test page
To be tested Incorrect To be tested To be tested Untestable Yes To be tested Yes Alternative Untestable Alternative To be tested To be tested No No To be tested To be tested
document.elementFromPoint(100,100)

Which coordinates does elementFromPoint() need? In general browsers work with clientX/Y.

Alternative: Browser uses pageX/Y instead.

  • Opera reports a text node whenever possible, while this method should report the containing element node.
  • Iris always reports the HTML element.

This method is a godsend for drag and drop scripts. When the user drops the dragged element, figure out what element is located at the drop point and go on from there. No more complicated calculations necessary.

However, you need to temporarily hide the dragged object. By definition it's the topmost element on the requested coordinates, and we need to know what's underneath it. The basic trick is:

releaseElement: function(e) { // called onmouseup
	var evt = e || window.event;
	draggedObject.style.display = 'none';
	var receiver = document.elementFromPoint(evt.clientX,evt.clientY);
	if (receiver.nodeType == 3) { // Opera
		receiver = receiver.parentNode;
	}
	draggedObject.style.display = '';
	

Now receiver contains the element the user dropped the dragged element on.

getBoundingClientRect()
Gets the encompassing rectangle

Test page
To be tested Possibly correct To be tested To be tested Untestable No To be tested No Untestable No To be tested To be tested No No To be tested To be tested
x.getBoundingClientRect()

Returns an object that contains the top, left, right, and bottom (all relative to the top left of the viewport) of the combined rectangle of element x. Essentially, the browser calculates all rectangles (see below getClientRects()), and getBoundingClientRect() returns the lowest (top, left) or highest (bottom, right) values found.

IE handles this correctly, provided you accept its incorrect calculation of the individual rectangles.

  • Firefox doesn't round the top/bottom coordinates.
  • I think Opera HTC does this right, but it reacts so poorly to the test that I can’t say for sure.
getClientRects()
Gets the several rectangles of an element

Test page
To be tested Possibly correct To be tested To be tested Untestable No To be tested No Untestable No To be tested To be tested No No To be tested To be tested
x.getClientRects()

Returns a list with Rectangle objects that contain the top, left, right, and bottom (all relative to the top left of the viewport) of the rectangles of element x.

The trick here is, that an inline element such as an <em> contains one rectangle for every inline box (line), and that all these rectangles are returned.

  • Firefox doesn't round the top/bottom coordinates.
scrollIntoView()

Makes an element scroll into view

(Not part of the specification)



Test page
To be tested Incomplete To be tested To be tested No Yes Incomplete Yes To be tested Incomplete Yes No Yes To be tested To be tested No No To be tested To be tested
x.scrollIntoView()

Element x scrolls into view.

Essentially element x behaves as if it's the target of an #hash: it scrolls to the topmost, leftmost position allowed.

  • Incomplete: browser handles the Y-coordinate correctly, but it also scrolls to the left edge of the page, which can make this method hard to use when the user has zoomed in.
Selector Opera Mobile Opera Mini 4.2 S60 WebKit Apple WebKit Other WebKit NetFront Blackberry IE Mobile Skyfire
(VF WM) Nokia E66 (9.5) HTC Touch Diamond (8.65) SE P1i (8.00) Motorola V3xx Nokia E71 Nokia E66 Nokia E71 Nokia N95 Samsung i560 iPhone Android Bolt (E71) Iris (HTC) Samsung F700 Sony Ericsson K770i Sony Ericsson C510 Blackberry 9500 HTC Touch Diamond Nokia E71

ElementView properties

These properties give information about the dimensions of an Element node (HTML tag).

Selector Opera Mobile Opera Mini 4.2 S60 WebKit Apple WebKit Other WebKit NetFront Blackberry IE Mobile Skyfire
(VF WM) Nokia E66 (9.5) HTC Touch Diamond (8.65) SE P1i (8.00) Motorola V3xx Nokia E71 Nokia E66 Nokia E71 Nokia N95 Samsung i560 iPhone Android Bolt (E71) Iris (HTC) Samsung F700 Sony Ericsson K770i Sony Ericsson C510 Blackberry 9500 HTC Touch Diamond Nokia E71
clientLeft and clientTop
The position of the upper left corner of the content field relative to the upper left corner of the entire element (including borders)

Test page
To be tested Yes To be tested To be tested Yes No To be tested Yes To be tested To be tested No No To be tested To be tested
x.clientLeft
x.clientTop
clientWidth and clientHeight
The width and height of the content field, excluding border and scrollbar, but including padding

Test page
To be tested Yes To be tested To be tested Yes Yes To be tested Yes Almost Incorrect Yes To be tested To be tested Yes No To be tested To be tested
x.clientWidth
x.clientHeight
  • Bolt counts the scrollbars as part of the clientWidth/Height.
  • Android G1 subtracts space for scrollbars even though it doesn’t show any.
offsetLeft and offsetTop
The left and top position of the element relative to its offsetParent.

Test page
To be tested Yes To be tested To be tested Untestable Yes To be tested Yes To be tested To be tested Yes Yes To be tested To be tested
x.offsetLeft
x.offsetTop
Selector Opera Mobile Opera Mini 4.2 S60 WebKit Apple WebKit Other WebKit NetFront Blackberry IE Mobile Skyfire
(VF WM) Nokia E66 (9.5) HTC Touch Diamond (8.65) SE P1i (8.00) Motorola V3xx Nokia E71 Nokia E66 Nokia E71 Nokia N95 Samsung i560 iPhone Android Bolt (E71) Iris (HTC) Samsung F700 Sony Ericsson K770i Sony Ericsson C510 Blackberry 9500 HTC Touch Diamond Nokia E71
offsetParent
The ancestor element relative to which the offsetLeft/Top are calculated.

Test page
To be tested Yes To be tested To be tested Untestable Yes To be tested Yes Untestable Yes To be tested To be tested Yes Incorrect To be tested To be tested
x.offsetParent

When calculating the offsetParent of x the browser moves up the DOM tree to x's ancestors until it encounters one of the following elements. That element becomes x's offsetParent.

  • <body>
  • An element with a position other than static.
  • A <table>, <th> or <td>, but only if x has position: static.

The <body> element does not have an offsetParent. Nonetheless the <html> element sometimes enters the offsetParent chain, though never as the offsetParent of the <body>.

In IE and Opera elements with position: fixed do not have an offsetParent.

  • Blackberry takes the text node as a target, which messes up my test script. It also always reports table elements, even if the target does not have position: static.
offsetWidth and offsetHeight
The width and height of the entire element, including borders

Test page
To be tested Yes To be tested To be tested Yes Yes To be tested Yes To be tested To be tested Yes Incorrect To be tested To be tested
x.offsetWidth
x.offsetHeight
  • Blackberry only measures content width and height.
scrollLeft and scrollTop
The amount of pixels the element has scrolled. Read/write.

Test page
To be tested 0 To be tested To be tested 0 Yes To be tested Yes 0 0 0 To be tested To be tested 0 No To be tested To be tested
x.scrollLeft
x.scrollTop
x.scrollTop = 20

I consider 0 correct if the browser is unable to scroll elements with overflow: auto, and incorrect if it is able to do so.

scrollWidth and scrollHeight
The width and height of the entire content field, including those parts that are currently hidden.
If there's no hidden content it should be equal to clientX/Y.

Test page
To be tested Yes To be tested To be tested Incorrect Yes To be tested Yes To be tested To be tested Incorrect No To be tested To be tested
x.scrollWidth
x.scrollHeight

When you scroll the element all the way down, scrollHeight should be equal to scrollTop + clientHeight.

If the element has no scrollbars scrollWidth/Height should be equal to clientWidth/Height.

  • When the element has no scrollbars IE makes the scrollHeight equal to the actual height of the content; and not the height of the element. scrollWidth is correct, except in IE8, where it’s 5 pixels off.
  • Opera doesn't include the element's padding.
  • NetFront SE C510 always makes scrollWidth/Height equal to offsetWidth/Height.
Selector Opera Mobile Opera Mini 4.2 S60 WebKit Apple WebKit Other WebKit NetFront Blackberry IE Mobile Skyfire
(VF WM) Nokia E66 (9.5) HTC Touch Diamond (8.65) SE P1i (8.00) Motorola V3xx Nokia E71 Nokia E66 Nokia E71 Nokia N95 Samsung i560 iPhone Android Bolt (E71) Iris (HTC) Samsung F700 Sony Ericsson K770i Sony Ericsson C510 Blackberry 9500 HTC Touch Diamond Nokia E71