HtmlFormatHelper HtmlFormatHelper HtmlFormatHelper HtmlFormatHelper HtmlFormatHelper Class


Responsible for formatting HTML content that you want to share or add to the Clipboard. Also allows you to get HTML fragments from the content.

public : static class HtmlFormatHelper
static struct winrt::Windows::ApplicationModel::DataTransfer::HtmlFormatHelper
public static class HtmlFormatHelper
Public Shared Class HtmlFormatHelper
// This class does not provide a public constructor.

Windows 10 requirements

Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)


if ( {
    document.getElementById("htmlContentArea").className = "unhidden"; (html) {
        if (html !== null) {
            var htmlFragment = Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.getStaticFragment(htmlFormat);

            // Set the innerHTML of the ifram to the HTML fragment.
            var iFrame = document.getElementById("htmlContent");
   = "";
            iFrame.contentDocument.documentElement.innerHTML = htmlFragment;

    // Loop through any images and use the resourceMap to map each image element's src.
    var images = iFrame.contentDocument.documentElement.getElementsByTagName("img");
    if (images.length > 0) { (resourceMap) {
            if (resourceMap.size > 0) {
                for (var i = 0, len = images.length; i < len; i++) {
                    var streamReference = resourceMap[images[i].getAttribute("src")];
                    if (streamReference) {
                        // Call a helper function to map the image element's src to a corresponding blob URL generated from the streamReference
                        setResourceMapURL(streamReference, images[i]);


For more information on how to use this class, check out DataPackage.SetHtmlFormat. You might also want to look at our topic, How to share HTML.


CreateHtmlFormat(String) CreateHtmlFormat(String) CreateHtmlFormat(String) CreateHtmlFormat(String) CreateHtmlFormat(String)

Takes a string that represents HTML content and adds the necessary headers to ensure it is formatted correctly for share and Clipboard operations.

GetStaticFragment(String) GetStaticFragment(String) GetStaticFragment(String) GetStaticFragment(String) GetStaticFragment(String)

Gets a string that represents an HTML fragment.