Lazy Load YouTube Videos in Blogger (Click to Play)
Embed YouTube videos in Blogger that load only when clicked. Faster pages, better Core Web Vitals, one line of HTML.
A normal YouTube embed loads the whole YouTube player, about 1 MB of scripts, even if nobody presses play. That slows down every post that has a video. The theme shows a light preview instead: the video's thumbnail with a play button. The real player loads only when a reader clicks.
Big Buck Bunny — Blender open moviePaste every example on this page in the post editor's HTML view, not in Compose view.
How it's built
Copy the video's address from YouTube, then write it as a link with the class video. The link text becomes the title on the preview.
<a class="video" href="https://www.youtube.com/watch?v=VIDEO_ID">Video title</a>
Any YouTube address works: the long youtube.com/watch?v= address, the short youtu.be/ one from the Share button, or a /shorts/ address.
If scripts are blocked, the preview stays a normal link that opens the video on YouTube, so readers can still watch it.
Options
Show the video length
Add data-time to show the length in the corner, like on YouTube.
<a class="video" href="..." data-time="10:35">Video title</a>
Start at a certain time
Add data-start with the number of seconds. This video starts at 1:30:
<a class="video" href="..." data-start="90">Video title</a>
A t= in the address, like youtu.be/VIDEO_ID?t=90, works too.
YouTube Shorts
Add short for vertical videos. The preview becomes tall and narrow, and sits in the middle of the post.
<a class="video short" href="https://www.youtube.com/shorts/VIDEO_ID">Short title</a>
Add a caption
Put the video in a <figure> with a <figcaption>, the same way as images.
<figure> <a class="video" href="...">Video title</a> <figcaption>Your caption.</figcaption> </figure>
Privacy and speed
- The player uses youtube-nocookie.com, so YouTube doesn't set tracking cookies until the reader plays the video.
- The thumbnail loads only when the reader scrolls near it.
- When the reader moves the mouse over the preview, the theme starts connecting to YouTube, so the video begins faster after the click.
Videos you already published
Videos added with Blogger's own Insert video button keep working. The theme makes them fill the post width and keeps their shape on phones. They still load the full player, though. To make an old post faster, replace the video with a video link.
Autoplay after the click can be blocked by some browsers. If that happens, the reader just presses play once more in the YouTube player.
Quick reference
| You want | Write |
|---|---|
| Video | <a class="video" href="YouTube address">Title</a> |
| Shorts | class="video short" |
| Show length | data-time="10:35" |
| Start time | data-start="90" (seconds) |
| Caption | wrap in <figure> + <figcaption> |

Written by
محمد العبدلله
Comments 0