--- title: "Liquid tags: cycle" description: Loops through a group of strings and outputs them one at a time for each iteration of a [`for` loop](/docs/api/liquid/tags/for). api_name: liquid source_url: html: https://shopify.dev/docs/api/liquid/tags/cycle md: https://shopify.dev/docs/api/liquid/tags/cycle.md --- # cycle Loops through a group of strings and outputs them one at a time for each iteration of a [`for` loop](https://shopify.dev/docs/api/liquid/tags/for). The `cycle` tag must be used inside a `for` loop. *** Tip Use the `cycle` tag to output text in a predictable pattern. For example, to apply odd/even classes to rows in a table. *** ## Syntax ```oobleckTag {% cycle string, string, ... %} ``` ```liquid {% for i in (1..4) -%} {% cycle 'one', 'two', 'three' %} {%- endfor %} ``` ##### Code ``` {% for i in (1..4) -%} {% cycle 'one', 'two', 'three' %} {%- endfor %} ``` ## Output ```html one two three one ``` ### Create unique cycle groups ## Syntax ```oobleckTag {% cycle string: string, string, ... %} ``` If you include multiple `cycle` tags with the same parameters, in the same template, then each set of tags is treated as the same group. This means that it's possible for a `cycle` tag to output any of the provided strings, instead of always starting at the first string. To account for this, you can specify a group name for each `cycle` tag. ```liquid {% for i in (1..4) -%} {% cycle 'one', 'two', 'three' %} {%- endfor %} {% for i in (1..4) -%} {% cycle 'one', 'two', 'three' %} {%- endfor %} {% for i in (1..4) -%} {% cycle 'group_1': 'one', 'two', 'three' %} {%- endfor %} {% for i in (1..4) -%} {% cycle 'group_2': 'one', 'two', 'three' %} {%- endfor %} ``` ##### Code ``` {% for i in (1..4) -%} {% cycle 'one', 'two', 'three' %} {%- endfor %} {% for i in (1..4) -%} {% cycle 'one', 'two', 'three' %} {%- endfor %} {% for i in (1..4) -%} {% cycle 'group_1': 'one', 'two', 'three' %} {%- endfor %} {% for i in (1..4) -%} {% cycle 'group_2': 'one', 'two', 'three' %} {%- endfor %} ``` ## Output ```html one two three one two three one two one two three one one two three one ```