Search code examples
javascripthtmltemplate-literals

How to use spaces in Template Literals?


I have a <li> element showing dynamic content using Template Literals (template strings).

<li className='floatLeft'><span><b>Galley Details</b></span> <br/>{`${galleyCartsDet[0].quantity} Full Cart ${galleyCartsDet[1].quantity} Half Cart${galleyCartsDet[2].quantity} SMU${galleyCartsDet[3].quantity} Stowage`}</li>

How can I use spaces in the given template string?

`${galleyCartsDet[0].quantity} Full Cart ${galleyCartsDet[1].quantity} Half Cart${galleyCartsDet[2].quantity} SMU${galleyCartsDet[3].quantity} Stowage`

Solution

  • You can use spaces in a template string in this way:

    `\u00A0\u00A0${option.value}\u00A0\u00A0`
    

    \u00A0 = non-breaking space
    \u0020 = normal space