<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/WebView-swift.class/replaceSelection(withMarkupString:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "c:objc(cs)WebView(im)replaceSelectionWithMarkupString:"
  },
  "title" : "replaceSelection(withMarkupString:)"
}
-->

# replaceSelection(withMarkupString:)

Replaces the current selection with mixed text and markup.

```
func replaceSelection(withMarkupString markupString: String!)
```

## Parameters

`markupString`

The markup string that replaces the current selection.

## Discussion

If the current selection is collapsed (a range is selected with the same nodes and offsets for the start and end) then no content is removed when inserting the markup, and the selection is collapsed and moved to the end of the inserted content. If no content is selected, the markup is not inserted.

See [HTML Clipboard Format](http://msdn.microsoft.com/en-us/library/aa767917.aspx) for a specification of the supported HTML markup.

---

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)