Back to Content

DevicePosture

files/en-us/web/api/deviceposture/index.md

latest1.3 KB
Original Source

{{APIRef("Device Posture API")}}{{SeeCompatTable}}

The DevicePosture interface of the {{domxref("Device Posture API", "Device Posture API", "", "nocode")}} represents the device's posture, that is, whether the viewport is in a flat or folded state.

{{InheritanceDiagram}}

Instance properties

Inherits properties from its parent, {{DOMxRef("EventTarget")}}.

  • {{domxref("DevicePosture.type", "type")}} {{ReadOnlyInline}} {{Experimental_Inline}}
    • : Returns the device's current posture.

Events

  • {{domxref("DevicePosture.change_event", "change")}} {{Experimental_Inline}}
    • : Fires when the device's posture changes.

Examples

js
const postureOutput = document.getElementById("currentPosture");

function reportPostureOutput() {
  // type property returns "continuous" or "folded"
  postureOutput.textContent = `Device posture: ${navigator.devicePosture.type}`;
}

navigator.devicePosture.addEventListener("change", reportPostureOutput);

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also