A RegExp that marks tags whose values are HTML-escaped by _.template() (default <%- ... %>). Part of Lodash Properties (stable in 4.x — not deprecated). Warning: never compile untrusted template strings — _.template builds executable code; Lodash plans to remove it in v5.
Set the property globally, or override it per call with options passed to _.template().
Syntax
Use _.templateSettings.escape. Start with this line.
Lodash
_.templateSettings.escape
Call
What it does
_.templateSettings.escape
Primary setting.
_.templateSettings.escape = /.../g
Assign a custom RegExp or value before compiling.
Prefer the full Lodash build when using _.template() and _.templateSettings.
Library declarations
Lodash
_.templateSettings.escape
Parameters
Parameter
Description
_.templateSettings.escape
Optional. (RegExp) Pattern for HTML-escape tags
Default pattern
Optional. (RegExp) /<%-([\s\S]+?)%>/g
Capture group
Required. Expression inside the tag
Return Value
Return Value
Description
*
RegExp (with a capturing group)
Lodash Examples
Example 1 — Official: HTML Escape Delimiter
Escape tags convert markup characters to HTML entities.
Lodash
var compiled = _.template('<b><%- value %></b>');
compiled({ 'value': '<script>' });
// → '<b><script></b>'
Same data; only the delimiter changes the safety of the output.
Lodash
var data = { value: '<i>x</i>' };
_.template('E:<%- value %>')(data);
// → 'E:<i>x</i>'
_.template('I:<%= value %>')(data);
// → 'I:<i>x</i>' (raw HTML inserted)
Threat. A crafted name tries to inject an HTML tag.
Escape tag. Encodes < / > before insert.
Result. Markup is inert text, not a live element.
Note. This does not make untrusted template source safe — only data inside escape tags.
Compatibility
Browser & Runtime Support
_.templateSettings.escape ships with Lodash full builds (stable in 4.x). It configures _.template, which runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.
Available on the [email protected] namespace. Works in evergreen browsers and current Node LTS when Lodash is installed. Treat _.template as legacy for untrusted template source.
100%With Lodash 4.x
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
.escapeLodash 4.x
Bottom line: Use escape tags for HTML-safe data insertion. Prefer per-call { escape } options over global mutation. Never compile untrusted template strings.
Frequently Asked Questions
It is a RegExp that tells _.template() which tags should HTML-escape values before insert. The default matches <\x25- ... \x25> tags.
A RegExp. Lodash uses it at compile time to find escape tags. Do not assign a callback to templateSettings.escape.
Escape tags (<\x25- \x25>) run _.escape on the value. Interpolate tags (<\x25= \x25>) insert the value as-is (not HTML-escaped).
When rendering text into HTML and you want &, <, >, ", and ' converted to entities — especially for user-provided strings.
Yes. Pass { escape: /.../g } to _.template(string, options) to override _.templateSettings.escape for that compile only.
No. Compiling untrusted templates can execute code. Use only developer-controlled templates. Lodash plans to remove _.template in v5.