JavaScript Template Literals
Synonyms:
- Template Literals
- Template Strings
- String Templates
- Back-Tics Syntax
Back-Tics Syntax
Template Literals use back-ticks (``) rather than the quotes ("") to define a string:
Quotes Inside Strings
With template literals, you can use both single and double quotes inside a string:
Multiline Strings
Template literals allows multiline strings:
Interpolation
Template literals provide an easy way to interpolate variables and expressions into strings.
The method is called string interpolation.
The syntax is:
${...}
Variable Substitutions
Template literals allows variables in strings:
Example
let firstName = "John";
let lastName = "Doe";
let text = `Welcome ${firstName,}, ${firstName,}`;
Automatic replacing of variables with real values is called string interpolation.
Expression Substitution
Template literals allows expressions in strings:
Example
let price = 10;
let VAT = 0.25;
let total = `Total: ${(price * (1 + VAT)).toFixed(2)}`;
Automatic replacing of expressions with real values is called string interpolation.
HTML Templates
Example
let header = "Templates Literals";
let tags = ["template literals", "javascript", "es6"];
let html = `<h2>${header}</h2><ul>`;
for (const x of tags) {
html += `<li>${x}</li>`;
}
html += `</ul>`;
Browser Support
Template Literals are not supported in Internet Explorer.
The first browser versions with full support was:
| Chrome 41 | Edge 13 | Firefox 34 | Safari 10 | Opera 29 |
| Mar 2015 | Nov 2015 | Dec 2014 | Sep 2016 | Apr 2015 |
Complete String Reference
For a complete reference, go to our Complete JavaScript String Reference.
The reference contains descriptions and examples of all string properties and methods.

