The web component serves as the ShadowDom web component version of Paul’s lite-youtube-embed component. It uses a lightweight placeholder image initially, then loads the full YouTube player only when needed. This approach delivers substantial performance improvements.
1. Install and import the lite-youtube web component.
# Yarn $ yarn add @justinribeiro/lite-youtube # NPM $ npm install @justinribeiro/lite-youtube
import '@justinribeiro/lite-youtube';
2. You can also directly import it into your HTML document from a CDN.
<script type="module" src="https://cdn.jsdelivr.net/npm/@justinribeiro/lite-youtube@1/lite-youtube.min.js"></script>
3. Add the <lite-youtube> custom element to your page and set the video ID & playlist (OPTIONAL) as follows:
<lite-youtube videoid="VIDEO ID HERE"></lite-youtube>
<lite-youtube videoid="VIDEO ID HERE" playlistid="PLAYLIST ID"></lite-youtube>
4. Add a fallback link for enhanced accessibility:
<lite-youtube videoid="guJLfqTFfIw"> <a class="lite-youtube-fallback" href="https://www.youtube.com/watch?v=guJLfqTFfIw">Watch on YouTube</a> </lite-youtube>
5. Enable mobile-optimized layout for Youtube Shorts:
<lite-youtube videoid="VIDEO ID" short></lite-youtube>
6. Delay the loading of YouTube video until it’s scrolled into view using the Intersection Observer API:
<lite-youtube videoid="VIDEO ID" autoload> </lite-youtube>
7. More props to customize the component.
videoid: The YouTube video ID. (Required)playlistid: The YouTube playlist ID. Requires a videoid for the thumbnail.videotitle: The title of the video. Defaults to “Video”.videoplay: The title of the play button (used for translation). Defaults to “Play”.videoStartAt: Sets the point at which the video should start, in seconds. Defaults to 0.posterquality: Sets the thumbnail poster quality. Options are: maxresdefault, sddefault, mqdefault, hqdefault. Defaults to hqdefault.posterloading: Sets the img lazy loading attribute for the poster image. Defaults to lazy.nocookie: Uses youtube-nocookie.com as the iframe embed URI. Defaults to false.autoload: Uses Intersection Observer to load the iframe when scrolled into view. Defaults to false.short: Shows a 9:16 YouTube Shorts-style interaction on mobile devices. Defaults to false.params: Sets YouTube query parameters.disablenoscripts: Inject into the lightdom a noscript for SEO help.autopause: Auto-Pause video when scrolled out of view.8. Customize the appearance of your Youtube embed.
lite-youtube::part(playButton) {
/* You styles here */}
lite-youtube {
/* Video aspect ratio */ --lite-youtube-aspect-ratio: 2 / 3;
}
lite-youtube {
/* disable the frame shadow */ --lite-youtube-frame-shadow-visible: no;
} v1.8.0 (04/26/2025)
The post Fast, Lightweight YouTube Video Embed Web Component – lite-youtube appeared first on CSS Script.
Frauds are no longer spotted by disorganized phishing emails that contain spelling errors. They are…
Microsoft is actively investigating a widespread authentication issue affecting users attempting to access Microsoft 365…
Two American nationals have been sentenced to federal prison for operating a sophisticated “laptop farm”…
A threat cluster tracked as UAC-0247 has been running an active campaign since early 2026,…
FORT WAYNE, IND. (WOWO) Indiana Governor Mike Braun is weighing in on multiple contested primary races…
The internet definitely had some thoughts about Jared Leto’s Skeletor voice when the first Masters…
This website uses cookies.