Greetings, traveler!
For years, displaying web content in SwiftUI meant falling back to WKWebView
from UIKit. It worked, but it always felt like a workaround.
Starting with iOS 18.4, Apple added a native WebView
for SwiftUI. No more UIViewRepresentable
, no more bridging. Just import WebKit and SwiftUI, and you are good to go.
How It Works
Here’s the exact line from the docs:
“A view that displays some web content. Connect a
WebView
with aWebPage
to fully control the browsing experience, including essential functionality such as loading a URL.”
So you can finally load web content the same way you’d work with other SwiftUI views. It’s all reactive and state-driven.
Modifiers
A few modifiers give more control over how the WebView
behaves.
webViewLinkPreviews(_:)
: Turn link previews on or off.webViewContentBackground(_:)
: Show or hide the web page’s native background.webViewMagnificationGestures(_:)
: Enable pinch-to-zoom.webViewBackForwardNavigationGestures(_:)
: Allow swipe-based back/forward navigation.webViewScrollPosition(_:)
: Bind the scroll offset to aScrollPosition
.
Two Ways to Use It
There are two initializers.
The simple one takes a URL
directly. Here’s what that looks like:
import SwiftUI
import WebKit
struct WebViewDemo: View {
private let url = URL(string: "https://developer.apple.com/wwdc25/")!
var body: some View {
WebView(url: url)
}
}
If you need more control—like injecting custom requests, observing page state, or updating content—you can use the WebPage
approach:
import SwiftUI
import WebKit
struct WebPageDemo: View {
@State private var page = WebPage()
private let url = URL(string: "https://developer.apple.com/wwdc25/")!
var body: some View {
WebView(page)
.onAppear {
page.load(URLRequest(url: url))
}
}
}
This gives you more room for state management.
One Thing to Keep in Mind
The new WebView
is only available from iOS 18.4 and later. If you support earlier versions, you’ll still need a fallback with WKWebView
.
Conclusion
This is a small addition, but a useful one. You no longer have to write a wrapper just to show a webpage. It’s a clean, native API, and it fits into SwiftUI the way you’d expect.
If you enjoyed this article, please feel free to follow me on my social media: