play youtube when on viewpoint on src code example

Example 1: iframe autoplay

<!-- 
first add ?autoplay=1 to your video url
then add allow='autoplay' attribute to your iframe element
-->
<iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ?autoplay=1" allow='autoplay'></iframe>

Example 2: load youtube iframe player api

// This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

Tags:

Html Example