<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/WebView-swift.struct",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "WebKit",
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:15_WebKit_SwiftUI0A4ViewV"
  },
  "title" : "WebView"
}
-->

# WebView

A view that displays some web content.

```
@MainActor @preconcurrency struct WebView
```

## Overview

Present HTML, CSS, and JavaScript content alongside your app’s native views with [`WebView`](/documentation/WebKit/WebView-swift.struct). Specify web content with a <doc://com.apple.documentation/documentation/Foundation/URL> when using the [`init(url:)`](/documentation/WebKit/WebView-swift.struct/init(url:)) initializer, or with a [`WebPage`](/documentation/WebKit/WebPage) when using the [`init(_:)`](/documentation/WebKit/WebView-swift.struct/init(_:)) initializer, which allows you to fully control the browsing experience. Any updates to the page propagate the information to the view.

[`WebView`](/documentation/WebKit/WebView-swift.struct) provides a complete browsing experience, including the ability to navigate between different webpages using links, forward and back buttons, and more. When a person clicks a link in your content, the view acts like a browser and displays the content at that link. To customize navigation, use a [`WebPage`](/documentation/WebKit/WebPage) with your [`WebView`](/documentation/WebKit/WebView-swift.struct) and customize the [`WebPage.Configuration`](/documentation/WebKit/WebPage/Configuration), or create a new type that conforms to [`WebPage.NavigationDeciding`](/documentation/WebKit/WebPage/NavigationDeciding).

The following example displays two different URLs depending on the state of a toggle, and also prevents back-forward navigation gestures:

```swift
import SwiftUI
import WebKit

struct ContentView: View {
    @State private var toggle = false

    private var url: URL? {
        toggle ? URL(string: "https://www.webkit.org") : URL(string: "https://www.swift.org")
    }

    var body: some View {
        WebView(url: url)
            .toolbar {
                Button(buttonName, systemImage: buttonIcon) {
                    toggle.toggle()
                }
            }
            .webViewBackForwardNavigationGestures(.disabled)
    }
}
```

A [`WebView`](/documentation/WebKit/WebView-swift.struct) is a scrollable view, and behaves similarly to <doc://com.apple.documentation/documentation/SwiftUI/ScrollView>. Customize scrolling in a [`WebView`](/documentation/WebKit/WebView-swift.struct) with:

- <doc://com.apple.documentation/documentation/SwiftUI/View/scrollBounceBehavior(_:axes:)>
- <doc://com.apple.documentation/documentation/SwiftUI/View/webViewScrollInputBehavior(_:for:)>
- <doc://com.apple.documentation/documentation/SwiftUI/View/webViewScrollPosition(_:)>
- <doc://com.apple.documentation/documentation/SwiftUI/View/webViewOnScrollGeometryChange(for:of:action:)>

Customize [`WebView`](/documentation/WebKit/WebView-swift.struct) display and interactions with view modifiers, such as:

- <doc://com.apple.documentation/documentation/SwiftUI/View/webViewBackForwardNavigationGestures(_:)>
- <doc://com.apple.documentation/documentation/SwiftUI/View/webViewMagnificationGestures(_:)>
- <doc://com.apple.documentation/documentation/SwiftUI/View/webViewLinkPreviews(_:)>
- <doc://com.apple.documentation/documentation/SwiftUI/View/webViewTextSelection(_:)>
- <doc://com.apple.documentation/documentation/SwiftUI/View/webViewElementFullscreenBehavior(_:)>
- <doc://com.apple.documentation/documentation/SwiftUI/View/webViewContextMenu(menu:)>
- <doc://com.apple.documentation/documentation/SwiftUI/View/webViewContentBackground(_:)>

To further customize and control a web interaction, connect a [`WebView`](/documentation/WebKit/WebView-swift.struct) to a [`WebPage`](/documentation/WebKit/WebPage). The following example demonstrates this by configuring the view’s navigation title to be the webpage’s title, which the system updates automatically because [`WebPage`](/documentation/WebKit/WebPage) is an `Observable` type:

```swift
struct ContentView: View {
    @State private var page = WebPage()

    var body: some View {
        NavigationStack {
            WebView(page)
                .navigationTitle(page.title)
        }
    }
}
```

You can only bind a [`WebPage`](/documentation/WebKit/WebPage) to a single [`WebView`](/documentation/WebKit/WebView-swift.struct) at a time.

## Topics

### Creating web views

[`init(WebPage)`](/documentation/WebKit/WebView-swift.struct/init(_:))

Create a new WebView.

[`init(url: URL?)`](/documentation/WebKit/WebView-swift.struct/init(url:))

Create a new WebView with the specified URL.

### Modifying web interactions

[`struct BackForwardNavigationGesturesBehavior`](/documentation/WebKit/WebView-swift.struct/BackForwardNavigationGesturesBehavior)

A type that defines the behavior of how horizontal swipe gestures trigger backward and forward page navigation.

[`struct LinkPreviewBehavior`](/documentation/WebKit/WebView-swift.struct/LinkPreviewBehavior)

A type specifying the behavior for the presentation of link previews when pressing a link.

[`struct ActivatedElementInfo`](/documentation/WebKit/WebView-swift.struct/ActivatedElementInfo)

Contains information about an element the user activated in a webpage, which may be used to configure a context menu for that element.

[`struct ElementFullscreenBehavior`](/documentation/WebKit/WebView-swift.struct/ElementFullscreenBehavior)

The behavior that determines whether a web view can display content full screen.

[`struct MagnificationGesturesBehavior`](/documentation/WebKit/WebView-swift.struct/MagnificationGesturesBehavior)

The options for controlling the behavior for how magnification gestures interact with web views.

### Modifying view behavior

## Relationships

### Conforms To

[`Sendable`](/documentation/Swift/Sendable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`View`](/documentation/SwiftUI/View)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)