Screen
The Screen
interface represents a screen, usually the one on which the current window is being rendered, and is obtained using window.screen
.
Note that browsers determine which screen to report as current by detecting which screen has the center of the browser window.
Properties
-
Screen.availTop
-
Specifies the y-coordinate of the first pixel that is not allocated to permanent or semipermanent user interface features.
-
Screen.availLeft
-
Returns the first available pixel available from the left side of the screen.
Screen.availHeight
-
Specifies the height of the screen, in pixels, minus permanent or semipermanent user interface features displayed by the operating system, such as the Taskbar on Windows.
Screen.availWidth
-
Returns the amount of horizontal space in pixels available to the window.
Screen.colorDepth
-
Returns the color depth of the screen.
Screen.height
-
Returns the height of the screen in pixels.
-
Screen.left
-
Returns the distance in pixels from the left side of the main screen to the left side of the current screen.
Screen.orientation
-
Returns the
ScreenOrientation
instance associated with this screen. Screen.pixelDepth
-
Gets the bit depth of the screen.
-
Screen.top
-
Returns the distance in pixels from the top side of the current screen.
Screen.width
-
Returns the width of the screen.
-
Screen.mozEnabled
-
Boolean. Setting to false will turn off the device's screen.
-
Screen.mozBrightness
-
Controls the brightness of a device's screen. A double between 0 and 1.0 is expected.
Events handler
-
Screen.onorientationchange
-
A handler for the
orientationchange
event.
Methods
-
Screen.lockOrientation
-
Lock the screen orientation (only works in fullscreen or for installed apps)
-
Screen.unlockOrientation
-
Unlock the screen orientation (only works in fullscreen or for installed apps)
Methods inherited from EventTarget
:
EventTarget.addEventListener()
-
Registers an event handler of a specific event type on the
EventTarget
. EventTarget.removeEventListener()
-
Removes an event listener from the
EventTarget
. EventTarget.dispatchEvent()
-
Dispatches an event to this
EventTarget
.
Example
if (screen.pixelDepth < 8) { // use low-color version of page } else { // use regular, colorful page }
Specifications
Specification |
---|
CSSOM View Module (CSSOM View) # the-screen-interface |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
Screen |
1 |
12 |
1 |
4 |
≤12.1 |
1 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
availHeight |
1 |
12
Always reflects the main screen.
|
1 |
4 |
≤12.1 |
1 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
availLeft |
1 |
79 |
1 |
No |
15 |
1 |
1 |
18 |
4 |
14 |
1 |
1.0 |
availTop |
1 |
79 |
1 |
No |
15 |
1 |
1 |
18 |
4 |
14 |
1 |
1.0 |
availWidth |
1 |
12
Always reflects the main screen.
|
1 |
4 |
≤12.1 |
1 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
colorDepth |
1
Starting with version 59 this property is no longer required to always return 24.
|
12 |
1 |
4 |
≤12.1 |
1 |
1
Starting with version 59 this property is no longer required to always return 24.
|
18
Starting with version 59 this property is no longer required to always return 24.
|
4 |
≤12.1 |
1 |
1.0
Starting with Samsung Internet 7.0 this property is no longer required to always return 24.
|
height |
1 |
12 |
1 |
4 |
≤12.1 |
1 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
left |
No |
≤18-79 |
1 |
No |
No |
No |
No |
No |
4 |
No |
No |
No |
lockOrientation |
38 |
12 |
14 |
11 |
Yes |
No |
38 |
38 |
14 |
Yes |
No |
3.0 |
mozBrightness |
No |
No |
12 |
No |
No |
No |
No |
No |
14 |
No |
No |
No |
mozEnabled |
No |
No |
12 |
No |
No |
No |
No |
No |
14 |
No |
No |
No |
onorientationchange |
No |
≤18-79 |
No |
No |
No |
No |
No |
No |
Yes |
No |
No |
No |
orientation |
38 |
79
12
Edge does not return an
Orientation object; instead, it returns the orientation type as a string. |
43
14
|
11
Not supported on Windows 7.
|
25 |
No |
No |
39 |
43
14
|
No |
No |
4.0 |
pixelDepth |
1
Starting with version 59 this property is no longer required to always return 24.
|
12 |
1 |
9 |
≤12.1 |
1 |
1
Starting with version 59 this property is no longer required to always return 24.
|
18
Starting with version 59 this property is no longer required to always return 24.
|
4 |
≤12.1 |
1 |
1.0
Starting with Samsung Internet 7.0 this property is no longer required to always return 24.
|
top |
No |
≤18-79 |
1 |
No |
No |
No |
No |
No |
4 |
No |
No |
No |
unlockOrientation |
38 |
12 |
14 |
11 |
Yes |
No |
38 |
38 |
14 |
Yes |
No |
3.0 |
width |
1 |
12 |
1 |
4 |
≤12.1 |
1 |
1 |
18 |
4 |
≤12.1 |
1 |
1.0 |
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Screen