HTML Video – How to Embed a Video Player with the HTML 5 Video Tag (2024)

/ #HTML
HTML Video – How to Embed a Video Player with the HTML 5 Video Tag (1)
Kolade Chris
HTML Video – How to Embed a Video Player with the HTML 5 Video Tag (2)

Before the advent of HTML 5, web developers had to embed video on a web page with a plugin like Adobe flash player.

Today, you can easily embed videos in an HTML document with the <video> tag.

In this article, we'll see how the <video> tag works in HTML.

Table of Contents

  • Basic Syntax
  • Attributes of the <video> Tag
  • The src Attribute
  • The poster Attribute
  • The controls Attribute
  • The loop Attribute
  • The autoplay Attribute
  • The width and height Attributes
  • The muted Attribute
  • The preload Attribute
  • Conclusion

Basic Syntax

Just like the <img> tag, <video> takes an src attribute with which you need to specify the source of the video.

<video src="weekend.mp4"></video>

By default, it is displayed like an image in the browser:HTML Video – How to Embed a Video Player with the HTML 5 Video Tag (3)

This CSS centers everything in the web page and change the background color:

 body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background-color: #d3d3d3; }

In addition, you can specify multiple video sources for the <video> with the <source> tag. This <source> tag has to carry its own src attribute too.

You can use multiple <source> tags to make different formats of the same video available. The browser will then play the format it supports.

<video controls> <source src="weekend.mp4" /> <source src="weekend.ogg" /> <source src="weekend .webm" /></video>

Attributes of the <video> Tag

The <video> tag supports global attributes such as id, class, style, and so on.

If you're wondering what global attributes are, they are attributes supported by all HTML tags.

The specific attributes supported by the <video> tag include src, poster, controls, loop, autoplay, width, height, muted, preload, and others.

The src Attribute

The src attribute is used to specify the source of the video. It could be a relative path to the video on your local machine or a live video link from the internet.

<video src="weekend.mp4"></video>

It’s optional because you can use the <source> tag instead of it.

The poster Attribute

With the poster attribute, you can incorporate an image to show before the video starts playing or while it is downloading.

<video src="weekend.mp4" poster="benefits-of-coding.jpg"></video>

Instead of the image of the first scene of the video, the browser will show this image:HTML Video – How to Embed a Video Player with the HTML 5 Video Tag (4)

The controls Attribute

When you use control, it lets the browser show playback controllers such as play and pause, volume, seek, and so on.

<video controls src="weekend.mp4" poster="benefits-of-coding.jpg"></video>

HTML Video – How to Embed a Video Player with the HTML 5 Video Tag (5)

The loop Attribute

With the loop attribute, you can make the video repeat automatically. That is, make it start playing again every time it stops playing.

<video controls loop src="weekend.mp4" poster="benefits-of-coding.jpg"></video>

The autoplay Attribute

The autoplay attribute lets you make the video start playing automatically immediately after the page loads.

<video controls loop autoplay src="weekend.mp4" poster="benefits-of-coding.jpg"></video>

The width and height Attributes

You can use the width and height attributes to specify a width and height for the video in pixels. It accepts only absolute values, for example, pixels.

<video controls loop autoplay src="weekend.mp4" width="350px" height="250px" poster="benefits-of-coding.jpg"></video>

HTML Video – How to Embed a Video Player with the HTML 5 Video Tag (6)

The muted Attribute

You can use the muted attribute to tell the browser not to play any sound associated with the video when it starts playing.

<video controls loop autoplay muted src="weekend.mp4" width="350px" height="250px" poster="benefits-of-coding.jpg"></video>

HTML Video – How to Embed a Video Player with the HTML 5 Video Tag (7)

If the controls attribute is specified, the user can click the volume button to unmute.

The preload Attribute

With the preload attribute, you can provide a hint to the browser on whether to download the video or not when the page loads.

This attribute is crucial for user experience.

You can use 3 values with the preload attribute:

  • none: specifies that the video won't load until the user presses play

  • auto: specifies that the video should be downloaded even when the user doesn't press play

  • metadata: specifies that the browser should collect metadata such as length, size, duration, and so on.

<video controls loop autoplay muted="true" preload="metadata" src="weekend.mp4" width="350px" height="250px" poster="benefits-of-coding.jpg"></video>

Conclusion

In this article, you learned about the HTML5 <video> tag and its attributes, so you can use it in your projects the right way.

Since audio is an important part of a complete video, you can also use the <video> tag to put an audio file on a web page. But in most cases, you should use the <audio> tag for this purpose for the appropriate user experience.

If you find this article helpful, share it with your friends and family so it can reach more people who might need it.

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

HTML Video – How to Embed a Video Player with the HTML 5 Video Tag (8)
Kolade Chris

I'm a software developer and tech writer focusing on frontend technologies

If you read this far, thank the author to show them you care.

Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started

ADVERTIsem*nT

HTML Video – How to Embed a Video Player with the HTML 5 Video Tag (2024)
Top Articles
21 Breakfast Recipes Featuring Strawberries
Brioche Bread Recipe
Average Jonas Wife
Sound Of Freedom Showtimes Near Governor's Crossing Stadium 14
Jesus Calling December 1 2022
Find All Subdomains
Hallowed Sepulchre Instances &amp; More
Rochester Ny Missed Connections
Cool Math Games Bucketball
What Is A Good Estimate For 380 Of 60
What Happened To Maxwell Laughlin
Belle Delphine Boobs
Luna Lola: The Moon Wolf book by Park Kara
Youravon Comcom
Ou Class Nav
Richland Ecampus
Keck Healthstream
Why Is 365 Market Troy Mi On My Bank Statement
Invitation Homes plans to spend $1 billion buying houses in an already overheated market. Here's its presentation to investors setting out its playbook.
12 Top-Rated Things to Do in Muskegon, MI
Amerisourcebergen Thoughtspot 2023
WRMJ.COM
Top 20 scariest Roblox games
Coindraw App
Copper Pint Chaska
The Collective - Upscale Downtown Milwaukee Hair Salon
Expression&nbsp;Home&nbsp;XP-452 | Grand public | Imprimantes jet d'encre | Imprimantes | Produits | Epson France
Slv Fed Routing Number
Staar English 1 April 2022 Answer Key
Synchrony Manage Account
Andhra Jyothi Telugu News Paper
Ukg Dimensions Urmc
Pitchfork's Top 200 of the 2010s: 50-1 (clips)
That1Iggirl Mega
Heelyqutii
About :: Town Of Saugerties
Wait List Texas Roadhouse
Flipper Zero Delivery Time
Craigslist - Pets for Sale or Adoption in Hawley, PA
Firestone Batteries Prices
Lacy Soto Mechanic
Craigslist Malone New York
Conan Exiles Colored Crystal
Maplestar Kemono
Neil Young - Sugar Mountain (2008) - MusicMeter.nl
The Machine 2023 Showtimes Near Roxy Lebanon
German American Bank Owenton Ky
Law Students
Asisn Massage Near Me
Acellus Grading Scale
Varsity Competition Results 2022
Latest Posts
Article information

Author: Frankie Dare

Last Updated:

Views: 5438

Rating: 4.2 / 5 (73 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Frankie Dare

Birthday: 2000-01-27

Address: Suite 313 45115 Caridad Freeway, Port Barabaraville, MS 66713

Phone: +3769542039359

Job: Sales Manager

Hobby: Baton twirling, Stand-up comedy, Leather crafting, Rugby, tabletop games, Jigsaw puzzles, Air sports

Introduction: My name is Frankie Dare, I am a funny, beautiful, proud, fair, pleasant, cheerful, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.