Skip to content
AI-powered appsNewChat, vision, voice, generationBookings & schedulingAppointments that book themselvesShops & sellingA storefront in every pocketClient & businessRun the operation from one placeCommunities & clubsA home that is not a group chat
Health & wellnessHabits, tracking and calmGames2D, 3D and multiplayerPersonal & toolsThe tool you wish existedInternal toolsThe tool ops never had time for
See all use cases
ArcadeNewPricingSecurity
EngineThe game engine and World EditorHow it worksFrom one sentence to a live productDocsGuides for building and publishingBlogStories, guides and newsChangelogWhat shipped latelyStatusUptime of every serviceSupportGet help from the team
AI-powered appsBookings & schedulingShops & sellingClient & businessCommunities & clubsHealth & wellnessGamesPersonal & toolsInternal tools
See all use cases
ArcadeNewPricingSecurity
EngineHow it worksDocsBlogChangelogStatusSupport
Language
Blog
IntegrationsNovember 22, 20266 min read

Embed YouTube Videos the Right Way

A plain YouTube iframe works, but it loads a heavy player for every visitor and sets cookies before anyone presses play. Here is the faster, more private way to do it.

Startbase Team
Editorial ink illustration of a wooden picture frame on an easel with a paper play-button card tucked into its corner, the play-button card in ember orange

Key takeaways

  • Show a thumbnail with a play button and load the real player only on click: the page stays fast and the video still plays in one tap.
  • Use the youtube-nocookie.com domain for privacy-enhanced mode, and add a descriptive title to every iframe.
  • A plain embed needs no API key. You only need a YouTube Data API key (kept in Secrets) when your app lists or searches videos.

To embed a YouTube video the right way, take the video ID from its URL (the part after v=), put it in an iframe pointed at youtube-nocookie.com/embed/VIDEO_ID, size it with a 16:9 aspect ratio so it scales on phones, and give it a title for screen readers. On any page where the video is not the first thing people see, go one step further: show the video's thumbnail with a play button and swap in the real player only when someone clicks. That keeps the page fast, avoids loading YouTube's scripts for visitors who never press play, and needs no account or API key.

What you will build

A reusable video block you can drop anywhere: a landing page hero, a course lesson, a product page, a "how it works" section. It shows a crisp thumbnail and a play button, starts the video in one tap on desktop and phone, can begin at a chosen second, and never pushes the layout around while it loads. Optionally, a "latest videos" grid that pulls a channel's newest uploads, which is the only part that needs a key.

What you need

  • For single embeds: nothing. Public YouTube videos can be embedded without an account, as long as the uploader has not turned embedding off.
  • For a channel feed or search: a Google Cloud project with the YouTube Data API v3 enabled and an API key. Restrict the key to that API in the Google Cloud console and store it in your backend's Secrets, never in the page.
  • The video IDs. In youtube.com/watch?v=dQw4w9WgXcQ the ID is the 11 characters after v=. In youtu.be/ links it is the path. Shorts links use /shorts/ID and embed the same way.

The embed URL and the parameters worth knowing

The watch URL does not work inside an iframe; the embed URL does. Use https://www.youtube-nocookie.com/embed/VIDEO_ID. The nocookie domain is YouTube's privacy-enhanced mode: it does not store viewing cookies on the visitor's browser until they interact with the player. It is not a full consent solution (playing the video still talks to Google), but it is the better default.

Add options as query parameters after a question mark, joined with &:

  • start=90 begins at 1:30. Use whole seconds. end=120 stops playback at 2:00, handy for showing one clip of a long talk.
  • autoplay=1 starts playback when the player loads. Browsers only allow autoplay with sound off, so pair it with mute=1. In the facade pattern below, autoplay=1 is what makes the click feel instant.
  • playsinline=1 keeps the video inside the page on iPhone instead of jumping to full screen.
  • rel=0 no longer hides related videos completely. It only limits them to the same channel, so do not promise a clean ending screen.
  • loop=1 only works together with playlist=VIDEO_ID (the same ID again). This is a long-standing quirk of the player.
  • cc_load_policy=1 shows captions by default, a small accessibility win for tutorials.

The click-to-load facade

A YouTube iframe pulls in the player, its scripts and its styles as soon as the page renders, which adds hundreds of kilobytes and several network requests per video. Put three videos on a page and phones feel it. The fix is a facade: a lightweight placeholder that looks like the player.

  1. 01Render a button containing the thumbnail image from i.ytimg.com/vi/VIDEO_ID/hqdefault.jpg (480 by 360, always available). maxresdefault.jpg is sharper but missing on some older or low-resolution uploads, so fall back to hqdefault if it fails to load.
  2. 02Overlay a play icon and give the button an accessible label like "Play video: Setting up your first project".
  3. 03On click, replace the button with the iframe, adding autoplay=1 so playback starts right away. The one tap counts as the user gesture browsers require, so sound is allowed.
  4. 04Reserve the space up front with aspect-ratio: 16 / 9 and width: 100% on the wrapper, so nothing jumps when the iframe arrives. Use 9 / 16 for Shorts.

Tip

Keep the facade for below-the-fold and multi-video pages. A single hero video that most visitors will play anyway can load as a normal iframe with loading="lazy" if it sits lower on the page.

Data flow for a "latest videos" grid

Listing a channel's uploads goes through the YouTube Data API, which needs your key, so the call belongs in an edge function, not the browser:

  1. 01A scheduled job runs every few hours (every 6 hours is a sensible start) and calls an edge function.
  2. 02The function reads YOUTUBE_API_KEY from Secrets and fetches the channel's uploads playlist (playlistItems.list), which costs 1 quota unit per call. Avoid search.list for this: it costs 100 units per call, and the default project quota is 10,000 units a day.
  3. 03It stores video ID, title, published date and thumbnail URL in a videos table, keyed by video ID so reruns update instead of duplicating.
  4. 04Your page reads that table and renders each row as a facade. Visitors never hit the YouTube API, so traffic spikes cannot burn your quota.

The same pattern (fetch on a schedule, cache in your database, serve from there) is explained in scheduled jobs explained and works for almost any third-party feed.

A brief you can paste

Add a reusable YouTubeEmbed component. Props: video ID, title, optional start time in seconds, and orientation (landscape or short). It shows the video's hqdefault thumbnail with a centered play button, reserves a 16:9 box (9:16 for shorts) so the layout never shifts, and on click swaps in an iframe from youtube-nocookie.com with autoplay=1 and playsinline=1. The button has an aria-label that includes the title, and the iframe gets the same title. If the thumbnail fails to load, show a neutral placeholder with the title. Use it for the three tutorial videos on the Help page (IDs: VIDEO_ID_1, VIDEO_ID_2, VIDEO_ID_3), each with a one-line caption underneath.

The docs page on embedding videos covers the other option, uploading video files into your project, and why large files slow previews down.

Pitfalls and how to avoid them

  • "Video unavailable" in the player. The uploader disabled embedding, the video is private, or it is blocked in the viewer's country. You cannot override any of these. For your own videos, check that embedding is allowed and the video is public or unlisted.
  • Pasting the watch URL into the iframe. youtube.com/watch?v= refuses to load in a frame. Always convert to /embed/ID. Strip extra parameters like &list= or &t= when extracting the ID, and convert t=1m30s into start=90.
  • Fixed pixel sizes. width="560" height="315" overflows small screens. Use the aspect-ratio wrapper and let width be 100%.
  • Autoplay with sound. It will be blocked silently. Either start muted or start on a click.
  • Cookie consent. In regions with consent rules, privacy-enhanced mode reduces but does not remove the need to think about it. A facade helps here too, because nothing from YouTube loads before the visitor chooses to play.
  • Treating YouTube as your video host for paid content. Unlisted videos can be shared by anyone who has the link. For lessons behind a paywall, a dedicated video host with signed playback is the safer choice.

Video embeds are one of the biggest weights on a marketing page. If page speed and search ranking matter to you, pair this with the advice in SEO for your app, and if you are building a lesson site, the online course platform guide covers progress tracking around the video itself.

Frequently asked questions

Do I need an API key to embed a YouTube video?

No. Embedding a public video only needs its ID in an iframe URL. You need a YouTube Data API key only to list, search or read details about videos from your app, and that key belongs in your backend secrets.

What is youtube-nocookie.com?

It is YouTube's privacy-enhanced embed domain. The player works the same, but YouTube does not store viewing cookies in the visitor's browser until they interact with the video.

Why does my embedded YouTube video not autoplay?

Browsers block autoplay with sound. Add mute=1 alongside autoplay=1, or start playback from a click, which counts as the user gesture browsers require.

How do I make a YouTube embed responsive?

Wrap the iframe in a container with width 100% and aspect-ratio 16 / 9, and make the iframe fill it. Drop the fixed width and height attributes YouTube's share code includes.

On this page

  • What you will build
  • What you need
  • The embed URL and the parameters worth knowing
  • The click-to-load facade
  • Data flow for a "latest videos" grid
  • A brief you can paste
  • Pitfalls and how to avoid them

Keep reading

More in Integrations
Editorial ink illustration of a folded paper street map with a brass compass and pushpins, the center pushpin in ember orange
IntegrationsNovember 22, 2026

How to add a map to your app

A map is two jobs: drawing tiles in the browser and turning addresses into coordinates. One key can be public, the other never should be.

6 min read
Editorial ink illustration of a carrier pigeon on a windowsill with a rolled note tied to its leg, the note in ember orange
IntegrationsNovember 22, 2026

How to send SMS from your app

Sending one text is ten lines of code. Sending texts people agreed to, that arrive, and that nobody can abuse, is the real work.

5 min read

Read less. Ship more.

Everything in this post is one prompt away. Describe your app and watch it build.

Start building

Apps, games, backends and publishing from one conversation.

Product

  • Features
  • Use cases
  • Pricing
  • Changelog

Resources

  • Blog
  • Docs
  • Support
  • Status
  • Security

Contact

  • w@startbase.ai
  • X / Twitter
  • LinkedIn
  • Instagram

Legal

  • Terms
  • Privacy

© 2026 Startbase. All rights reserved.