GHTML: A JavaScript Library for HTML Generation


Replace your template engine with fast JavaScript by leveraging the power of tagged templates.

Inspired by html-template-tag.


npm i ghtml

API Reference

The main export of the package is the html function that can be used to tag template literals and escape their expressions. To bypass escaping an expression, prefix it with !.

Node.js users also have access to the includeFile function that reads and outputs the content of a file while caching it in memory for future use.


import { html } from "ghtml";

const username = '<img src="">';
const greeting = html`<h1>Hello, ${username}!</h1>`;

// Output: <h1>Hello, &lt;img src=&quot;;&gt;</h1>

const img = '<img src="">';
const container = html`<div>!${img}</div>`;

// Output: <div><img src=""></div>

The includeFile function returns the content of a file. Again, remember that it also caches the result, so any subsequent modifications to the same file won't be reflected until the app is restarted:

import { includeFile } from "ghtml/includeFile.js";

const logo = includeFile("static/logo.svg");

// Output: content of "static/logo.svg"

Download Details:

Author: Gurgunday
Source Code: 
License: MIT license

#javascript #template #engine #html 

GHTML: A JavaScript Library for HTML Generation
1.05 GEEK