Skip to main content

video_tag

media | video_tag
returns string

Generates an HTML <video> tag for a given video.


Note

When mp4 videos are uploaded, Shopify generates an m3u8 file as an additional video_source. An m3u8 file enables video players to leverage HTTP live streaming (HLS), resulting in an optimized video experience based on the user's internet connection. If loop is enabled, the HLS source is not used in order to allow progessive download to cache the video.

If the m3u8 source isn't supported, then the player falls back to the mp4 source.


{% for media in product.media %}
{% if media.media_type == 'video' %}
{{ media | video_tag }}
{% endif %}
{% endfor %}

Output

<video playsinline="playsinline" preload="metadata" aria-label="Potion beats" poster="//polinas-potent-potions.myshopify.com/cdn/shop/products/4edc28a708b7405093a927cebe794f1a.thumbnail.0000000_small.jpg?v=1655255324"><source src="//polinas-potent-potions.myshopify.com/cdn/shop/videos/c/vp/4edc28a708b7405093a927cebe794f1a/4edc28a708b7405093a927cebe794f1a.HD-1080p-7.2Mbps.mp4?v=0" type="video/mp4"><img src="//polinas-potent-potions.myshopify.com/cdn/shop/products/4edc28a708b7405093a927cebe794f1a.thumbnail.0000000_small.jpg?v=1655255324"></video>

Rendered output

media | video_tag: image_size: string

Specify the dimensions of the video's poster image in pixels.

{% for media in product.media %}
{% if media.media_type == 'video' %}
{{ media | video_tag: image_size: '400x' }}
{% endif %}
{% endfor %}

Output

<video playsinline="playsinline" preload="metadata" aria-label="Potion beats" poster="//polinas-potent-potions.myshopify.com/cdn/shop/products/4edc28a708b7405093a927cebe794f1a.thumbnail.0000000_400x.jpg?v=1655255324"><source src="//polinas-potent-potions.myshopify.com/cdn/shop/videos/c/vp/4edc28a708b7405093a927cebe794f1a/4edc28a708b7405093a927cebe794f1a.HD-1080p-7.2Mbps.mp4?v=0" type="video/mp4"><img src="//polinas-potent-potions.myshopify.com/cdn/shop/products/4edc28a708b7405093a927cebe794f1a.thumbnail.0000000_400x.jpg?v=1655255324"></video>

Rendered output

Anchor to Optional supported HTML5 attributes

Optional supported HTML5 attributes

media | video_tag: attribute: boolean

video_tag supports all HTML5 video attributes. For example:

AttributeValue
autoplayWhether to automatically play the video after it’s loaded. Accepted values:true,false
loopWhether to loop the video. Accepted values:true,false
mutedWhether to mute the video’s audio. Accepted values:true,false
controlsWhether a user can control the video playback. Accepted values:true,false
{% for media in product.media %}
{% if media.media_type == 'video' %}
{{ media | video_tag: autoplay: true, loop: true, muted: true, controls: true }}
{% endif %}
{% endfor %}

Output

<video playsinline="playsinline" autoplay="autoplay" loop="loop" muted="muted" controls="controls" preload="metadata" aria-label="Potion beats" poster="//polinas-potent-potions.myshopify.com/cdn/shop/products/4edc28a708b7405093a927cebe794f1a.thumbnail.0000000_small.jpg?v=1655255324"><source src="//polinas-potent-potions.myshopify.com/cdn/shop/videos/c/vp/4edc28a708b7405093a927cebe794f1a/4edc28a708b7405093a927cebe794f1a.HD-1080p-7.2Mbps.mp4?v=0" type="video/mp4"><img src="//polinas-potent-potions.myshopify.com/cdn/shop/products/4edc28a708b7405093a927cebe794f1a.thumbnail.0000000_small.jpg?v=1655255324"></video>

Rendered output

Was this page helpful?