Maximillian Laumeister

How To Hide Related Videos In YouTube Embeds (2018 Update)

How To Remove Related Videos In YouTube Embeds 2018 Update

When an embedded YouTube video is done playing, the YouTube player normally shows several related videos, also known as “suggested videos”. However, there are reasons a website owner might want these related videos not to show - due to branding preferences or simply wanting a cleaner user experience.

Before September 2018, a webmaster could disable related videos on YouTube embeds by simply adding ?rel=0 to the iframe’s src like this:

<iframe width="640" height="360" src="" frameborder="0"></iframe>

However in September 2018, YouTube changed their embed code so that this rel=0 trick no longer fully disables related videos (instead it makes it so the related videos come from the same YouTube channel as the video displayed). It is no longer possible to fully disable related videos using rel=0.

The behavior for the rel parameter is changing on or after September 25, 2018. The effect of the change is that you will not be able to disable related videos. However, you will have the option of specifying that the related videos shown in the player should be from the same channel as the video that was just played.

YouTube Player API Release Notes - August 23, 2018

This option was likely deprecated because it was not seeing a lot of use. But for those of us who still want to be able to embed YouTube videos without related videos showing at the end, there is a snippet of code we can use as a workaround. This is the final result (pay attention at the end of the video):

And this is the embed code you can use to achieve it:

    <!-- --><style>#playerWrap{display: inline-block; position: relative;}#playerWrap.shown::after{content:""; position: absolute; top: 0; left: 0; bottom: 0; right: 0; cursor: pointer; background-color: black; background-repeat: no-repeat; background-position: center; background-size: 64px 64px; background-image: url(data:image/svg+xml;utf8;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMjgiIGhlaWdodD0iMTI4IiB2aWV3Qm94PSIwIDAgNTEwIDUxMCI+PHBhdGggZD0iTTI1NSAxMDJWMEwxMjcuNSAxMjcuNSAyNTUgMjU1VjE1M2M4NC4xNSAwIDE1MyA2OC44NSAxNTMgMTUzcy02OC44NSAxNTMtMTUzIDE1My0xNTMtNjguODUtMTUzLTE1M0g1MWMwIDExMi4yIDkxLjggMjA0IDIwNCAyMDRzMjA0LTkxLjggMjA0LTIwNC05MS44LTIwNC0yMDQtMjA0eiIgZmlsbD0iI0ZGRiIvPjwvc3ZnPg==);}</style><div id="playerWrapOuter"> <div id="playerWrap"> <iframe width="640" height="360" src="" frameborder="0" ></iframe></div></div><script>(function(){let playerFrame=document.currentScript.previousElementSibling.querySelector("iframe"); let tag=document.createElement('script'); tag.src=""; let firstScriptTag=document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); let player; window.onYouTubeIframeAPIReady=function(){player=new YT.Player(playerFrame,{events:{'onStateChange': onPlayerStateChange}});}; window.onPlayerStateChange=function(event){if ({document.getElementById("playerWrap").classList.add("shown");}}; document.getElementById("playerWrap").addEventListener("click", function(){player.seekTo(0); document.getElementById("playerWrap").classList.remove("shown");});})();</script>

IMPORTANT: After you paste the code onto your site, replace the highlighted part with the Video ID of the YouTube video you want to embed.

Under the hood, the script hooks into the YouTube API to determine whether the video is playing. When the video ends, the script shows a custom “replay” button over the entire embed. When the replay button is clicked, the video plays over from the beginning again. If the user pauses the video then related videos may still display - this script is only for the end-screen!

This code has been tested in Chrome, Firefox, Edge, and Chrome for Android. It is not designed to work with Internet Explorer. I can’t make any guarantees about how long it will continue to work in the future, because YouTube is constantly iterating on their API.

To see the full, unminified version of the script, click here.

Subscribe to my future articles!
Subscribe by Email