Skip to content

Add safe area utilities for mobile app usage#19921

Open
riderx wants to merge 3 commits intotailwindlabs:mainfrom
riderx:codex/add-safe-area-utilities
Open

Add safe area utilities for mobile app usage#19921
riderx wants to merge 3 commits intotailwindlabs:mainfrom
riderx:codex/add-safe-area-utilities

Conversation

@riderx
Copy link
Copy Markdown

@riderx riderx commented Apr 9, 2026

Summary

  • add built-in safe-area utilities for inset, margin, padding, scroll margin, and scroll padding
  • add safe and safe-none control utilities so safe-area values can be scoped or reset via CSS custom properties
  • add viewport-safe height utilities for screen, svh, lvh, and dvh

Why

  • Tailwind users currently need external plugins or ad hoc utilities for safe-area handling on notch and home-indicator devices
  • this brings the most common safe-area patterns into core with the existing spacing and fraction syntax

Impact

  • users can write classes like pt-safe-4, -top-safe-px, scroll-p-safe, and h-dvh-safe
  • safe-none style utilities let component subtrees opt out without redefining the spacing helpers

Validation

  • pnpm exec vitest run packages/tailwindcss/src/utilities.test.ts packages/tailwindcss/src/intellisense.test.ts packages/tailwindcss/src/candidate.test.ts packages/tailwindcss/src/prefix.test.ts

@riderx riderx requested a review from a team as a code owner April 9, 2026 13:11
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 51763ed4f5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 926175a8-43b0-4475-a210-9f2447393615

📥 Commits

Reviewing files that changed from the base of the PR and between 246f79e and 132ec1a.

📒 Files selected for processing (2)
  • packages/tailwindcss/src/utilities.test.ts
  • packages/tailwindcss/src/utilities.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/tailwindcss/src/utilities.test.ts

Walkthrough

Adds safe-area inset utilities and tests to Tailwind CSS. Introduces helpers and a SafeAreaInset type to emit var(--tw-safe-area-<edge>, env(safe-area-inset-<edge>)) declarations, side-specific properties with optional additive offsets and negation, and spacing resolution for theme keys, fractions, multipliers, and arbitrary values. Registers static safe* and safe*-none variables plus safe-area-aware spacing utilities for inset, m, p, scroll-m, and scroll-p (including negative and fractional variants). Adds viewport-height safe-height utilities for h, min-h, and max-h across vh, svh, lvh, and dvh. Adds tests asserting generated CSS and runtime class handling.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add safe area utilities for mobile app usage' directly reflects the main changes in the pull request, which adds safe-area utilities for inset, margin, padding, scroll margin, and scroll padding to support mobile devices with notches and home indicators.
Description check ✅ Passed The description clearly outlines the changes (safe-area utilities), explains the motivation (mobile device support), describes the impact (new utility classes), and includes validation steps, all directly related to the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/tailwindcss/src/utilities.ts (1)

598-625: Extract the spacing resolution path instead of copying it.

resolveSpacingUtilityValue now reimplements the same theme/bare/fraction resolution that spacingUtility already owns. Any future change to spacing candidate handling will have to be updated in both places, which is an easy drift point for core utilities.

Also applies to: 627-666

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/tailwindcss/src/utilities.ts` around lines 598 - 625,
resolveSpacingUtilityValue duplicates the spacing resolution logic already
implemented by spacingUtility; extract that shared resolution path into a single
helper (e.g., resolveSpacingCandidate or reuse spacingUtility's internal
resolver) and have resolveSpacingUtilityValue call it instead of reimplementing
theme.resolve/fraction/bare/multiplier logic. Refactor so the new helper accepts
the same inputs used here (candidate, themeKeys, supportsFractions) and
internally uses theme.resolve, segment/isPositiveInteger, and
isValidSpacingMultiplier to produce the final value; update both
resolveSpacingUtilityValue and the original spacingUtility call sites to use the
shared helper to avoid duplication and future drift.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/tailwindcss/src/utilities.test.ts`:
- Around line 319-437: The test currently covers 'safe', 'safe-x-none', and
'safe-b' but misses the primary control utility 'safe-none'; update the
candidate list in the utilities.test.ts test (the array alongside 'safe',
'safe-x-none', 'safe-b') to include 'safe-none' so the snapshot generation also
asserts the .safe-none rule (alongside existing .safe, .safe-x-none, .safe-b)
that sets all --tw-safe-area-* variables to 0; run the test to refresh the
inline snapshot if necessary.

In `@packages/tailwindcss/src/utilities.ts`:
- Around line 775-808: The safe-axis utilities currently use physical sides
(left/right/top/bottom) which breaks logical-axis consistency; update the
entries passed to safeAreaSpacingUtility so that 'inset-x-safe' and any other
"*-x-safe" use the inline-axis pair (inline-start, inline-end) and
'inset-y-safe' and "*-y-safe" use the block-axis pair (block-start, block-end),
and change single-side safe entries (e.g., 'left-safe', 'right-safe',
'top-safe', 'bottom-safe') to their logical equivalents where appropriate
(inline-start/inline-end/block-start/block-end) so the safe variants match
Tailwind’s logical-axis semantics; locate and modify the arrays in the for-loop
that calls safeAreaSpacingUtility (names like 'inset-safe', 'inset-x-safe',
'inset-y-safe', 'top-safe', 'right-safe', 'bottom-safe', 'left-safe') and mirror
the same logical-axis replacement in the other similar blocks noted in the
review.

---

Nitpick comments:
In `@packages/tailwindcss/src/utilities.ts`:
- Around line 598-625: resolveSpacingUtilityValue duplicates the spacing
resolution logic already implemented by spacingUtility; extract that shared
resolution path into a single helper (e.g., resolveSpacingCandidate or reuse
spacingUtility's internal resolver) and have resolveSpacingUtilityValue call it
instead of reimplementing theme.resolve/fraction/bare/multiplier logic. Refactor
so the new helper accepts the same inputs used here (candidate, themeKeys,
supportsFractions) and internally uses theme.resolve, segment/isPositiveInteger,
and isValidSpacingMultiplier to produce the final value; update both
resolveSpacingUtilityValue and the original spacingUtility call sites to use the
shared helper to avoid duplication and future drift.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6749e52a-559b-41ef-9a78-aab6eaa3f876

📥 Commits

Reviewing files that changed from the base of the PR and between aad6017 and 51763ed.

⛔ Files ignored due to path filters (1)
  • packages/tailwindcss/src/__snapshots__/intellisense.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • packages/tailwindcss/src/utilities.test.ts
  • packages/tailwindcss/src/utilities.ts

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 246f79e9ce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@riderx riderx changed the title [codex] Add safe area utilities Add safe area utilities for mobile app usage Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant