Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including html-document with all npm packages installed. Try it out:

var htmlDocument = require("html-document")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

html-document v0.8.1

Partial implementation of document, HTMLElement for node

html-document NPM version Build Status Code Climate Coverage

Partial implementation of the DOM, document for node.

Quick example

import Document from 'html-document'; // or var Document = require('html-document');
const document = new Document();

let textNode = document.createTextNode('Hello');
let h1 = document.createElement('h1');
h1.setAttribute('id', 'title');

expect(h1.outerHTML, '<h1 id="title">Hello</h1>');


The partial implementation allows you to build html like you would in the browser, with the DOM API.

This library will never implement all specifications of the W3C.


See the generated API here.


Inject window, document, Document, DocumentFragment, Node and Event in the global scope.

import 'html-document/lib/global'; // or var Document = require('html-document/lib/global');

let textNode = document.createTextNode('Hello');
expect(textNode.textContent, 'Hello');

Create an HTML layout

let document = new Document();
let fragment = document.createDocumentFragment();
fragment.appendChild(new Doctype());
let html = document.createElement('html');
let head = document.createElement('head');
let body = document.createElement('body');
expect(fragment.innerHTML, '<!DOCTYPE html><html><head></head><body></body></html>');
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free