Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App
Next Article:
How To Autoplay Youtube Video in HTML
Next article icon

How To Autoplay Youtube Video in HTML

Last Updated : 04 Dec, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

To embed and play YouTube videos in HTML, you can use the <iframe> tag with the YouTube embed URL.

Furthermore, to autoplay a YouTube video in HTML, you need to add some specific parameters in the URL to control autoplay and muting.

  • Autoplay: (autoplay=1) in the URL automatically starts playing the video.
  • Mute: (mute=1 ) is essential since most browsers block autoplay with sound.

Here’s the code to Autoplay Youtube Video in HTML.

HTML
<!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <title>Autoplay YouTube Video</title> </head> <body>      <h1>Autoplay YouTube Video Example</h1>          <iframe width="560" height="315"          src="https://www.youtube.com/embed/YOUR_VIDEO_ID?autoplay=1&mute=1">     </iframe>  </body> </html> 

Explanation :

  • <iframe> is an HTML element that lets you embed another webpage, like a YouTube video, within your page.
  • Width and Height: The width and height attribute of iframe provide a way to set the video dimensions (ex: width="560" and height="315") which can be adjusted as needed.

URL Parameters:

Additional URL parameters for autoplay and mute.

  • Autoplay: (autoplay=1) is a URL parameter that tells the video to start playing automatically when the page loads. By adding (autoplay=1) to the URL of the YouTube embed link, you can enable the autoplay feature for that video.
  • Mute: (mute=1) silences the video, which is often necessary since many browsers block autoplay if the sound is on. It is a URL parameter that tells the video to start playing without sound. Adding (mute=1) to the URL mutes the audio when the video begins playing.

Note: The '?' symbol in the URL indicates the beginning of the query string, which is where parameters are added to pass information to the server or control aspects of embedded content and the '&' symbol is used to separate two different parameters.


Next Article
How To Autoplay Youtube Video in HTML

T

tauheeda834k
Improve
Article Tags :
  • HTML
  • HTML5

Similar Reads

    How to Autoplay Videos in HTML?
    Autoplay is a feature that automatically starts a video when the page loads. While it can be convenient for certain scenarios, it's essential to use as it avoids annoying users or consuming excessive bandwidth.We will discuss different approaches to autoplay videos in HTML:Table of ContentUsing the
    2 min read
    How to Add Autoplay Video in HTML?
    Web design often has a feature of including a video that starts to play as soon as the web page loads. This effect can be achieved using HTML5 <video> element with the autoplay attribute. In this way, videos start playing without any user interaction hence improving the multimedia experience o
    2 min read
    How to Add Video in HTML?
    To add a video in HTML, you use the <video> tag, which allows you to embed videos directly into your webpage for users to view without needing external players.The <video> tag supports multiple formats like MP4, WebM, and Ogg.You can include attributes such as controls, autoplay, and loo
    4 min read
    How to display video controls in HTML5 ?
    The HTML <video> controls attribute is used to display video controls in HTML5. It is a Boolean attribute that adds video controls like volume, pause, and play. HTML5 commonly uses formats such as OGG, MP4, OGM, and OGV because browser support for these formats varies. Syntax <video control
    3 min read
    How to add video in HTML5 ?
    In This article, we will define how to add video content using a <video> element in the document. Before HTML5 came into existence, videos could only be played in a browser using a plugin like flash, but after the release of HTML5, adding a video to a web page is easy as adding an image. The H
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences