<!--
{
  "availability" : [
    "macOS: 10.3.0 - 10.14.0"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/WebFrame/loadHTMLString(_:baseURL:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "c:objc(cs)WebFrame(im)loadHTMLString:baseURL:"
  },
  "title" : "loadHTMLString(_:baseURL:)"
}
-->

# loadHTMLString(_:baseURL:)

Sets the main page contents and base URL.

```
func loadHTMLString(_ string: String!, baseURL URL: URL!)
```

## Parameters

`string`

The string to use as the main page for the document.

    Since the string is treated as a webpage with UTF-8 encoding, the default encoding for any script elements referenced by the HTML is also UTF-8. To avoid this, include a character set attribute on the script element.

`URL`

A file that is used to resolve relative URLs within the document.

## Discussion

---

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)