Skip to main content

StylesheetTagInWrongFile

Identifies {% stylesheet %} tags in files where stylesheet tags aren't valid. Theme Check reports a stylesheet tag unless it's in a section, block, or snippet file.

Shopify bundles the CSS from stylesheet tags in section, block, and snippet files only, so keep these tags out of templates, layouts, and other theme files. For more information, refer to JavaScript and stylesheet tags.


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

In the following example, templates/index.liquid contains a {% stylesheet %} tag:

{% stylesheet %}
.template-index {
display: grid;
}
{% endstylesheet %}

In the following example, snippets/card.liquid is a snippet file, so it can contain a {% stylesheet %} tag:

{% stylesheet %}
.card {
display: grid;
}
{% endstylesheet %}

The following example contains the default configuration for this check:

StylesheetTagInWrongFile:
enabled: true
severity: error
ParameterDescription
enabledWhether this check is enabled.
severityThe severity of the check.

Anchor to Disabling this checkDisabling 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. This ensures that you intentionally disable the check for each instance.

{% # theme-check-disable StylesheetTagInWrongFile %}
{% stylesheet %}
.template-index {
display: grid;
}
{% endstylesheet %}
{% # theme-check-enable StylesheetTagInWrongFile %}

Was this page helpful?