Skip to content

HTML Filters

HTML filters generate complete HTML tags from URLs or filenames. They’re convenient shortcuts for creating stylesheet and script references.

Wraps a URL in a complete <link> tag for CSS stylesheets.

Syntax:

{{ url | stylesheet_tag }}

Input: A URL string (typically from asset_url).

Output: A complete <link> element.

{{ 'css/main.css' | asset_url | stylesheet_tag }}

Generated attributes:

  • rel="stylesheet"
  • type="text/css"
  • media="all"
<head>
<meta charset="utf-8">
<title>{{ page.title }}</title>
{# Load stylesheets #}
{{ 'css/normalize.css' | asset_url | stylesheet_tag }}
{{ 'css/main.css' | asset_url | stylesheet_tag }}
{{ content_for_header }}
</head>

Generates a complete <script> tag for a JavaScript file from your theme’s assets.

Syntax:

{{ 'filename.js' | script_tag }}

Input: A filename relative to the assets/ directory.

Output: A complete <script> element with the full asset URL.

{{ 'js/main.js' | script_tag }}
{# At the end of the body #}
{{ 'js/vendor.js' | script_tag }}
{{ 'js/main.js' | script_tag }}
</body>

FilterInputNeeds asset_url?
stylesheet_tagFull URLYes
script_tagFilename onlyNo (built-in)
{# Stylesheet: chain with asset_url #}
{{ 'css/main.css' | asset_url | stylesheet_tag }}
{# Script: filename only #}
{{ 'js/main.js' | script_tag }}