DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
Mountain View desk8 min

Day 7: Creating a YouTube-Style Page Using HTML and CSS

Build a beginner-friendly YouTube-style page with semantic HTML, CSS grid, and a responsive 16:9 iframe embed, plus when to use the video element instead.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You can build a YouTube-style video page with one HTML file, one CSS file, and a YouTube embed code. The page has a header, a main area with a video player and a description, and a sidebar of related lessons. The video sits in a box that keeps a 16:9 shape as the page gets wider or narrower. This lesson builds an illustrative design that shows the layout techniques. It does not reproduce YouTube’s interface or styling.

What you need before you start

  • A plain text editor such as VS Code, Sublime Text, or Notepad.
  • A modern web browser to open the file. You do not need a server for this lesson.
  • A folder containing two files: index.html and styles.css.
  • A YouTube video that you can open in a browser and share. Your embed options depend on the video and its settings.

Step 1: Build the HTML skeleton

Start with semantic elements so the page has clear regions. Screen readers and search tools can then identify the header, the main content, the video section, and the sidebar without relying on class names. Save this as index.html:

As an Amazon Associate I earn from qualifying purchases.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Video Lab: Lesson 7</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <header class="site-header">
    <h1>Video Lab</h1>
    <nav aria-label="Main">
      <a href="#">Home</a>
      <a href="#">Lessons</a>
    </nav>
  </header>

  <main class="layout">
    <section class="player" aria-labelledby="lesson-title">
      <div class="video-frame">
        <iframe src="https://www.youtube.com/embed/VIDEO_ID" title="Lesson 7 video" allowfullscreen></iframe>
      </div>
      <article class="video-details">
        <h2 id="lesson-title">About this lesson</h2>
        <p class="meta">Lesson 7 · Beginner level</p>
        <p>Use this description to explain what the video covers and what the reader will practise.</p>
      </article>
    </section>

    <aside class="related" aria-labelledby="up-next">
      <h2 id="up-next">Up next</h2>
      <ul>
        <li><a href="#">Lesson 8: Styling forms</a></li>
        <li><a href="#">Lesson 6: Flexbox basics</a></li>
      </ul>
    </aside>
  </main>

  <footer class="site-footer">
    <p>An illustrative lesson layout, not an official YouTube design.</p>
  </footer>
</body>
</html>
  • header holds the site name and navigation.
  • main holds the page’s primary content. Only one main should appear on a page.
  • section and article group the player and its description. aside holds supporting links that relate to the main content.

Step 2: Copy the embed code from YouTube

YouTube’s Help page describes embedding as the way to add a video to a website, and it instructs users to choose Share and then Embed. The steps are:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Open the video on YouTube in your browser.
  2. Select Share below the player.
  3. Select Embed.
  4. Copy the code shown in the dialog.
  5. Paste the code inside the <div class="video-frame"> element in index.html, replacing the example iframe.

The copied code is an iframe. Its src attribute begins with https://www.youtube.com/embed/, followed by the video ID that YouTube generated. Replace VIDEO_ID in the example with that ID. The copied code also contains width and height attributes. Remove them, because the CSS in Step 4 controls the size. Keep the title attribute, since it describes what the frame contains.

The embed code can include additional parameters after the video ID. Google’s YouTube Embedded Players and Player Parameters documentation lists the supported options.

Autoplay and data collection

Do not add autoplay to the embed by default. Google’s player documentation notes that enabling autoplay starts playback without user interaction, and that playback data collection and sharing occur on page load. Leave autoplay off unless the lesson needs it and you have considered the effect on visitors.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Child-oriented sites

YouTube Help says that if your website or app is child-oriented, you must self-designate it using YouTube’s tools when you embed videos. This affects personalized ads and some embedded player features. Check this before you publish a lesson aimed at children.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Step 3: Style the layout with CSS

Save the following as styles.css in the same folder. The main area uses CSS Grid. On narrow screens it has one column. On screens 900 pixels wide and above, the player takes two parts of the width and the sidebar takes one part.

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, Arial, sans-serif;
  line-height: 1.5;
  color: #0f0f0f;
  background: #f7f7f7;
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid #e5e5e5;
}

.site-header h1 {
  margin: 0;
  font-size: 1.25rem;
}

.site-header nav a {
  margin-left: 16px;
  color: #0f0f0f;
  text-decoration: none;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 2fr) minmax(240px, 1fr);
    padding: 24px;
  }
}

.video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
}

.video-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.video-details {
  padding: 16px 0;
}

.meta {
  color: #606060;
  font-size: 0.9rem;
}

.related ul {
  list-style: none;
  padding: 0;
}

.related li {
  padding: 10px 0;
  border-bottom: 1px solid #e5e5e5;
}

.site-footer {
  padding: 16px;
  text-align: center;
  color: #606060;
  font-size: 0.9rem;
}

The minmax(0, 1fr) and minmax(0, 2fr) track definitions allow a grid column to shrink below the width of its content. Without them, a wide child such as a long word or a fixed-width element can push the column past the screen edge.

Step 4: Keep the video responsive

The .video-frame wrapper uses aspect-ratio: 16 / 9. The browser calculates its height from its width, so the frame keeps the shape of a 16:9 video as the column changes size. The iframe fills the wrapper with absolute positioning. MDN’s guide to understanding and setting aspect ratios describes this approach for responsive media. MDN’s general embedding technologies article covers third-party embeds such as YouTube in the same context.

Player size guidance

Google’s player documentation gives two figures. The embedded player viewport must be at least 200 pixels by 200 pixels. For a 16:9 player with controls, Google recommends at least 480 pixels wide by 270 pixels high. These are documented player figures, not CSS breakpoints. The table below shows how a 16:9 frame of different widths compares with them. The heights are calculated from the 16:9 ratio.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Frame width (CSS pixels) Frame height at 16:9 Meets the 200 × 200 minimum? Meets the 480 × 270 recommendation?
320 180 No (height is below 200) No
360 202.5 Yes No (width is below 480)
480 270 Yes Yes
640 360 Yes Yes

On a phone, the frame is narrower than the recommended 480 pixels. That is expected for a responsive layout. The minimum of 200 pixels is the more important limit. A frame narrower than about 356 pixels has a height below 200 pixels at 16:9, which is under Google’s documented minimum. If you see this on a small phone, reduce the side padding on .layout in the mobile rule, rather than fixing the frame’s height.

Best Value
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choosing between a YouTube embed and the video element

The layout above works for a YouTube-hosted video. If the video file belongs to you, HTML’s video element is the better tool. The table compares the two approaches.

Factor YouTube iframe embed HTML video element with your own file
Where the video is hosted On YouTube. Playback is delegated to YouTube. On your site or server. You supply the media files.
How you get the code Share, then Embed, in YouTube. Write the video element with source children.
Playback controls Provided by the YouTube player. Shown when you include the controls attribute.
Browsing context An iframe is a separate browsing context. MDN notes that iframes use additional memory and other browser resources. Part of the page’s own document.
Responsive sizing Use the wrapper with aspect-ratio from Step 4. Use CSS such as width: 100%; height: auto; on the element.
Layout shift Not stated for this lesson. The wrapper keeps the frame’s shape before the iframe loads. Explicit width and height attributes help avoid layout shift, especially with lazy-loaded video (MDN).

Use the iframe method for a video that already lives on YouTube. Use the video element for media you host. The MDN video element reference documents its attributes, and the MDN iframe reference documents the iframe element.

Self-hosted alternative with the video element

If you host the file yourself, replace the iframe inside .video-frame with a video element. You must provide compatible media files. Use one or more source elements so the browser can choose a format it supports:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<video controls preload="metadata" width="640" height="360">
  <source src="media/lesson-7.mp4" type="video/mp4">
  <source src="media/lesson-7.webm" type="video/webm">
  Your browser cannot play this video. <a href="media/lesson-7.mp4">Download the file</a>.
</video>

The controls attribute provides the playback controls. Add this CSS so the element scales with its column while keeping its shape:

.video-frame video {
  display: block;
  width: 100%;
  height: auto;
}

Common problems and fixes

  • The frame is blank or collapsed. Check that the iframe sits inside .video-frame and that the wrapper has width: 100% and aspect-ratio: 16 / 9. The iframe’s absolute positioning depends on the wrapper’s position: relative.
  • The page scrolls sideways on a phone. Confirm that the grid columns use minmax(0, 1fr) and that the iframe has width: 100%, not a fixed width carried over from the copied code.
  • The player is cramped on a small screen. Use the width-to-height figures in Step 4 to check whether the frame falls below Google’s 200-pixel minimum, and reduce the side padding if it does.
  • The page feels slow with several videos. Each iframe is a separate browsing context that uses additional memory and browser resources, according to MDN. Add embeds only where they serve the lesson.
  • The embed code has no ID you can recognise. Use the code exactly as YouTube generated it. Only the value after /embed/ should change when you swap videos.

When these pieces are in place, the page has a clear structure, a player that keeps its shape, and a layout that adapts from a phone to a desktop screen.

Quick Recap

SaleBestseller No. 2
HTML and CSS: Design and Build Websites
HTML and CSS: Design and Build Websites
HTML CSS Design and Build Web Sites; Comes with secure packaging; It can be a gift option
$14.94
SaleBestseller No. 3
SaleBestseller No. 5
Web Design with HTML, CSS, JavaScript and jQuery Set
Web Design with HTML, CSS, JavaScript and jQuery Set
Brand: Wiley; Set of 2 Volumes
$35.05

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.