Skip to content
Home Blog Web Development Using HTML5 Video and Audio Tags

Using HTML5 Video and Audio Tags

  • Web Development
Blueprint Digital
Blueprint Digital

Insights from the Blueprint Digital team.

It is important to make websites more attractive and interactive to users. One of the ways to do that is to add video and audio files. HTML5 introduced a lot of cool new features and tags, and some of the new tags are <audio> and <video> tags.

How to Use Video and Audio Tags

The <audio> and <video> tags have very similar formatting:

<audio src="myfile.mp3" />
<audio src="myfile.mp3"></audio>

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

The tags are self-closing, so both formats would be considered correct. It’s really easy, isn’t it? The new tags themselves are not so complicated. However, video codecs are complex and create a lot of issues. Long story short, each browsers support different codecs, and because of this, it would be wise to add different video formats for maximum compatibility between browsers. The formats would then change to these:

<audio controls>
<source src="myfile.mp3" type="video/mp3" />
<source src="myfile.ogg" type="video/ogg" />
</audio>

<video controls>
<source src="myfile.mp4" type="video/mp4" />
<source src="myfile.webm" type="video/webm" />
<source src="myfile.ogv" type="video/ogg" />
</video>

In addition to these attributes, you could set width and height on the <audio> and <video> tags.

New Attributes for Video and Audio Tags

There are some new attributes that could be used on <audio> and <video> tags. I will list some below, and these attributes could be used for both audio and video:

  • preload – This attribute controls when the video or audio file will download. It is especially useful for large files.
  • loop – Using this attribute will make the audio or video file start over when it ends. It is a Boolean attribute, so all you need to do is include the word loop in the <audio> or <video> tag.
  • autoplay – Also a Boolean attribute, this attribute determines whether the video will start on page load or not.
  • controls – This is a Boolean attribute that enables users to pause or play the files without right-clicking on the video to start it. Because of this, it is a good practice to include this attribute. When this attribute is used, each browser will apply its own styled controls to the video or audio files. To have your own controls, you could make them through JavaScript.

Helpful Tools

There are many helpful tools out there to get started with HTML5 videos and audios. One of them is MediaElement.js. Another is Video.js. Both use JavaScript to help the video and audio files look uniform in different browsers and offer Flash fallbacks for browsers that are not compatible with these new HTML5 tags.

Conclusion

It is important to include video and audio files in your website. I hope this article was helpful in getting you started with HTML5 audio and video tags. If you would like to learn more about getting started with HTML5 in general, check out this article: Getting started with HTML5

Ready to Dominate Online and Grow Your Business?

Schedule time to connect with Blueprint about your online goals, or request a free review of marketing campaigns.

Related Posts

What Is Automated Lead Follow-Up and How Does It Work

What Is Automated Lead Follow-Up and How Does It Work

A new lead fills out a form, then waits. If the phone stays silent for a day, that lead has usually moved on to whoever answered first. Automated lead follow-up closes the gap. It is a marketing automation system that responds to every new inquiry within minutes, then continues the conversation through scheduled texts, emails,[...]
Free Advertising for Nonprofits Through Google Ad Grants

Free Advertising for Nonprofits Through Google Ad Grants

Advertising is usually the first line cut from a nonprofit budget, and the one that quietly costs the most to lose. Donors still search, scroll, and read, whether or not the cause has money to meet them there. Free advertising for nonprofits means promoting a cause without paying for placements, and it is how organizations[...]
Lead Scoring for B2B: How to Decide Which Leads Your Sales Team Chases

Lead Scoring for B2B: How to Decide Which Leads Your Sales Team Chases

Every marketing team has handed sales a list of leads that went nowhere. After a few of those lists, sales stops trusting them, works its own referrals instead, and the two teams settle into a standing argument about lead quality. Underneath the argument is a simpler problem: nobody has written down what a good lead[...]
Previous
Next

Partner with BLUEPRINT to reach your online goals, grow your business and reshape your story.

Get in touch with BLUEPRINT

Reach out to request a discovery call, a free campaign review, or for all other inquiries.

Subscribe to our newsletter