# Variable tags

Use variable tags to create new Liquid variables.

Use variable tags to create new Liquid variables.

Predefined Liquid objects can be overwritten by variables with the same name. To keep access to all Liquid objects, do not give your variables the name of a predefined object.

## assign

Creates a new named variable.

```liquid
{% assign favorite_food = 'apples' %}

My favorite food is {{ favorite_food }}.
```

```text
My favorite food is apples.
```

Variables created with `assign` can be strings or Booleans (true or false). Do not put the value in quotes if it is `true` or `false`:

```liquid
{% assign first_time_visitor = true %}
{% if first_time_visitor == true %}
  Welcome to the site!
{% endif %}
```

```text
Welcome to the site!
```

## capture

Captures the string between the opening and closing tags and assigns it to a variable. Variables created with `capture` are stored as strings.

With `capture` you can build complex strings from other variables created with `assign`.

```liquid
{% assign favorite_food = 'pizza' %}
{% assign age = 35 %}

{% capture about_me %}
I am {{ age }} and my favorite food is {{ favorite_food }}.
{% endcapture %}

{{ about_me }}
```

```text
I am 35 and my favorite food is pizza.
```

## increment

Creates a new number variable and increases its value by 1 every time `increment` is called on it. The counter starts at 0.

Here an `increment` counter creates a unique numbered class for each list item:

```liquid
<ul>
  <li class="item-{% increment counter %}">apples</li>
  <li class="item-{% increment counter %}">oranges</li>
  <li class="item-{% increment counter %}">peaches</li>
  <li class="item-{% increment counter %}">plums</li>
</ul>
```

```html
<ul>
  <li class="item-0">apples</li>
  <li class="item-1">oranges</li>
  <li class="item-2">peaches</li>
  <li class="item-3">plums</li>
</ul>
```

Variables created with `increment` are separate from variables created with `assign` or `capture`.

In the following example, `assign` creates a variable named `my_number`. The `increment` tag is then used several times on a variable with the same name. The `increment` tag does not change the value of `my_number` created with `assign`.

```liquid
{% assign my_number = 10 %}

{% increment my_number %}
{% increment my_number %}
{% increment my_number %}

{{ my_number }}
```

```text
0
1
2

10
```

## decrement

Creates a new number variable and decreases its value by 1 every time `decrement` is called on it. The counter starts at -1.

```liquid
{% decrement variable %}
{% decrement variable %}
{% decrement variable %}
```

```text
-1
-2
-3
```

Like [increment](#increment), variables declared with `decrement` are independent of variables created with `assign` or `capture`.
