Skip to main content
Our new developer certification is live!

YouTubeVideo

Atom component for embedding YouTube videos using a video ID. Creates an iframe embed with configurable parameters.

Props

PropTypeRequiredDefaultDescription
videoIdstringYes-YouTube video ID (e.g., "dQw4w9WgXcQ")
titlestringNo'YouTube video player'Accessibility title for iframe
relbooleanNotrueHide related videos from other channels (rel=0)
modestbrandingbooleanNotrueUse minimal YouTube branding
playsinlinebooleanNotruePlay inline on mobile devices
$CSLPFieldMappingNo-CSLP mapping for Live Preview
classNamestringNo''Additional CSS classes

Usage

import YouTubeVideo from '@/components/atoms/YouTubeVideo';

<YouTubeVideo 
  videoId="dQw4w9WgXcQ"
  title="My Video Title"
/>

Features

  • Responsive: Uses aspect-video for 16:9 aspect ratio
  • Accessible: Includes proper iframe title and attributes
  • YouTube parameters: Supports rel, modestbranding, and playsinline parameters
  • CSLP support: Supports Contentstack Live Preview editing
  • Lazy loading: Uses loading="lazy" for performance

YouTube Embed URL

The component constructs the embed URL as:

https://www.youtube.com/embed/{videoId}?rel=0&modestbranding=1&playsinline=1

Parameters are only added when their corresponding props are set to true (default behavior).

YouTube Parameters

  • rel=0: Hides related videos from other channels (when rel={true})
  • modestbranding=1: Uses minimal YouTube branding
  • playsinline=1: Plays inline on mobile devices

Styling

  • Container: w-full my-4 with optional custom className
  • Video wrapper: relative w-full aspect-video overflow-hidden rounded-lg bg-surface-3
  • Iframe: absolute inset-0 w-full h-full border-0

Notes

  • Returns null if no videoId is provided
  • Uses the same structure as RichTextRenderer embed for consistency
  • Supports fullscreen via allowFullScreen attribute
  • Includes all necessary iframe permissions for YouTube embeds