Tailwind CSS safe area helpers
npm install tailwindcss-safe-areaTailwind CSS utilities for safe areas.
- Responsive safe area utilities tailored for margin, padding, height and position
- Flexible spacing helpers using offset and or variants that adapt to safe areas
- Modern CSS support including logical properties and scroll snap
``sh`
npm install tailwindcss-safe-area
Import the CSS plugin directly in your main CSS file:
`css`
@import "tailwindcss";
@import "tailwindcss-safe-area";
_Note: we use @import above rather than @plugin_
`sh`Latest version with v3 support
npm install tailwindcss-safe-area@0.8.0
Then add the plugin to your tailwind.config.js file:
`js`
// tailwind.config.js
module.exports = {
theme: {},
plugins: [require("tailwindcss-safe-area")],
};
To extend content behind the safe area, add or append viewport-fit=cover to your viewport meta tag:
`html`
name="viewport"
content="width=device-width, initial-scale=1, viewport-fit=cover"
/>
Handle safe area margin, padding, height and position:
`html`
Extend base utilities with an additional offset:
`html`...
This adds right padding equal to the safe area plus 4.
Apply a minimum value while respecting the safe area:
`html`...
This adds bottom padding equal to the larger of the safe area or 8.
- m-safe, mx-safe, my-safe, ms-safe, me-safemt-safe
- , mr-safe, mb-safe, ml-safep-safe
- , px-safe, py-safe, ps-safe, pe-safept-safe
- , pr-safe, pb-safe, pl-safe
With variants:
- Add -offset-{value} for additional spacing (e.g. pt-safe-offset-4)-or-{value}
- Add for minimum values (e.g. pb-safe-or-8)
Same as margin/padding utilities, prefixed with scroll-:
- scroll-m-safe, scroll-mx-safe, scroll-my-safe, etc.scroll-p-safe
- , scroll-px-safe, scroll-py-safe, etc.
Screen utilities:
- h-screen-safe, min-h-screen-safe, max-h-screen-safe
Viewport utilities:
- h-vh-safe, h-dvh-safe, h-svh-safe, h-lvh-safemin-h-vh-safe
- , min-h-dvh-safe, min-h-svh-safe, min-h-lvh-safemax-h-vh-safe
- , max-h-dvh-safe, max-h-svh-safe, max-h-lvh-safe
-webkit-fill-available utilities:
- h-fill-safe, min-h-fill-safe, max-h-fill-safe
- inset-safe, inset-x-safe, inset-y-safestart-safe
- , end-safetop-safe
- , right-safe, bottom-safe, left-safe
With variants:
- Add -offset-{value} for additional spacing (e.g., top-safe-offset-4)-or-{value}
- Add for minimum values (e.g., inset-safe-or-8)
- border-safe, border-x-safe, border-y-safeborder-s-safe
- , border-e-safeborder-t-safe
- , border-r-safe, border-b-safe, border-l-safe
With variants:
- Add -offset-{value} for additional spacing (e.g., border-t-safe-offset-4)-or-{value}
- Add for minimum values (e.g., border-safe-or-8)
- safe, safe-x, safe-ysafe-t
- , safe-r, safe-b, safe-lsafe-none
- , safe-x-none, safe-y-nonesafe-t-none
- , safe-r-none, safe-b-none, safe-l-none`