Liquid cheat sheet
A comprehensive Liquid cheat sheet covering syntax, filters, tags, and best practices for dynamic web content and e-commerce - Shopify - development.
takes up the same width as a normal space.
 
) 
) 
) 
)​
)All of these space entities provide fine control over spacing in HTML content and Cascading Style Sheets (CSS), allowing for precise text formatting. Simply use them inside your text, e.g.:
<p>I like en space and em space.<br>
They rock more than hair space.</p>
Which will be rendered as:
I like en space and em space.
They rock more than hair space.
<code>
element #If you want to preserve spaces inside a code
element, you should use non-breaking spaces (
). Here is an example:
<p><code>This code has spaces.</code></p>
The spaces are visible when the page is rendered:
This code has spaces.
Of course, the text will take the styling of the <code>
element.
<pre>
element #The <pre>
element preserves all spaces and line breaks exactly as they are written in the code:
<pre>
This text has multiple spaces.
</pre>
The output will maintain the spaces exactly as they appear in the source code:
This text has multiple spaces.
Of course, the text will take the styling of the <pre>
element.
word-spacing
#The word-spacing
property in (CSS) controls the space between words. Example:
<p style="word-spacing: 20px;">This is an example of word spacing.</p>
The words will be spaced 20 pixels apart:
This is an example of word spacing.
letter-spacing
#The letter-spacing
property adjusts the space between characters:
<p style="letter-spacing: 5px;">Letter spacing example</p>
Each letter in the paragraph will be spaced 5 pixels apart:
Letter spacing example
You can use inline CSS styles to add spaces directly in an HTML element:
<p style="margin-left: 30px;">This paragraph has left margin space.</p>
This method is useful when you need precise control over spacing:
This paragraph has left margin space.
JavaScript can be used to modify spacing dynamically. For example, you can change the word-spacing
property using JavaScript:
<p id="text">This is a JavaScript example.</p>
<button onclick="increaseSpacing()">Increase Space</button>
<button onclick="resetSpacing()">Reset Space</button>
<script>
function increaseSpacing() {
document.getElementById("text").style.wordSpacing = "10px";
}
function resetSpacing() {
document.getElementById("text").style.wordSpacing = "normal";
}
</script>
When you click the “Increase Space” button, the space between words will increase dynamically. Clicking the “Reset Space” button will return the spacing to its default setting:
This is a JavaScript example.
Sources and recommended, further resources on the topic:
How to insert spaces in HTML by Jonas Jared Jacek is licensed under CC BY-SA 4.0.
This license requires that reusers give credit to the creator. It allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, for noncommercial purposes only. To give credit, provide a link back to the original source, the author, and the license e.g. like this:
<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://www.ditig.com/how-to-insert-spaces-in-html">How to insert spaces in HTML</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://www.j15k.com/">Jonas Jared Jacek</a> is licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="license noopener noreferrer">CC BY-SA 4.0</a>.</p>
For more information see the Ditig legal page.
“Make errors impossible. Making it impossible for the user to make errors is the best way to eliminate error messages.”