---
title: LiquidNestingDepth
description: Reports Liquid files with deeply nested control-flow structures.
source_url:
  html: >-
    https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/liquid-nesting-depth
  md: >-
    https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/liquid-nesting-depth.md
api_name: liquid
---

# Liquid​Nesting​Depth

Identifies Liquid control-flow tags nested deeper than the configured [`maxDepth`](#options). This check counts nested `if`, `unless`, `for`, `case`, and `tablerow` tags. `elsif` and `else` branches don't add nesting depth.

Reducing nesting depth helps keep theme files easier to scan and makes conditional rendering behavior easier to follow. When a file exceeds the maximum, flatten the logic by combining conditions, returning early with guard clauses, or moving nested logic into snippets that you render from the original file.

***

## Examples

The following examples contain code snippets that either fail or pass this check.

### ✗ Fail

In the following example, the innermost `if` tag is nested 11 levels deep, which is greater than the default maximum of 10:

```liquid
{% if level_1 %}
  {% if level_2 %}
    {% if level_3 %}
      {% if level_4 %}
        {% if level_5 %}
          {% if level_6 %}
            {% if level_7 %}
              {% if level_8 %}
                {% if level_9 %}
                  {% if level_10 %}
                    {% if level_11 %}
                      Too deeply nested
                    {% endif %}
                  {% endif %}
                {% endif %}
              {% endif %}
            {% endif %}
          {% endif %}
        {% endif %}
      {% endif %}
    {% endif %}
  {% endif %}
{% endif %}
```

### ✓ Pass

In the following example, the nested conditions are flattened into a single guard, so nesting depth stays at one:

```liquid
{% if level_1 and level_2 and level_3 and level_4 and level_5 and level_6 and level_7 and level_8 and level_9 and level_10 and level_11 %}
  Rendered when every condition is met
{% endif %}
```

***

## Options

The following example contains the default configuration for this check:

```yaml
LiquidNestingDepth:
  enabled: true
  severity: warning
  maxDepth: 10
```

| Parameter | Description |
| - | - |
| `enabled` | Whether this check is enabled. |
| `severity` | The [severity](https://shopify.dev/docs/storefronts/themes/tools/theme-check/configuration#check-severity) of the check. |
| `maxDepth` | The maximum allowed control-flow nesting depth for a Liquid file. |

***

## Disabling this check

Disabling this check isn't recommended. If you can't avoid violating the rule, then you should disable the check using the [comment syntax](https://shopify.dev/docs/storefronts/themes/tools/theme-check/configuration#disable-checks-using-liquid-comments). This ensures that you intentionally disable the check for each instance.

```liquid
{% # theme-check-disable LiquidNestingDepth %}
{% if level_1 %}
  {% if level_2 %}
    Nested logic
  {% endif %}
{% endif %}
{% # theme-check-enable LiquidNestingDepth %}
```

***
