<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/WKWebView",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "c:objc(cs)WKWebView"
  },
  "title" : "WKWebView"
}
-->

# WKWebView

An object that displays interactive web content, such as for an in-app browser.

```
@MainActor class WKWebView
```

## Overview

A [`WKWebView`](/documentation/WebKit/WKWebView) object is a platform-native view that you use to incorporate web content seamlessly into your app’s UI. A web view supports a full web-browsing experience, and presents HTML, CSS, and JavaScript content alongside your app’s native views. Use it when web technologies satisfy your app’s layout and styling requirements more readily than native views. For example, you might use it when your app’s content changes frequently.

A web view offers control over the navigation and user experience through delegate objects. Use the navigation delegate to react when the user clicks links in your web content, or interacts with the content in a way that affects navigation. For example, you might prevent the user from navigating to new content unless specific conditions are met. Use the UI delegate to present native UI elements, such as alerts or contextual menus, in response to interactions with your web content.

> Note:
> ``doc://com.apple.webkit/documentation/WebKit/WKWebView`` replaces the <doc://com.apple.documentation/documentation/UIKit/UIWebView> class in iOS 8 and later, and it replaces the ``doc://com.apple.webkit/documentation/WebKit/WebView-swift.class`` class in macOS 10.10 and later.

Embed a [`WKWebView`](/documentation/WebKit/WKWebView) object programmatically into your view hierarchy, or add it using Interface Builder. Interface Builder supports many customizations, such as configuring data detectors, media playback, and interaction behaviors. For more extensive customizations, create your web view programmatically using a [`WKWebViewConfiguration`](/documentation/WebKit/WKWebViewConfiguration) object. For example, use a web view configuration object to specify handlers for custom URL schemes, manage cookies, and customize preferences for your web content.

Before your web view appears onscreen, load content from a web server using a <doc://com.apple.documentation/documentation/Foundation/URLRequest> structure or load content directly from a local file or HTML string. The web view automatically loads embedded resources such as images or videos as part of the initial load request. It then renders your content and displays the results inside the view’s bounds rectangle. The following code example shows a view controller that replaces its default view with a custom [`WKWebView`](/documentation/WebKit/WKWebView) object.

```swift
import UIKit
import WebKit

class ViewController: UIViewController, WKUIDelegate {
    
    var webView: WKWebView!
    
    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        view = webView
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let myURL = URL(string:"https://www.apple.com")
        let myRequest = URLRequest(url: myURL!)
        webView.load(myRequest)
    }
}
```

A web view automatically converts telephone numbers that appear in web content to Phone links. When the user taps a Phone link, the Phone app launches and dials the number. Use the [`WKWebViewConfiguration`](/documentation/WebKit/WKWebViewConfiguration) object to change the default data detector behavior.

You can also use [`setMagnification(_:centeredAt:)`](/documentation/WebKit/WKWebView/setMagnification(_:centeredAt:)) to programmatically set the scale of web content the first time it appears in a web view. Thereafter, the user can change the scale using gestures.

### Manage the navigation through your web content

[`WKWebView`](/documentation/WebKit/WKWebView) provides a complete browsing experience, including the ability to navigate between different webpages using links, forward and back buttons, and more. When the user clicks a link in your content, the web view acts like a browser and displays the content at that link. To disallow navigation, or to customize your web view’s navigation behavior, provide your web view with a navigation delegate — an object that conforms to the [`WKNavigationDelegate`](/documentation/WebKit/WKNavigationDelegate) protocol. Use your navigation delegate to modify the web view’s navigation behavior, or to track the loading progress of new content.

You can also use the methods of [`WKWebView`](/documentation/WebKit/WKWebView) to navigate programmatically through your content, or to trigger navigation from other parts of your app’s interface. For example, if your UI includes forward and back buttons, connect those buttons to the [`goBack(_:)`](/documentation/WebKit/WKWebView/goBack(_:)) and [`goForward(_:)`](/documentation/WebKit/WKWebView/goForward(_:)) methods of your web view to trigger the corresponding web navigation. Use the [`canGoBack`](/documentation/WebKit/WKWebView/canGoBack) and [`canGoForward`](/documentation/WebKit/WKWebView/canGoForward) properties to determine when to enable or disable your buttons.

### Provide sharing options

People may want to share the contents of your web view with an app or other people. Use a <doc://com.apple.documentation/documentation/UIKit/UIActivityViewController> to present a share sheet offering all the ways people can share the web content.

If your app has the <doc://com.apple.documentation/documentation/BundleResources/Entitlements/com.apple.developer.web-browser> entitlement, the iOS share sheet can offer Add to Home Screen for an `http` or `https` webpage, creating a convenient link to a web app or bookmark. To allow someone to add the current webpage to the Home Screen, include the [`WKWebView`](/documentation/WebKit/WKWebView) instance in the `activityItems` array when you call <doc://com.apple.documentation/documentation/UIKit/UIActivityViewController/init(activityItems:applicationActivities:)> to create the <doc://com.apple.documentation/documentation/UIKit/UIActivityViewController>. For more information about building a browser app, see <doc://com.apple.documentation/documentation/Xcode/preparing-your-app-to-be-the-default-browser>.

## Topics

### Creating a web view

[`init(frame:configuration:)`](/documentation/WebKit/WKWebView/init(frame:configuration:))

Creates a web view and initializes it with the specified frame and configuration data.

[`init(coder:)`](/documentation/WebKit/WKWebView/init(coder:))

Returns an object initialized from data in the specified coder object.

[`configuration`](/documentation/WebKit/WKWebView/configuration)

The object that contains the configuration details for the web view.

### Determining whether WebKit can load content

[`handlesURLScheme(_:)`](/documentation/WebKit/WKWebView/handlesURLScheme(_:))

Returns a Boolean value that indicates whether WebKit natively supports resources with the specified URL scheme.

### Displaying native user interface elements

[`uiDelegate`](/documentation/WebKit/WKWebView/uiDelegate)

The object you use to integrate custom user interface elements, such as contextual menus or panels, into web view interactions.

[`WKUIDelegate`](/documentation/WebKit/WKUIDelegate)

The methods for presenting native user interface elements on behalf of a webpage.

### Managing navigation between webpages

[`navigationDelegate`](/documentation/WebKit/WKWebView/navigationDelegate)

The object you use to manage navigation behavior for the web view.

[`WKNavigationDelegate`](/documentation/WebKit/WKNavigationDelegate)

Methods for accepting or rejecting navigation changes, and for tracking the progress of navigation requests.

### Loading web content

[`load(_:)`](/documentation/WebKit/WKWebView/load(_:))

Loads the web content that the specified URL request object references and navigates to that content.

[`load(_:mimeType:characterEncodingName:baseURL:)`](/documentation/WebKit/WKWebView/load(_:mimeType:characterEncodingName:baseURL:))

Loads the content of the specified data object and navigates to it.

[`loadHTMLString(_:baseURL:)`](/documentation/WebKit/WKWebView/loadHTMLString(_:baseURL:))

Loads the contents of the specified HTML string and navigates to it.

[`loadFileRequest(_:allowingReadAccessTo:)`](/documentation/WebKit/WKWebView/loadFileRequest(_:allowingReadAccessTo:))

Loads the web content from the file the URL request object specifies and navigates to that content.

[`loadFileURL(_:allowingReadAccessTo:)`](/documentation/WebKit/WKWebView/loadFileURL(_:allowingReadAccessTo:))

Loads the web content from the specified file and navigates to it.

[`loadSimulatedRequest(_:response:responseData:)`](/documentation/WebKit/WKWebView/loadSimulatedRequest(_:response:responseData:))

Loads the web content from the data you provide as if the data were the response to the request.

[`loadSimulatedRequest(_:responseHTML:)`](/documentation/WebKit/WKWebView/loadSimulatedRequest(_:responseHTML:))

Loads the web content from the HTML you provide as if the HTML were the response to the request.

[`isLoading`](/documentation/WebKit/WKWebView/isLoading)

A Boolean value that indicates whether the view is currently loading content.

[`estimatedProgress`](/documentation/WebKit/WKWebView/estimatedProgress)

An estimate of what fraction of the current navigation has been loaded.

### Managing the loading process

[`reload()`](/documentation/WebKit/WKWebView/reload())

Reloads the current webpage.

[`reload(_:)`](/documentation/WebKit/WKWebView/reload(_:))

Reloads the current webpage.

[`reloadFromOrigin()`](/documentation/WebKit/WKWebView/reloadFromOrigin())

Reloads the current webpage, and performs end-to-end revalidation of the content using cache-validating conditionals, if possible.

[`reloadFromOrigin(_:)`](/documentation/WebKit/WKWebView/reloadFromOrigin(_:))

Reloads the current webpage, and performs end-to-end revalidation of the content using cache-validating conditionals, if possible.

[`stopLoading()`](/documentation/WebKit/WKWebView/stopLoading())

Stops loading all resources on the current page.

[`stopLoading(_:)`](/documentation/WebKit/WKWebView/stopLoading(_:))

Stops loading all resources on the current page.

### Managing downloads

[`startDownload(using:completionHandler:)`](/documentation/WebKit/WKWebView/startDownload(using:completionHandler:))

Starts to download the resource at the URL in the request.

[`resumeDownload(fromResumeData:completionHandler:)`](/documentation/WebKit/WKWebView/resumeDownload(fromResumeData:completionHandler:))

Resumes a failed or canceled download.

### Making web content inspectable

[`isInspectable`](/documentation/WebKit/WKWebView/isInspectable)

A Boolean value that indicates whether you can inspect the view with Safari Web Inspector.

### Inspecting the view information

[`scrollView`](/documentation/WebKit/WKWebView/scrollView)

The scroll view associated with the web view.

[`title`](/documentation/WebKit/WKWebView/title)

The page title.

[`url`](/documentation/WebKit/WKWebView/url)

The URL for the current webpage.

[`mediaType`](/documentation/WebKit/WKWebView/mediaType)

The media type for the contents of the web view.

[`customUserAgent`](/documentation/WebKit/WKWebView/customUserAgent)

The custom user agent string.

[`serverTrust`](/documentation/WebKit/WKWebView/serverTrust)

The trust management object you use to evaluate trust for the current webpage.

[`hasOnlySecureContent`](/documentation/WebKit/WKWebView/hasOnlySecureContent)

A Boolean value that indicates whether the web view loaded all resources on the page through securely encrypted connections.

[`themeColor`](/documentation/WebKit/WKWebView/themeColor)

The theme color that the system gets from the first valid meta tag in the webpage.

[`underPageBackgroundColor`](/documentation/WebKit/WKWebView/underPageBackgroundColor)

The color the web view displays behind the active page, visible when the user scrolls beyond the bounds of the page.

### Scaling content

[`pageZoom`](/documentation/WebKit/WKWebView/pageZoom)

The scale factor by which the web view scales content relative to its bounds.

[`allowsMagnification`](/documentation/WebKit/WKWebView/allowsMagnification)

A Boolean value that indicates whether magnify gestures change the web view’s magnification.

[`magnification`](/documentation/WebKit/WKWebView/magnification)

The factor by which the page content is currently scaled.

[`setMagnification(_:centeredAt:)`](/documentation/WebKit/WKWebView/setMagnification(_:centeredAt:))

Scales the page content and centers the result on the specified point.

### Interacting with media

[`pauseAllMediaPlayback(completionHandler:)`](/documentation/WebKit/WKWebView/pauseAllMediaPlayback(completionHandler:))

Pauses playback of all media in the web view.

[`pauseAllMediaPlayback:`](/documentation/WebKit/WKWebView/pauseAllMediaPlayback:)

Pauses playback of all media in the web view.

[`requestMediaPlaybackState(completionHandler:)`](/documentation/WebKit/WKWebView/requestMediaPlaybackState(completionHandler:))

Requests the playback status of media in the web view.

[`requestMediaPlaybackState:`](/documentation/WebKit/WKWebView/requestMediaPlaybackState:)

Requests the playback status of media in the web view.

[`setAllMediaPlaybackSuspended(_:completionHandler:)`](/documentation/WebKit/WKWebView/setAllMediaPlaybackSuspended(_:completionHandler:))

Changes whether the webpage is suspending playback of all media in the page.

[`suspendAllMediaPlayback:`](/documentation/WebKit/WKWebView/suspendAllMediaPlayback:)

Changes whether the webpage is suspending playback of all media in the page.

[`resumeAllMediaPlayback:`](/documentation/WebKit/WKWebView/resumeAllMediaPlayback:)

Resumes playback of all media in a web view.

[`closeAllMediaPresentations(completionHandler:)`](/documentation/WebKit/WKWebView/closeAllMediaPresentations(completionHandler:))

Closes all media the web view is presenting, including picture-in-picture video and fullscreen video.

[`WKMediaPlaybackState`](/documentation/WebKit/WKMediaPlaybackState)

An enumeration that describes whether an audio or video presentation is playing, paused, or suspended.

### Managing the microphone and camera

[`cameraCaptureState`](/documentation/WebKit/WKWebView/cameraCaptureState)

An enumeration case that indicates whether the webpage is using the camera to capture images or video.

[`microphoneCaptureState`](/documentation/WebKit/WKWebView/microphoneCaptureState)

An enumeration case that indicates whether the webpage is using the microphone to capture audio.

[`setCameraCaptureState(_:completionHandler:)`](/documentation/WebKit/WKWebView/setCameraCaptureState(_:completionHandler:))

Changes whether the webpage is using the camera to capture images or video.

[`setMicrophoneCaptureState(_:completionHandler:)`](/documentation/WebKit/WKWebView/setMicrophoneCaptureState(_:completionHandler:))

Changes whether the webpage is using the microphone to capture audio.

[`WKMediaCaptureState`](/documentation/WebKit/WKMediaCaptureState)

An enumeration that describes whether a media device, like a camera or microphone, is currently capturing audio or video.

### Searching the current page’s content

[`find(_:configuration:completionHandler:)`](/documentation/WebKit/WKWebView/find(_:configuration:completionHandler:))

Searches for the specified string in the web view’s content.

[`find(_:configuration:)`](/documentation/WebKit/WKWebView/find(_:configuration:))

Searches for the specified string in the web view’s content.

[`findString:withConfiguration:completionHandler:`](/documentation/WebKit/WKWebView/findString:withConfiguration:completionHandler:)

Searches for the specified string in the web view’s content.

[`WKFindConfiguration`](/documentation/WebKit/WKFindConfiguration)

The configuration parameters to use when searching the contents of the web view.

[`WKFindResult`](/documentation/WebKit/WKFindResult)

An object that contains the results of searching the web view’s contents.

### Navigating between webpages

[`allowsBackForwardNavigationGestures`](/documentation/WebKit/WKWebView/allowsBackForwardNavigationGestures)

A Boolean value that indicates whether horizontal swipe gestures trigger backward and forward page navigation.

[`backForwardList`](/documentation/WebKit/WKWebView/backForwardList)

The web view’s back-forward list.

[`goBack(_:)`](/documentation/WebKit/WKWebView/goBack(_:))

Navigates to the back item in the back-forward list.

[`goBack()`](/documentation/WebKit/WKWebView/goBack())

Navigates to the back item in the back-forward list.

[`goForward(_:)`](/documentation/WebKit/WKWebView/goForward(_:))

Navigates to the forward item in the back-forward list.

[`goForward()`](/documentation/WebKit/WKWebView/goForward())

Navigates to the forward item in the back-forward list.

[`go(to:)`](/documentation/WebKit/WKWebView/go(to:))

Navigates to an item from the back-forward list and sets it as the current item.

[`canGoBack`](/documentation/WebKit/WKWebView/canGoBack)

A Boolean value that indicates whether there is a valid back item in the back-forward list.

[`canGoForward`](/documentation/WebKit/WKWebView/canGoForward)

A Boolean value that indicates whether there is a valid forward item in the back-forward list.

[`allowsLinkPreview`](/documentation/WebKit/WKWebView/allowsLinkPreview)

A Boolean value that determines whether pressing a link displays a preview of the destination for the link.

[`interactionState`](/documentation/WebKit/WKWebView/interactionState)

An object you use to capture the current state of interaction in a web view so that you can restore that state later to another web view.

### Executing JavaScript

[`evaluateJavaScript(_:completionHandler:)`](/documentation/WebKit/WKWebView/evaluateJavaScript(_:completionHandler:))

Evaluates the specified JavaScript string.

[`evaluateJavaScript(_:in:in:completionHandler:)`](/documentation/WebKit/WKWebView/evaluateJavaScript(_:in:in:completionHandler:))

Evaluates a JavaScript string in the context of the specified frame and content world.

[`evaluateJavaScript(_:in:contentWorld:)`](/documentation/WebKit/WKWebView/evaluateJavaScript(_:in:contentWorld:))

Evaluates a JavaScript string in the context of the specified frame and content world.

[`callAsyncJavaScript(_:arguments:in:in:completionHandler:)`](/documentation/WebKit/WKWebView/callAsyncJavaScript(_:arguments:in:in:completionHandler:))

Executes the specified string as an asynchronous JavaScript function.

[`callAsyncJavaScript(_:arguments:in:contentWorld:)`](/documentation/WebKit/WKWebView/callAsyncJavaScript(_:arguments:in:contentWorld:))

Executes the specified string as an asynchronous JavaScript function.

[`evaluateJavaScript:inFrame:inContentWorld:completionHandler:`](/documentation/WebKit/WKWebView/evaluateJavaScript:inFrame:inContentWorld:completionHandler:)

Evaluates the specified JavaScript string in the specified frame and content world.

[`callAsyncJavaScript:arguments:inFrame:inContentWorld:completionHandler:`](/documentation/WebKit/WKWebView/callAsyncJavaScript:arguments:inFrame:inContentWorld:completionHandler:)

Executes the specified string as an asynchronous JavaScript function.

### Capturing the web view’s content

[`takeSnapshot(with:completionHandler:)`](/documentation/WebKit/WKWebView/takeSnapshot(with:completionHandler:))

Generates a platform-native image from the web view’s contents asynchronously.

[`createPDF(configuration:completionHandler:)`](/documentation/WebKit/WKWebView/createPDF(configuration:completionHandler:))

Generates PDF data from the web view’s contents asynchronously.

[`pdf(configuration:)`](/documentation/WebKit/WKWebView/pdf(configuration:))

Generates PDF data from the web view’s contents asynchronously.

[`createWebArchiveData(completionHandler:)`](/documentation/WebKit/WKWebView/createWebArchiveData(completionHandler:))

Creates a web archive of the web view’s current contents asynchronously.

[`createPDFWithConfiguration:completionHandler:`](/documentation/WebKit/WKWebView/createPDFWithConfiguration:completionHandler:)

Generates PDF data from the web view’s contents asynchronously.

[`createWebArchiveDataWithCompletionHandler:`](/documentation/WebKit/WKWebView/createWebArchiveDataWithCompletionHandler:)

Creates a web archive of the web view’s contents asynchronously.

[`printOperation(with:)`](/documentation/WebKit/WKWebView/printOperation(with:))

Returns the print operation object to use when printing the contents of the web view.

[`WKSnapshotConfiguration`](/documentation/WebKit/WKSnapshotConfiguration)

The configuration data to use when generating an image from a web view’s contents.

[`WKPDFConfiguration`](/documentation/WebKit/WKPDFConfiguration)

The configuration data to use when generating a PDF representation of a web view’s contents.

### Supporting Find and Replace

[`isFindInteractionEnabled`](/documentation/WebKit/WKWebView/isFindInteractionEnabled)

[`findInteraction`](/documentation/WebKit/WKWebView/findInteraction)

### Handling full-screen transitions

[`fullscreenState`](/documentation/WebKit/WKWebView/fullscreenState-swift.property)

[`WKWebView.FullscreenState`](/documentation/WebKit/WKWebView/FullscreenState-swift.enum)

### Configuring viewport insets

[`setMinimumViewportInset(_:maximumViewportInset:)`](/documentation/WebKit/WKWebView/setMinimumViewportInset(_:maximumViewportInset:))

[`minimumViewportInset`](/documentation/WebKit/WKWebView/minimumViewportInset)

[`maximumViewportInset`](/documentation/WebKit/WKWebView/maximumViewportInset)

### Examining data types

[`WKWebViewDataType`](/documentation/WebKit/WKWebViewDataType)

### Deprecated

[Deprecated symbols](/documentation/WebKit/wkwebview-deprecated-symbols)

Review unsupported symbols and their replacements.



---

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)
