Template literal
A JavaScript string literal delimited by backticks that supports multiline text and embedded expressions.
Web Components in Action
An ECMAScript string literal delimited by backticks that supports interpolation and multiline content.
- How it is used
- Uses template literals to keep multiline HTML/CSS readable and insert values into Web Component markup.
- How deep it goes
- Works through backticks, placeholders, imported render functions, and generated menus; defers fuller expression syntax to an appendix.
- Examples
- Builds a business-card customizer with interpolated contact fields and generated logo and background selectors.
- What you can do after
- Build it from scratch: place a Web Component’s HTML/CSS in a separate JavaScript module and generate markup from supplied values.
Read how Web Components in Action explains template literal →
Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond
A JavaScript literal syntax that supports embedded expressions, multiline text, and optional tag functions for processing the literal parts and substitutions.
- How it is used
- Makes dynamic greetings and product HTML readable without chains of string concatenation.
- How deep it goes
- Explains interpolation, multiline literals, tagging, and evaluation-time reuse limits; poses tag implementation as an exercise.
- Examples
- Uses cart messages, multiline greetings, product HTML, and an object-to-HTML-attributes tag exercise.
- What you can do after
- Practice/perform writing interpolated multiline strings, wrapping literals for reuse, and designing a tag for object values.
Building User-Friendly DSLs
A JavaScript literal syntax delimited by backticks that can represent multiline strings and interpolate expressions.
- How it is used
- Uses ES2015 template literals with embedded expressions to implement template functions that generate code from pieces of an AST.
- How deep it goes
- Explains multiline strings, backtick delimiters, embedded expressions, and template-function use, while deferring detailed reference information.
- Examples
- Demonstrates a generatedIndexJsx template function copying runtime/index.jsx and runs it through the generator command.
- What you can do after
- Build it from scratch: create a template function that emits generated code and invoke it from a generator.
Read how Building User-Friendly DSLs explains template literal →
Also covered in
- JavaScript in DepthIn early access (MEAP)
- React in Depth
- Pro Angular 16
- Web Component Development with Modern Libraries and ToolingIn early access (MEAP)
- Essential TypeScript 5, Third Edition
- Vanilla WebIn early access (MEAP)
What to know first
- JavaScriptJavaScript is a high-level, dynamically typed programming language standardized as ECMAScript and used for web and general-purpose programming.
- CSSCSS (Cascading Style Sheets) is a stylesheet language for specifying the presentation and layout of structured documents.
- HTMLHTML is the standard markup language for structuring content and elements in documents on the web.
- stringA string is a programming-language value representing textual data as an ordered sequence of characters or encoded units.
Related concepts
- interpolationuses · Interpolation is the construction of text by inserting evaluated values or expressions into designated placeholders in a string or template.
- concatenationalternative to · Concatenation is the operation of joining ordered sequences end to end, or along a specified dimension, to form a combined sequence or structure.
- JavaScriptkind of · JavaScript is a high-level, dynamically typed programming language standardized as ECMAScript and used for web and general-purpose programming.
- string literalalternative to · A string literal is a fixed sequence of text characters written directly in a programming or data-language expression as a string value, rather than computed from other data.
- literalkind of · A literal is a language construct that directly denotes a fixed value or specifies an exact value permitted by a type.
- HTMLuses · HTML is the standard markup language for structuring content and elements in documents on the web.
Questions about template literal
What is template literal?
A JavaScript string literal delimited by backticks that supports multiline text and embedded expressions.
Which Manning books explain template literal?
Web Components in Action, Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond and Building User-Friendly DSLs.
What should I know before learning template literal?
Manning books that teach template literal usually introduce JavaScript, CSS, HTML and string first.
What is the difference between template literal and concatenation?
A JavaScript string literal delimited by backticks that supports multiline text and embedded expressions. Concatenation is the operation of joining ordered sequences end to end, or along a specified dimension, to form a combined sequence or structure.
What is template literal a kind of?
Template literal is a kind of JavaScript. JavaScript is a high-level, dynamically typed programming language standardized as ECMAScript and used for web and general-purpose programming.
What is template literal also called?
Template literal is also called template string.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


