In Liquid you can add a hyphen to the tag syntax {{-, -}}, {%- and -%} to strip whitespace on the left or right side of a rendered tag.
Normally every Liquid line in a template outputs an empty line in the rendered HTML, even if it outputs no text:
Order summary:
{% if customer %}
Welcome back, {{ customer.first_name }}
{% endif %}
The rendered template contains two empty lines:
Order summary:
Welcome back, Anna
Adding hyphens to the Liquid tags ({%- and -%}) removes the generated whitespace:
Order summary:
{%- if customer -%}
Welcome back, {{ customer.first_name }}
{%- endif -%}
Order summary:
Welcome back, Anna
If you only need to control whitespace on one side of a tag, add the hyphen only to the opening or the closing delimiter. In this example, the closing delimiter around customer.name has a hyphen:
Hello, {{ customer.name -}} !
Hello, Anna!