css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv
CodePen probably won't work great in this browser. We generally only support the major desktop browsers like Chrome, Firefox, Safari, and Edge. Use this one at your own risk! If you're looking to test things, try looking at Pens/Projects in Debug View.
user profile image

We are going to pull and play a YouTube video, not when the page loads, but when the user asks to do so. This method is popularly known as lazy loading–it will minimise the HTTP requests on initial page load, and ultimately improve the page’s performance.

Read the full tutorial.

This Pen is a fork of Thoriq Firdaus's Pen Youtube Lazy Loading.


  1. Thank you for that, dudes ! It makes the job quite perfectly !

    2 questions then, if I may :

    • autoplay=1 does not to work on iPads & iphones (means users have to click twice to launch the video) Is this fixable & how ?
    • in some case I find myself with videos that has no thumbnails like /sddefault.jpg. How would it be possible, in such case, to fill in 'var source' with an alternative img, home hosted ?

    Thanks in advance ;)

Leave a Comment Markdown supported. Click @usernames to add to comment.

You must be logged in to comment.