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 ref class HtmlFormatHelper abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class HtmlFormatHelper final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public static class HtmlFormatHelper
Public Class HtmlFormatHelper
Object IInspectable HtmlFormatHelper

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)


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.



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


Gets a string that represents an HTML fragment.

Applies to