---
title: 'Liquid filters: script_tag'
description: >-
  Generates an HTML `<script>` tag for a given resource URL. The tag has a
  `type` attribute of `text/javascript`.
source_url:
  html: 'https://shopify.dev/docs/api/liquid/filters/script_tag'
  md: 'https://shopify.dev/docs/api/liquid/filters/script_tag.md'
api_name: liquid
---

# script\_​tag

```oobleck
string | script_tag
```

returns [string](https://shopify.dev/docs/api/liquid/basics#string)

Generates an HTML `<script>` tag for a given resource URL. The tag has a `type` attribute of `text/javascript`.

You can add any other [HTML attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attributes) to the tag by adding a parameter that matches the attribute name, and the desired value. Boolean attributes, such as `defer` and `async`, are rendered when the value is `true`, and omitted when the value is `false`.

***

**Note:** The \<code>src\</code> attribute is managed by the filter and can\&#39;t be overridden.

***

##### Code

```liquid
{{ 'cart.js' | asset_url | script_tag }}
```

##### Output

```html
<script src="//polinas-potent-potions.myshopify.com/cdn/shop/t/4/assets/cart.js?v=83971781268232213281663872410" type="text/javascript"></script>
```

### HTML attributes

```oobleck
string | script_tag: attribute: string
```

You can specify [HTML attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attributes) by adding a parameter that matches the attribute name, and the desired value. Boolean attributes, such as `defer` and `async`, are rendered when the value is `true`, and omitted when the value is `false`. The `src` attribute is managed by the filter and can't be overridden.

##### Code

```liquid
{{ 'cart.js' | asset_url | script_tag: type: 'module', defer: true }}
```

##### Output

```html
<script src="//polinas-potent-potions.myshopify.com/cdn/shop/t/4/assets/cart.js?v=83971781268232213281663872410" type="module" defer="defer"></script>
```
