We have safe-area-inset-left, safe-area-inset-right, safe-area-inset-top, and safe-area-inset-bottom in CSS, but how can we get those values using JavaScript?
From https://benfrain.com/how-to-get-the-value-of-phone-notches-environment-variables-env-in-javascript-from-css/. You can find more context in the link.
Within CSS
:root {
    --sat: env(safe-area-inset-top);
    --sar: env(safe-area-inset-right);
    --sab: env(safe-area-inset-bottom);
    --sal: env(safe-area-inset-left);
}
Within JS
getComputedStyle(document.documentElement).getPropertyValue("--sat")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With