String Filters
Filters for changing, trimming, splitting, and encoding text values.
String filters change text. Use them to add, remove, replace, trim, or cut parts of a string. They are some of the most used filters in any template.
append
Add text to the end of a string. This is handy for building paths or adding units:
{{ 'hello' | append: ' world' }}Output: hello world
prepend
Add text to the start of a string. Works the same as append but puts the new text at the front:
{{ 'world' | prepend: 'hello ' }}Output: hello world
capitalize
Make the first letter of the string uppercase:
{{ 'hello world' | capitalize }}Output: Hello world
Only the very first letter changes. The rest stays as it is.
upcase
Turn every letter in the string to uppercase:
{{ 'hello' | upcase }}Output: HELLO
downcase
Turn every letter in the string to lowercase:
{{ 'HELLO' | downcase }}Output: hello
strip
Remove whitespace from both ends of a string:
{{ ' hello ' | strip }}Output: hello
lstrip
Remove whitespace from the left side only:
{{ ' hello ' | lstrip }}Output: hello (trailing space remains)
rstrip
Remove whitespace from the right side only:
{{ ' hello ' | rstrip }}Output: hello (leading space remains)
replace
Find a piece of text and swap it for something new. This changes every match in the string:
{{ 'I like cats and cats like me' | replace: 'cats', 'dogs' }}Output: I like dogs and dogs like me
replace_first
Swap only the first match and leave the rest alone:
{{ 'I like cats and cats like me' | replace_first: 'cats', 'dogs' }}Output: I like dogs and cats like me
remove
Delete every match of the given text from the string:
{{ 'hello world' | remove: 'l' }}Output: heo word
remove_first
Delete only the first match:
{{ 'hello world' | remove_first: 'l' }}Output: helo world
truncate
Shorten a string to a set number of characters. Adds an ellipsis by default:
{{ 'This is a long product description' | truncate: 20 }}Output: This is a long pr...
The total count includes the three dots at the end. You can use a different ending instead:
{{ 'This is a long product description' | truncate: 20, '—' }}Output: This is a long prod—
truncatewords
Shorten a string to a set number of words:
{{ 'This is a long product description that goes on' | truncatewords: 5 }}Output: This is a long product...
split
Break a string into an array using a delimiter:
{% assign colours = 'red,green,blue' | split: ',' %}
{% for colour in colours %}
<span>{{ colour }}</span>
{% endfor %}This creates an array with three items: red, green, and blue.
slice
Extract part of a string by position. The first character is at position 0:
{{ 'hello' | slice: 1, 3 }}Output: ell
The first argument is the start position. The second is how many characters to take. If you leave out the length, you get one character:
{{ 'hello' | slice: 0 }}Output: h
Use a negative number to count from the end:
{{ 'hello' | slice: -3, 3 }}Output: llo
handleize
Convert a string into a URL-safe handle (also called a slug). Spaces become hyphens, special characters are removed, and everything is lowercased:
{{ 'Summer Collection 2026!' | handleize }}Output: summer-collection-2026
This is useful when you need to build links or CSS class names from user-entered text:
<div class="collection-{{ collection.title | handleize }}">
{{ collection.title }}
</div>The filter handle is an alias for handleize. Both work the same way.
Encoding filters
These filters make text safe for use in HTML or URLs.
escape
Turn special HTML characters into safe codes. This stops the browser from reading the text as real HTML tags:
{{ '<p>Hello & welcome</p>' | escape }}Output: <p>Hello & welcome</p>
escape_once
Works like escape, but it will not encode text that has been encoded before. This keeps you safe from double encoding:
{{ '<p>Already escaped & safe</p>' | escape_once }}Output stays the same. No double encoding.
url_encode
Encode a string for use in a URL:
{{ 'hello world' | url_encode }}Output: hello+world
url_decode
Decode a URL-encoded string back to plain text:
{{ 'hello+world' | url_decode }}Output: hello world
HTML filters
strip_html
Remove all HTML tags from a string. Only the plain text inside the tags is kept:
{{ '<p>Hello <strong>world</strong></p>' | strip_html }}Output: Hello world
strip_newlines
Remove all line breaks from a string:
{{ product.description | strip_newlines }}Useful when you need a single line of text, such as a meta description.
newline_to_br
Convert line breaks to HTML <br> tags:
{{ product.description | newline_to_br }}Each \n in the text becomes a <br> tag so the line breaks show on the page.
pluralize
Choose between singular and plural forms based on a number:
{{ cart.item_count }} {{ cart.item_count | pluralize: 'item', 'items' }}If the count is 1, the output is 1 item. For any other number, the output uses the second argument: 3 items.