WebView makes website content unaccessible on the top/bottom edges

I'm being faced with an issue when using SwiftUI's WebView on iOS 26. In many websites, the top/bottom content is unaccessible due to being under the app's toolbars. It feels like the WebView doesn't really understand the safe areas where it's being shown, because the content should start right below the navigation bar, and only when the user scrolls down, the content should move under the bar (but it's always reachable if the users scroll back up).

Here's a demo of the issue:

Here's a 'fix' by ensuring that the content of the WebView never leaves its bounds. But as you can see, it feels out of place on iOS 26 (would be fine on previous OS versions if you had a fully opaque toolbar):

Code:

struct ContentView: View {
  
  var body: some View {
    NavigationStack {
      WebView(url: URL(string: "https://apple.com")).toolbar {
        ToolbarItem(placement: .primaryAction) {
          Button("Top content covered, unaccessible.") {}
        }
      }
    }
  }
}

Does anyone know if there's a way to fix it using some sort of view modifier combination or it's just broken as-is?

Answered by DTS Engineer in 856043022

Hello. This is expected behavior for the SwiftUI WebView. You may notice that the ScrollView operates in a similar manner. To work around this problem, here are some things you can try:

  • In SwiftUI, they can use the safeAreaPadding(_:) modifier
  • in your web content, use the safe-area-inset CSS properties (see Designing Websites for iPhone X for details).

Hello. This is expected behavior for the SwiftUI WebView. You may notice that the ScrollView operates in a similar manner. To work around this problem, here are some things you can try:

  • In SwiftUI, they can use the safeAreaPadding(_:) modifier
  • in your web content, use the safe-area-inset CSS properties (see Designing Websites for iPhone X for details).

Hello @DTS Engineer. I don't think that ScrollView works the same way. From my point of view, ScrollView correctly handles the safe area. The content on a ScrollView starts right below the safe area, where on the WebView it doesn't.

Here's a quick example of what I mean. On the ScrollView, the content is always accessible. On the WebView, the top part is not.

About the suggestions:

  • safeAreaPadding(_:) doesn't seem to change anything when applied to the WebView.
  • Modifying the CSS is not an option since I'm trying to load any webpage (building sort of a browser wrapper).

Any more ideas? I do really want to have websites behave like they do on Safari (or on SFSafariViewController) where the website content starts below the safe area and moves under the bars as you scroll. But I can't figure out how to make WebView behave like those two.

I don't see .safeAreaPadding(_:) applied to the WebView in the screen capture you provided above. This is the approach recommended by WebKit engineering. If it's not working for you, then perhaps we should get a feedback report filed about it.

@DTS Engineer Here's a screenshot with .safeAreaPadding(.vertical, 100) applied to the WebView. As you can see, nothing changes.

I've been playing with this, and I sort of got an idea. I could observe the scroll position of the WebView, and move the Dividers I showed on the original post as a workaround as needed (on the video I toggle them with a button just for show):

But after having done that, what I really want (I think), is simply being able to remove the clipToBounds on the WebView. That way I could always position it inside the safe areas so the content is always accessible (and web content 'sticky' top/bottom is always reachable), but whenever the user scrolls, the content would flow below the navigation bars because it would bleed outside of the WebView since it's no longer clipped by the bounds. I've tried the scrollClipDisabled, but doesn't seem to change anything, any suggestions are much appreciated!

Again, I'm using the VStack + Dividers combo because if I don't, the WebView fills the entire screen not respecting the SafeArea. If there's another way that's better that might help with the removal of the clipToBounds, I'm all ears! 🙏

WebView makes website content unaccessible on the top/bottom edges
 
 
Q