Convert HTML, SVG, and XML markup strings into DOM objects
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Version Badge Build Status Dependencies License File Size

Convert HTML, SVG, and XML markup strings into DOM objects.


Convert a single element HTML string into a DOM element:

const div = dominate('<div>foo</div>');
div.nodeName; // DIV

Convert a multiple element HTML string into a document fragment:

const frag = dominate('<strong>Hello</strong> <em>World</em>');
frag.nodeName; // #document-fragment

Convert plain text to a DOM text node:

const text = dominate('This is plain text.');
text.nodeName; // #text

Convert an SVG element into a DOM element:

const rect = dominate('<rect x="10" y="10" width="100" height="100"/>');
rect instanceof SVGRectElement; // true

Executes script tags within an HTML string by default:

const script = dominate('<script>console.log("foo");</script>');
document.body.appendChild(script); // console outputs "foo"

Remove script tags to prevent execution:

const el = dominate('<section><script src="foo.js"></script></section>', {scripts: false});
const script = el.querySelector('script'); // null

Use a custom document instead of the default (window.document)

import { jsdom } from 'jsdom';
const doc = jsdom('<html><body></body></html>');

const el = dominate('<div></div>', {context: doc});
el.ownerDocument === doc; // true

Convert XML string into a DOM element:

const xml = dominate('<name>foo</name>', {type: 'xml'});
xml instanceof Element; // true
xml instanceof HTMLElement; // false

Supports tagged template literals:

const names = ['John', 'Amy', 'Joe'];

const el = dominate`
            ${ => `<li>${name}</li>`)}



Dominate is CommonJS and AMD compatible with no dependencies. You can download the development or minified version, or install it in one of the following ways:

npm install ryanmorr/dominate

bower install ryanmorr/dominate


Open test/runner.html in your browser or test with PhantomJS by issuing the following commands:

npm install
npm install -g gulp
gulp test


This project is dedicated to the public domain as described by the Unlicense.