Registry / serialization / html5-tag

html5-tag

JSON →
library0.3.0jsnpmunverified

html5-tag is a lightweight JavaScript utility designed for programmatically generating HTML5 tags and handling their attributes. Its primary function is to create HTML strings, correctly managing void elements (e.g., `<br>`, `<input>`) by omitting their closing tags, and automatically escaping attribute values to prevent XSS vulnerabilities. The current stable version is 0.3.0, released in 2016, indicating a very slow release cadence and likely an abandoned status. Unlike full-fledged templating engines or JSX, html5-tag focuses solely on simple string concatenation for server-side HTML generation, making it suitable for scenarios where a minimal, dependency-free solution for basic HTML element creation is preferred. A key differentiator is its automatic handling of attribute escaping and void elements, abstracting away common HTML syntax pitfalls.

npm install html5-tag
INSTALL
IMPORT
SIG · HTML5-TAG
H
html5-tag
serializationjavascriptv0.3.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

tag
import tag from 'html5-tag'
import { tag } from 'html5-tag'
The library exports a default function for tag generation. Named imports will not work.
tag (CommonJS)
const tag = require('html5-tag');
For CommonJS environments, the default export is directly assigned to the require call.

Demonstrates how to import and use the `tag` function to create various HTML elements, including void elements, attribute escaping, and the default 'div' behavior.

import tag from 'html5-tag'; // Basic usage: tag name, attributes object, and child content const link = tag('a', { href: 'https://example.com', target: '_blank' }, 'Visit Example'); console.log(link); // Expected: <a href="https://example.com" target="_blank">Visit Example</a> // Void elements do not receive a closing tag const linebreak = tag('br'); console.log(linebreak); // Expected: <br> // Attributes are automatically escaped const divWithTitle = tag('div', { title: 'It\'s "a" test & <more>' }, 'Escaped Title'); console.log(divWithTitle); // Expected: <div title="It&#39;&quot;a&quot; test &amp; &lt;more&gt;">Escaped Title</div> // If tag is omitted, it defaults to 'div' (since v0.3.0) const defaultDiv = tag({ class: 'container' }, 'Content goes here'); console.log(defaultDiv); // Expected: <div class="container">Content goes here</div>
Debug
Known issues
gotchaThe html5-tag package appears to be unmaintained. The last release (v0.3.0) was in 2016. It may lack updates for modern web standards, security patches, or compatibility with newer JavaScript ecosystems.
fix
Consider more actively maintained alternatives for generating HTML, especially in new projects.
affects: <=0.3.0
breakingStarting with version 0.3.0, the `tag` function defaults to generating a `div` element if the tag name is not explicitly provided as the first argument.
fix
Ensure you always provide the desired tag name as the first argument, or explicitly rely on the 'div' default if that is the intended behavior. For example, `tag({ class: 'my-class' }, 'Content')` now yields `<div>` instead of potentially throwing an error or having different behavior in older versions.
affects: >=0.3.0
Errors
Common errors & fixes
TypeError: html5_tag_1.tag is not a function
Attempting to use a named import (`import { tag } from 'html5-tag';`) when the library only provides a default export.
fix
Change the import statement to use a default import: `import tag from 'html5-tag';`.
TypeError: Cannot read properties of undefined (reading 'call')
This error can occur in CommonJS environments if `require('html5-tag')` is not assigned correctly, or if `exports.default` is accessed directly after `require()`, often when mixing ESM import syntax with CJS usage.
fix
Ensure the CommonJS import is `const tag = require('html5-tag');` to correctly capture the default exported function.
Upgrade
Version history
0.3.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
html5-tag — npm install html5-tag · libregistry