<!--
{
  "availability" : [
    "macOS: 10.5.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/DOMHTMLDocument/createDocumentFragment(withMarkupString:baseURL:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "c:objc(cs)DOMHTMLDocument(im)createDocumentFragmentWithMarkupString:baseURL:"
  },
  "title" : "createDocumentFragment(withMarkupString:baseURL:)"
}
-->

# createDocumentFragment(withMarkupString:baseURL:)

Creates a document fragment containing the given HTML markup.

```
func createDocumentFragment(withMarkupString markupString: String!, baseURL: URL!) -> DOMDocumentFragment!
```

## Parameters

`markupString`

The HTML content to parse into a DOM tree.

`baseURL`

The URI from which the content originated. Used for interpreting relative URLs.

## Return Value

A `DOMDocumentFragment` derived from the original markup string.

## Discussion

This is a convenience method for the `createDocumentFragment` method in `DOMDocument`. It creates a fragment that has the HTML markup parsed into child nodes of the fragment using the `baseURL` to resolve any relative paths for images or other resources.

---

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)