# JavaScript template engine libraries

JavaScript template engine libraries render HTML or text by filling a template with data in Node.js and the browser. An engine either embeds plain JavaScript in the template or uses its own tag syntax with helpers, partials, and layout inheritance. These libraries let web servers, static site generators, and email tools build pages from shared templates.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [Lodash](#lodash) | 801.2M | Not on GitHub | Apr 2026 | MIT |
| [EJS](#ejs) | 230.1M | 8.1K | Oct 2026 | Apache-2.0 |
| [Handlebars](#handlebars) | 219.7M | 18.7K | Oct 2026 | MIT |
| [Underscore](#underscore) | 166.4M | Not on GitHub | Feb 2026 | MIT |
| [mustache](#mustache) | 98.2M | 16.7K | Mar 2021 | MIT |
| [Eta](#eta) | 42.4M | Not on GitHub | Apr 2026 | MIT |
| [Pug](#pug) | 19.8M | Not on GitHub | Mar 2026 | MIT |
| [Nunjucks](#nunjucks) | 19.3M | 9.0K | Apr 2023 | BSD-2-Clause |

Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[EJS](#ejs) has the most monthly downloads among dedicated template engines in this comparison, at 223.7M.

## Capabilities

| Library | Escapes interpolation | Async rendering | File-loading API |
| --- | --- | --- | --- |
| [Lodash](#lodash) | No | No | No |
| [EJS](#ejs) | Yes | Yes | Yes |
| [Handlebars](#handlebars) | Yes | No | Yes |
| [Underscore](#underscore) | No | No | No |
| [mustache](#mustache) | Yes | No | No |
| [Eta](#eta) | Yes | Yes | Yes |
| [Pug](#pug) | Yes | No | Yes |
| [Nunjucks](#nunjucks) | Yes | Yes | Yes |

## Libraries

### Lodash

[GitHub](https://github.com/lodash/lodash) · [npm](https://www.npmjs.com/package/lodash) · [Docs](https://cdn.jsdelivr.net/npm/lodash@4.18.1/README.md)

Compiles text templates with configurable delimiters as one part of a broad utility library.

- Downloads / mo: 801.2M
- Last release: 4.18.1
- License: MIT
- Capabilities: [From the Lodash docs](https://cdn.jsdelivr.net/npm/lodash@4.18.1/README.md)

```sh
npm install lodash@4.18.1
```

**sindresorhus/gulp-template** (287 stars)

[sindresorhus/gulp-template](https://github.com/sindresorhus/gulp-template) 

```javascript
function compile(options, data, render) {
	return gulpPlugin('gulp-template', file => {
		const contents = file.contents.toString();

		try {
			const template = _.template(contents, options);
			file.contents = Buffer.from(render ? template(_.merge({}, file.data, data)) : template.toString());
			return file;
		} catch (error) {
			error.message = `${error.message} in ${file.path}`;
			error.fileName = file.path;
			throw error;
		}
	});
}

```

[index.js](https://github.com/sindresorhus/gulp-template/blob/cb471422e40027eb5aebe2535e315b56bc5179f8/index.js#L5-L19) · [More projects using Lodash →](https://dashboard.exa.ai/playground/search?q=lodash%20GitHub%20projects)

**Quickstart**

```javascript
const _ = require('lodash');

const render = _.template('Hello <%= name %>!');
const output = render({ name: 'Ada' });

```

From [lodash.js](https://api.github.com/repos/lodash/lodash/contents/lodash.js?ref=4.18.1)

### EJS

[GitHub](https://github.com/mde/ejs) · [npm](https://www.npmjs.com/package/ejs) · [Docs](https://cdn.jsdelivr.net/npm/ejs@7.0.2/README.md)

Generates template output using JavaScript control flow and escaped or raw interpolation.

- Downloads / mo: 230.1M
- Stars: 8.1K
- Last release: 7.0.2
- License: Apache-2.0
- Capabilities: [From the EJS docs](https://cdn.jsdelivr.net/npm/ejs@7.0.2/README.md)

**Strengths**

- **Uses JavaScript inside templates.** Write loops and conditions with normal JavaScript.
- **Changes delimiters per template.** Choose delimiters per render instead of changing global settings.

**Watch out for**

- **Templates need trusted authors.** Do not accept unrestricted template source from end users.
- **Layouts rely on includes.** Compose headers and footers; EJS does not provide layout blocks.

```sh
npm install ejs@7.0.2
```

**11ty/buildawesome** (20.1K stars)

[11ty/buildawesome](https://github.com/11ty/buildawesome) 

```javascript
async compile(str, inputPath) {
  let options = this.getEjsOptions();

  if (inputPath && inputPath !== "ejs" && inputPath !== "md") {
    options.filename = inputPath;
  }

  let fn = this.ejsLib.compile(str, options);

  return function (data) {
    return fn(data);
  };
}

```

[src/Engines/Ejs.js](https://github.com/11ty/buildawesome/blob/e71cb94003b5a94dcd40ec96f8f4b455767b9833/src/Engines/Ejs.js#L40-L52) · [More projects using EJS →](https://dashboard.exa.ai/playground/search?q=JavaScript%20applications%20using%20ejs%20for%20template%20compilation%2C%20reusable%20partials%2C%20layout%20rendering%20and%20data%20binding&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```javascript
const ejs = require('ejs');

const output = ejs.render('Hello <%= name %>!', { name: 'Ada' });

```

From [README.md](https://cdn.jsdelivr.net/npm/ejs@7.0.2/README.md)

### Handlebars

[GitHub](https://github.com/handlebars-lang/handlebars.js) · [npm](https://www.npmjs.com/package/handlebars) · [Docs](https://cdn.jsdelivr.net/npm/handlebars@4.7.10/README.markdown)

Generates HTML or other template text from an input object.

- Downloads / mo: 219.7M
- Stars: 18.7K
- Last release: 4.7.10
- License: MIT
- Capabilities: [From the Handlebars docs](https://cdn.jsdelivr.net/npm/handlebars@4.7.10/README.markdown)

**Strengths**

- **Precompiles templates for client execution.** Generate template code before deploying the rendering runtime.
- **Reuses registered partial templates.** Register partials once and call them from other templates.

**Watch out for**

- **Missing fields are silently ignored.** Enable strict to throw when template data is missing.
- **Prototype properties are blocked.** Convert model instances to plain objects before rendering.

```sh
npm install handlebars@4.7.10
```

**11ty/buildawesome** (20.1K stars)

[11ty/buildawesome](https://github.com/11ty/buildawesome) 

```javascript
async compile(str) {
  // Ensure partials are cached and registered.
  await this.getPartials();

  let fn = this.handlebarsLib.compile(str);
  return function (data) {
    return fn(data);
  };
}

```

[src/Engines/Handlebars.js](https://github.com/11ty/buildawesome/blob/e71cb94003b5a94dcd40ec96f8f4b455767b9833/src/Engines/Handlebars.js#L62-L70) · [More projects using Handlebars →](https://dashboard.exa.ai/playground/search?q=JavaScript%20applications%20using%20handlebars%20for%20template%20compilation%2C%20reusable%20partials%2C%20layout%20rendering%20and%20data%20binding&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```javascript
const Handlebars = require('handlebars');

const render = Handlebars.compile('Hello {{name}}!');
const output = render({ name: 'Ada' });

```

From [README.md](https://cdn.jsdelivr.net/npm/handlebars@4.7.10/README.markdown)

### Underscore

[GitHub](https://github.com/jashkenas/underscore) · [npm](https://www.npmjs.com/package/underscore) · [Docs](https://cdn.jsdelivr.net/npm/underscore@1.13.8/README.md)

Compiles text templates with evaluate, interpolate, and escape tags as one part of a utility toolkit.

- Downloads / mo: 166.4M
- Last release: 1.13.8
- License: MIT
- Capabilities: [From the Underscore docs](https://cdn.jsdelivr.net/npm/underscore@1.13.8/README.md)

```sh
npm install underscore@1.13.8
```

**jashkenas/backbone** (28.1K stars)

[jashkenas/backbone](https://github.com/jashkenas/backbone) 

```javascript
function() {
      this.$el.html(this.template(this.model.toJSON()));
      this.$el.toggleClass('done', this.model.get('done'));
      this.input = this.$('.edit');
      return this;
    }

```

[examples/todos/todos.js](https://github.com/jashkenas/backbone/blob/94260d91dcf4050360f055506271b61f7b24e5e3/examples/todos/todos.js#L99-L104) · [More projects using Underscore →](https://dashboard.exa.ai/playground/search?q=underscore%20GitHub%20projects)

**Quickstart**

```javascript
const _ = require('underscore');

const render = _.template('Hello <%= name %>!');
const output = render({ name: 'Ada' });

```

From [template.js](https://api.github.com/repos/jashkenas/underscore/contents/modules/template.js?ref=1.13.8)

### mustache

[GitHub](https://github.com/janl/mustache.js) · [npm](https://www.npmjs.com/package/mustache) · [Docs](https://cdn.jsdelivr.net/npm/mustache@4.2.0/README.md)

Expands template tags using values supplied in an object.

- Downloads / mo: 98.2M
- Stars: 16.7K
- Last release: 4.2.0
- License: MIT
- Capabilities: [From the mustache docs](https://cdn.jsdelivr.net/npm/mustache@4.2.0/README.md)

**Strengths**

- **Reuses partials at runtime.** Supply partial text by name when rendering nested templates.
- **Changes tag delimiters inline.** Switch delimiters when braces conflict with other template content.

**Watch out for**

- **Complex branching belongs in data.** Prepare decisions in view values or helper functions.
- **Missing keys render nothing.** Validate required input fields before rendering.

```sh
npm install mustache@4.2.0
```

**11ty/buildawesome** (20.1K stars)

[11ty/buildawesome](https://github.com/11ty/buildawesome) 

```javascript
async compile(str) {
  let partials = await super.getPartials();

  return function (data) {
    return this.render(str, data, partials).trim();
  }.bind(this.mustacheLib);
}

```

[src/Engines/Mustache.js](https://github.com/11ty/buildawesome/blob/e71cb94003b5a94dcd40ec96f8f4b455767b9833/src/Engines/Mustache.js#L16-L22) · [More projects using mustache →](https://dashboard.exa.ai/playground/search?q=JavaScript%20applications%20using%20mustache%20for%20template%20compilation%2C%20reusable%20partials%2C%20layout%20rendering%20and%20data%20binding&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```javascript
const Mustache = require('mustache');

const output = Mustache.render('Hello {{name}}!', { name: 'Ada' });

```

From [README.md](https://cdn.jsdelivr.net/npm/mustache@4.2.0/README.md)

### Eta

[GitHub](https://github.com/eta-dev/eta) · [npm](https://www.npmjs.com/package/eta) · [Docs](https://cdn.jsdelivr.net/npm/eta@4.6.0/README.md)

Renders embedded JavaScript templates with escaping by default, async methods, includes, and layouts.

- Downloads / mo: 42.4M
- Last release: 4.6.0
- License: MIT
- Capabilities: [From the Eta docs](https://cdn.jsdelivr.net/npm/eta@4.6.0/README.md)

```sh
npm install eta@4.6.0
```

**meta/docusaurus** (66.8K stars)

[meta/docusaurus](https://github.com/meta/docusaurus) 

```javascript
export async function compileSSGTemplate(
  template: string,
): Promise<SSGTemplateCompiled> {
  const eta = new Eta({rmWhitespace: true});
  const compiledTemplate = eta.compile(template.trim());

  return (data: SSGTemplateData) => eta.render(compiledTemplate, data);
}

```

[packages/docusaurus/src/ssg/ssgTemplate.ts](https://github.com/meta/docusaurus/blob/c880050d8e79e10218cbbf21c313465cbee56910/packages/docusaurus/src/ssg/ssgTemplate.ts#L55-L62) · [More projects using Eta →](https://dashboard.exa.ai/playground/search?q=eta%20GitHub%20projects)

**Quickstart**

```javascript
const { Eta } = require('eta');

const eta = new Eta();
const output = eta.renderString('Hello <%= it.name %>!', { name: 'Ada' });

```

From [README.md](https://cdn.jsdelivr.net/npm/eta@4.6.0/README.md)

### Pug

[GitHub](https://github.com/pugjs/pug) · [npm](https://www.npmjs.com/package/pug) · [Docs](https://cdn.jsdelivr.net/npm/pug@3.0.4/README.md)

Compiles a whitespace-sensitive template language to HTML with includes and block inheritance.

- Downloads / mo: 19.8M
- Last release: 3.0.4
- License: MIT
- Capabilities: [From the Pug docs](https://cdn.jsdelivr.net/npm/pug@3.0.4/README.md)

```sh
npm install pug@3.0.4
```

**11ty/buildawesome** (20.1K stars)

[11ty/buildawesome](https://github.com/11ty/buildawesome) 

```javascript
async compile(str, inputPath) {
  let options = this.getPugOptions();
  if (!inputPath || inputPath === "pug" || inputPath === "md") {
    // do nothing
  } else {
    options.filename = inputPath;
  }

  return this.pugLib.compile(str, options);
}

```

[src/Engines/Pug.js](https://github.com/11ty/buildawesome/blob/e71cb94003b5a94dcd40ec96f8f4b455767b9833/src/Engines/Pug.js#L30-L39) · [More projects using Pug →](https://dashboard.exa.ai/playground/search?q=pug%20GitHub%20projects)

**Quickstart**

```javascript
const pug = require('pug');

const output = pug.render('p Hello #{name}!', { name: 'Ada' });

```

From [README.md](https://cdn.jsdelivr.net/npm/pug@3.0.4/README.md)

### Nunjucks

[GitHub](https://github.com/mozilla/nunjucks) · [npm](https://www.npmjs.com/package/nunjucks) · [Docs](https://cdn.jsdelivr.net/npm/nunjucks@3.2.4/README.md)

Renders templates with reusable layouts and overridable blocks.

- Downloads / mo: 19.3M
- Stars: 9.0K
- Last release: 3.2.4
- License: BSD-2-Clause
- Capabilities: [From the Nunjucks docs](https://cdn.jsdelivr.net/npm/nunjucks@3.2.4/README.md)

**Strengths**

- **Supports template inheritance.** Use extends and blocks to share page layouts.
- **Supports asynchronous template work.** Add asynchronous filters and loaders for data-dependent rendering.

**Watch out for**

- **Default API shares one configuration.** Create an explicit Environment when instances need separate settings.
- **Async loaders need async rendering.** Use callback-based rendering with asynchronous loaders.

```sh
npm install nunjucks@3.2.4
```

**11ty/buildawesome** (20.1K stars)

[11ty/buildawesome](https://github.com/11ty/buildawesome) 

```javascript
async compile(str, inputPath) {
  let tmpl;

  if (this._usingPrecompiled) {
    tmpl = this.njkEnv.getTemplate(str, true);
  } else if (!inputPath || inputPath === "njk" || inputPath === "md") {
    tmpl = new NunjucksLib.Template(str, this.njkEnv, null, true);
  } else {
    tmpl = new NunjucksLib.Template(str, this.njkEnv, inputPath, true);
  }

  return async function (data) {
    return new Promise(function (resolve, reject) {
      tmpl.render(data, function (err, res) {
        if (err) {
          reject(err);
        } else {
          resolve(res);
        }
      });
    });
  };
}

```

[src/Engines/Nunjucks.js](https://github.com/11ty/buildawesome/blob/e71cb94003b5a94dcd40ec96f8f4b455767b9833/src/Engines/Nunjucks.js#L398-L420) · [More projects using Nunjucks →](https://dashboard.exa.ai/playground/search?q=JavaScript%20applications%20using%20nunjucks%20for%20template%20compilation%2C%20reusable%20partials%2C%20layout%20rendering%20and%20data%20binding&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```javascript
const nunjucks = require('nunjucks');

const output = nunjucks.renderString('Hello {{ name }}!', { name: 'Ada' });

```

From [api.md](https://cdn.jsdelivr.net/npm/nunjucks@3.2.4/README.md)

## FAQ

### Which JavaScript template engine library should I use?

[EJS](#ejs) suits Express apps that want plain JavaScript inside templates. [Handlebars](#handlebars) suits teams that want logic-light templates with helpers and precompilation. [Nunjucks](#nunjucks) suits sites that share layouts through block inheritance.

### What is EJS?

[EJS](#ejs) is an embedded JavaScript template engine. Templates mix HTML with JavaScript control flow and escaped or raw output tags.

### EJS vs Handlebars: which should I use?

[EJS](#ejs) runs ordinary JavaScript inside templates. [Handlebars](#handlebars) keeps logic out of templates and moves it into registered helpers.

### What is Handlebars?

[Handlebars](#handlebars) is a Mustache-family template engine with escaped interpolation, helpers, partials, and precompiled templates.

### Handlebars vs Mustache: what is the difference?

[Mustache.js](#mustache) keeps templates logic-less with sections and partials. [Handlebars](#handlebars) accepts Mustache templates and adds helpers, block expressions, and precompilation.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best JavaScript template engines Handlebars Nunjucks EJS Mustache code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
