
TikTok Videos
A horizontally scrollable video gallery designed to mimic the TikTok interface. It features vertical 9:16 aspect ratio videos with custom play/pause overlays, gradient borders, and synchronized playback that pauses other videos when a new one starts.
- Horizontal scroll-snap slider
- 9:16 vertical video aspect ratio
- Single-active playback logic
- Auto-hiding pause controls
- Gradient border styling
- Displaying User Generated Content (UGC) on the homepage.
- Showcasing product demonstrations in a mobile-first format.
- Adding a social media style feed to collection pages.
- Shopify Online Store 2.0
- Most Shopify themes
The code
1<!DOCTYPE html>2<html lang="en">34<head>5 <meta charset="UTF-8">6 <meta name="viewport" content="width=device-width, initial-scale=1.0">7 <title>TikTok Video Viewer</title>8 <style>9 .slider-containerv8 {10 position: relative;11 width: 100%;12 overflow-x: scroll;13 display: flex;14 align-items: center;15 scroll-snap-type: x mandatory;16 max-width: 1200px;17 margin-left: auto;18 margin-right: auto;19 padding: 0px 10px;20 }2122 .sliderv8 {23 display: flex;24 gap: 10px;25 scroll-snap-type: x mandatory;2627 }2829 .slidev8 {30 flex: 0 0 60%;31 max-width: 360px;32 scroll-snap-align: center;33 display: flex;34 justify-content: center;35 align-items: center;36 position: relative;3738 }39 @media screen and (min-width: 769px){40 .slidev8 {41 flex: 0 0 50%;42 max-width: 260px;43 scroll-snap-align: center;44 display: flex;45 justify-content: center;46 align-items: center;47 position: relative;4849 }50 }5152 .tiktok-videov8 {53 width: 100%;54 height: auto;55 aspect-ratio: 9 / 16;56 border-radius: 10px;57 display: block;58 }5960 .play-buttonv8,61 .pause-buttonv8 {62 position: absolute;63 width: 50px;64 height: 50px;65 background: rgba(0, 0, 0, 0.6);66 color: white;67 border-radius: 50%;68 display: flex;69 justify-content: center;70 align-items: center;71 font-size: 20px;72 cursor: pointer;73 z-index: 10;7475 }7677 .play-buttonv8 {78 display: flex;79margin-left: 2px;80 }8182 .pause-buttonv8 {83 display: none;84 opacity: 1;85 transition: opacity 0.5s ease;86 }8788 .pause-buttonv8.hiddenv8 {89 opacity: 0;90 }9192 .slider-containerv8::-webkit-scrollbar {93 height: 10px;94 }9596 .slider-containerv8::-webkit-scrollbar-thumb {97 background: #aaa;98 border-radius: 10px;99 }100101 .slider-containerv8::-webkit-scrollbar-track {102 background: #ddd;103 }104 .with-borderv8 {105 padding: 4px;106 border-radius: 10px;107background: linear-gradient(0deg, #fe2d52, #28ffff);108 }109 </style>110 <script>111 document.addEventListener("DOMContentLoaded", () => {112 const slides = document.querySelectorAll(".slidev8");113114 slides.forEach(slide => {115 const playButton = slide.querySelector(".play-buttonv8");116 const pauseButton = slide.querySelector(".pause-buttonv8");117 const video = slide.querySelector("video");118119 let hidePauseButtonTimeout;120121 const showPauseButton = () => {122 pauseButton.classList.remove("hiddenv8");123 clearTimeout(hidePauseButtonTimeout);124 hidePauseButtonTimeout = setTimeout(() => {125 pauseButton.classList.add("hiddenv8");126 }, 1000);127 };128129 playButton.addEventListener("click", () => {130 // Pause other videos131 document.querySelectorAll("video").forEach(v => {132 if (v !== video) {133 v.pause();134 v.classList.remove("playingv8");135 }136 });137138 // Play selected video139 video.play();140 video.classList.add("playingv8");141 playButton.style.display = "none";142 pauseButton.style.display = "flex";143 showPauseButton();144 });145146 pauseButton.addEventListener("click", () => {147 video.pause();148 video.classList.remove("playingv8");149 playButton.style.display = "flex";150 pauseButton.style.display = "none";151 });152153 video.addEventListener("mousemove", showPauseButton);154 video.addEventListener("click", showPauseButton);155156 video.addEventListener("play", () => {157 playButton.style.display = "none";158 pauseButton.style.display = "flex";159 showPauseButton();160 });161162 video.addEventListener("pause", () => {163 playButton.style.display = "flex";164 pauseButton.style.display = "none";165 });166 });167 });168 </script>169</head>170171<body>172 <div class="slider-containerv8">173 <div class="sliderv8">174 <div class="slidev8">175 <div class = "with-borderv8">176 <video class="tiktok-videov8" poster="https://cdn.shopify.com/s/files/1/0727/7268/1977/files/Captura_de_pantalla_2025-02-20_155011_1.png?v=1740085420">177 <source src="https://cdn.shopify.com/videos/c/o/v/49f49e5ff92f404b89bdedd6fc371077.mp4" type="video/mp4">178 Your browser does not support the video tag.179 </video>180 </div>181 <div class="pause-buttonv8 hiddenv8">❚❚</div>182 <div class="play-buttonv8">▷</div>183 </div>184 <div class="slidev8">185 <div class = "with-borderv8">186 <video class="tiktok-videov8" poster="https://cdn.shopify.com/s/files/1/0727/7268/1977/files/Captura_de_pantalla_2025-02-20_155225_1.png?v=1740085420">187 <source src= "https://cdn.shopify.com/videos/c/o/v/d4dfdd955f2840b1b63b223ecc77cafd.mp4" type="video/mp4">188 Your browser does not support the video tag.189 </video>190 </div>191 <div class="pause-buttonv8 hiddenv8">❚❚</div>192 <div class="play-buttonv8">▷</div>193 </div>194 <div class="slidev8">195 <div class = "with-borderv8">196 <video class="tiktok-videov8" poster="https://cdn.shopify.com/s/files/1/0727/7268/1977/files/Captura_de_pantalla_2025-02-20_155258_1.png?v=1740085420">197198 <source src="https://cdn.shopify.com/videos/c/o/v/171162a47d1b44f1a042656ad7f85d02.mp4" type="video/mp4">199 Your browser does not support the video tag.200 </video>201 </div>202 <div class="pause-buttonv8 hiddenv8">❚❚</div>203 <div class="play-buttonv8">▷</div>204 </div>205 <div class="slidev8">206 <div class = "with-borderv8">207 <video class="tiktok-videov8" poster="https://cdn.shopify.com/s/files/1/0727/7268/1977/files/Captura_de_pantalla_2025-02-20_155328_1.png?v=1740085420">208 <source src="https://cdn.shopify.com/videos/c/o/v/d8d1ca1c53114802a2d840e57fcd7e75.mp4" type="video/mp4">209 Your browser does not support the video tag.210 </video>211 </div>212 <div class="pause-buttonv8 hiddenv8">❚❚</div>213 <div class="play-buttonv8">▷</div>214 </div>215 <div class="slidev8">216 <div class = "with-borderv8">217 <video class="tiktok-videov8" poster="https://cdn.shopify.com/s/files/1/0727/7268/1977/files/Captura_de_pantalla_2025-02-20_155354_1.png?v=1740085420">218 <source src="https://cdn.shopify.com/videos/c/o/v/354c7787f58b457a90f0f0f8751470d4.mp4" type="video/mp4">219 Your browser does not support the video tag.220 </video>221 </div>222 <div class="pause-buttonv8 hiddenv8">❚❚</div>223 <div class="play-buttonv8">▷</div>224 </div>225 <div class="slidev8">226 <div class = "with-borderv8">227 <video class="tiktok-videov8" poster="https://cdn.shopify.com/s/files/1/0727/7268/1977/files/Captura_de_pantalla_2025-02-20_155434_1.png?v=1740085420">228 <source src="https://cdn.shopify.com/videos/c/o/v/38d2b924b27e425d939ddba898550c3c.mp4" type="video/mp4">229 Your browser does not support the video tag.230 </video>231 </div>232 <div class="pause-buttonv8 hiddenv8">❚❚</div>233 <div class="play-buttonv8">▷</div>234 </div>235 <div class="slidev8">236 <div class = "with-borderv8">237 <video class="tiktok-videov8" poster="https://cdn.shopify.com/s/files/1/0727/7268/1977/files/Captura_de_pantalla_2025-02-20_155523_1.png?v=1740085420">238 <source src="https://cdn.shopify.com/videos/c/o/v/f9070d05630d4a73aa7c4c6133e21748.mp4" type="video/mp4">239 Your browser does not support the video tag.240 </video>241 </div>242 <div class="pause-buttonv8 hiddenv8">❚❚</div>243 <div class="play-buttonv8">▷</div>244 </div>245 <div class="slidev8">246 <div class = "with-borderv8">247 <video class="tiktok-videov8" poster="https://cdn.shopify.com/s/files/1/0727/7268/1977/files/Captura_de_pantalla_2025-02-20_155602_1.png?v=1740085420">248 <source src="https://cdn.shopify.com/videos/c/o/v/7b2f0f5c16c147769a931b8352840c80.mp4" type="video/mp4">249 Your browser does not support the video tag.250 </video>251 </div>252 <div class="pause-buttonv8 hiddenv8">❚❚</div>253 <div class="play-buttonv8">▷</div>254 </div>255 </div>256 </div>257</body>258259</html>
How to install TikTok Videos on your Shopify theme
This snippet belongs in sections/main-product.liquid, directly under the Add to cart button, where it reinforces the purchase decision. Expect the whole job to take about 15–25 minutes.
- 1From your Shopify admin, open Online Store → Themes, click the … button on your live theme and choose Duplicate. Always work on a copy so you can roll back instantly.
- 2On the duplicated theme, click … → Edit code to open the theme code editor.
- 3Open sections/main-product.liquid in the file tree. If your theme uses different file names, search for the template that renders the area where you want the block to show up.
- 4Click Copy code on this page, then paste the snippet directly under the Add to cart button, where it reinforces the purchase decision.
- 5The snippet ships with its own scoped
<style>block, so you do not need to touchbase.cssortheme.css. If you prefer to keep CSS centralised, move the contents of the style tag into your theme stylesheet and delete the inline block. - 6Keep the
<script>tag at the end of the snippet. It only runs once the surrounding markup exists in the DOM, so moving it higher up the file can break the behaviour. - 7Click Save, then hit Preview and check the block on desktop, tablet and mobile widths.
- 8When you are happy with the result, publish the duplicated theme from Online Store → Themes → Actions → Publish.
How to customise it
Every value below lives inside the snippet, so you can adapt TikTok Videos to your brand without touching the rest of the theme.
- Colours — the snippet uses
#aaa,#ddd,#fe2d52,#28ffff. Replace those values inside the style block with your brand palette, keeping at least a 4.5:1 contrast ratio between text and background so the block stays accessible. - Gradient — swap the
linear-gradient(...)declaration for a flat background colour if you want a more minimal, theme-native look. - Sizing — adjust the font-size values (20px) and the padding so the block carries the same visual weight as the elements around it.
- Corners —
border-radius: 10pxcontrols the roundness. Set it to 0 for a sharper editorial look, or increase it for a softer, app-like feel. - Copy — rewrite the hard-coded text (for example “TikTok Video Viewer”) in your own brand voice, and translate it if you sell in more than one language.
- Responsive behaviour — the
@mediaquery defines the mobile breakpoint. Adjust the pixel value if your theme uses a different breakpoint scale.
Common mistakes to avoid
These are the issues merchants run into most often when installing a snippet like this one.
- Editing the live theme directly. Duplicate it first — a single unbalanced Liquid tag can take a storefront down mid-campaign.
- Pasting the code into the wrong file. Dropped into
layout/theme.liquidinstead ofsections/main-product.liquid, this block will render on every page of the store, including ones where it makes no sense. - Renaming the CSS classes in the markup but not in the style block, or vice versa. The class names have to match exactly or the styling silently disappears.
- Adding the snippet twice on the same page. The script targets its selector, so two copies can conflict or double-fire.
- Publishing without testing on a real phone. Most Shopify traffic is mobile, and layout problems almost always surface there first.
Performance notes
What this block costs you in load time, and how to keep that cost at zero.
- The CSS is inline and scoped to this block, so it adds no extra network request. At a few kilobytes it has no measurable effect on your Lighthouse score.
- The JavaScript is vanilla — no jQuery, no external library, no additional request. Keep it after the markup so it never blocks rendering.
- Run PageSpeed Insights before and after you add the block so you have a concrete number rather than a guess.
SEO & accessibility
How to add this block without damaging your on-page structure or your rich results.
- Nothing in this snippet should replace your page
<h1>. Keep product and page headings intact and use<h2>or<h3>for the block's own heading so the document outline stays clean. - If the block shows review or rating content, keep it consistent with the structured data your review app already outputs. Duplicating or contradicting rating markup can cost you the rich result entirely.
- The block does not create a new URL, so there is no canonical or indexing change to make. It improves on-page engagement signals rather than crawlability.
TikTok Videos — questions merchants ask
Will this snippet work with my theme?
It is built with standard Liquid, HTML and CSS, so it works with Dawn and virtually every Online Store 2.0 theme, as well as most vintage themes. The only thing that changes between themes is the file you paste it into — if yours has no sections/main-product.liquid, look for the equivalent template that renders the same area.
Do I need an app to use it?
No. This is theme code you own outright: no monthly fee, no third-party script tag, and no app that can break your storefront the next time it updates.
How long does it take to add “TikTok Videos” to a store?
Most merchants have it live in under fifteen minutes — duplicate the theme, paste the code, adjust the colours and copy, preview on mobile, publish.
The block appears but nothing happens. What is wrong?
That is almost always a script-order problem. Check that the script tag is still at the bottom of the snippet and that the markup was not pasted inside another script or a Liquid comment block. Open your browser console and look for an error naming the snippet's selector.
The styling looks broken after pasting. How do I fix it?
Confirm you copied the whole snippet including the closing style tag, then check whether one of your theme's own CSS rules is overriding it. If a theme rule wins, increase the specificity of the snippet's selector rather than scattering !important through the file.
Will it slow my store down?
Not meaningfully. It is inline markup with scoped CSS and at most a few lines of vanilla JavaScript — no external libraries, no extra HTTP request. Optimising your product images will always have a far bigger impact on load time.
Can I use it on a client store or a commercial project?
Yes. Every snippet in the MCO Hub library is free to copy, modify and ship on any store, including client work. Attribution is appreciated but not required.
Related snippets
Keep exploring
Guides
Shopify Liquid
Tools



