We use cookies to ensure you get the best experience on our website. Read our privacy policy

Skip to main content

Directory

YouTube Component

The YouTube component provides optimized video embedding with automatic thumbnail loading, custom play buttons, and performance optimizations. Choose between two implementation options to best suit your needs.

  • Check Circle

    Performance Optimized: Lazy-loaded iframes and smart resource preloading

  • Check Circle

    SEO-Friendly: Includes structured data and semantic markup

  • Check Circle

    Customizable: Supports custom thumbnails and player parameters

<YouTube src="dQw4w9WgXcQ" title="Never Gonna Give You Up" thumbnailQuality="high" />

The YouTube component offers:

  • Custom play button styling
  • Structured data support
  • Simplified prop-based configuration
  • Enhanced thumbnail options
<lite-youtube videoid="dQw4w9WgXcQ" playlabel="Play: Never Gonna Give You Up"></lite-youtube>

The lite-youtube component provides:

  • Optimized for YouTube Shorts
  • Extremely lightweight
  • Mobile-first approach

To read more about the lite-youtube component, please visit the lite-youtube documentation.

Required Props
YouTube Component Props Extends <div> HTMLElement
Prop Type Default Description
src string YouTube video ID or URL
buttonProps ComponentProps<typeof Button> Custom play button properties
description string Video description for structured data
params string Additional YouTube player parameters
structuredData boolean true Enable/disable Schema.org markup
title string Video title for accessibility and overlay
thumbnailProps ComponentProps<typeof Image> Custom thumbnail image properties (src can be undefined and will be generated from the video ID)
thumbnailQuality "max" | "high" | "default" | "low" Thumbnail image quality (for generated thumbnails)
uploadDate Date Video upload date for structured data

The component exposes the following function for you to use:

play(): Promise<void>;
<YouTube src="dQw4w9WgXcQ" />
<YouTube
src="dQw4w9WgXcQ"
title="Never Gonna Give You Up"
description="Rick Astley's iconic music video"
thumbnailQuality="max"
params="start=30&autoplay=1"
buttonProps={{
class: "custom-play-button",
variant: "secondary"
}}
/>
<YouTube
src="dQw4w9WgXcQ"
title="Never Gonna Give You Up"
description="Rick Astley's iconic music video"
uploadDate={new Date('1987-07-27')}
structuredData={true}
/>

The YouTube component implements several performance optimizations:

  1. Smart Resource Loading

    • Defers iframe creation until play
    • Preconnects to required domains
    • Lazy loads high-quality thumbnails
  2. Reduced Network Impact

    • Uses youtube-nocookie.com domain
    • Optimizes API loading
    • Minimizes initial page load
  3. Progressive Enhancement

    • Starts with static thumbnail
    • Upgrades to WebP when available
    • Gracefully falls back when needed
  1. Video Loading

    • Use appropriate thumbnail quality
    • Consider mobile data usage
    • Implement lazy loading for off-screen videos
  2. Accessibility

    • Always provide descriptive titles
    • Include meaningful play labels
    • Ensure keyboard navigation support
  3. Performance

    • Limit videos per page
    • Use thumbnail quality appropriately
    • Consider mobile viewers

Limited Time Launch Sale

Start embedding YouTube videos with optimal performance today. Get our AstroJS starter template and access the YouTube component along with many other pre-built features.

GET 60% OFF!
North Star Themes Logo

Subscribe to our newsletter

Get the latest AstroJS tips and tricks right to your inbox

Email: [email protected]

© 2025 North Star Themes

Web Kit Provided By North Star Themes