node package manager



Build status NPM version XO code style

Create HTML strings with JavaScript

Goes hand in hand with hyperscript-helpers.


Install hyperscript-string using npm:

npm install --save hyperscript-string


Module usage

const h = require('hyperscript-string');
const html = h('ul.list', [
    h('li.item', 'Lorem ipsum'),
    h('li.item', {title: 'Second item'}, 'Dolor sit'),
    h('li.item', 'Amet')
<ul class="list">
    <li class="item">Lorem ipsum</li>
    <li title="Second item" class="item">Dolor sit</li>
    <li class="item">Amet</li>

Attributes that are null, undefined or false are excluded in the generated HTML.
Empty strings are left as is, e.g. h('a', {href: ''}) => '<a href=""></a>', and true are generated without value, e.g. h('button', {disabled: true}, 'Click me') => '<button disabled>Click me</button>'.
Void elements' children are excluded in the generated HTML as well.

Related packages


h(selector[, attrs, children])

Name Type Description
selector String Contains at least the HTML tag name
attrs Object Attributes for the HTML tag
children String or Array The children for the HTML tag

Returns: String, the generated HTML.


MIT © Joakim Carlstein