Autoplay video on the site

Videos can be divided into two categories: those that require you to click the "play" button to play, and those that start automatically.

Let's look at how autoplay affects users and how to implement it on a website.

Impact on users

The effect can be both positive and negative.

On the one hand, autoplay allows you to show the video immediately, without having to click the play button. This is useful when demonstrating a product or explaining complex concepts. But some visitors find autoplay annoying, especially if they were not expecting it or if the sound is on by default. Autoplay can consume more resources and increase data costs, especially for users with limited internet connections or mobile devices.

Tips for use

To make autoplay enjoyable for users, you can:

  1. Adjust the volume and turn it off – this will help avoid irritation.
  2. Duration. The video should be short so as not to tire visitors. The recommended duration is from 1 to 3 minutes.
  3. Preview and short description – will help visitors understand what it is about and what they can expect from watching.
  4. Support for various devices and browsers. It is important to make sure that autoplay works on all popular mobile devices, tablets and browsers.

 

Instructions for adding

Let's consider two options: uploading to a hosting and using the YouTube service.

Upload the media file to the server or hosting.

Insert the code to play the video in the HTML document. To do this, use the <video> tag:

<video>
  <source src="sample.mp4" type="video/mp4">
</video>

In our case:

  • source src – path to video,
  • type – video type.

Add the autoplay attribute to the <video> tag to make the video play automatically when the page loads:

<video autoplay>
  <source src="sample.mp4" type="video/mp4">
</video>

Additionally, you can customize other parameters, such as width and height, playback controls (pause or sound buttons), and player design. Let's change the width of the video and add control buttons.

The "width" and "controls" attributes are responsible for this, respectively.

The final code looks like this:

<video width="600" controls autoplay>
  <source src="sample.mp4" type="video/mp4" />
</video>

Now the video starts immediately after the page loads

Another option is to use YouTube as a source. This will save space on the server and ensure faster loading.

Go to the YouTube page, find and open the desired video.

Click the Share button below the player.

 

In the window that opens, select the "Embed" option.

 

Copy the contents of the field with the <iframe> tag and paste it into the HTML document of the site.

The iframe tag passes the video URL as the src attribute. To pass additional parameters to the element, you need to put the "?" sign at the very end of the URL and then list the parameters with their values ​​in the following form:

parameter=value

For autostart it looks like this:

autoplay=1

where 1 is enabled, 0 is disabled.

In our case, the contents of the src attribute together with the autorun parameter will look like this:

https://www.youtube.com/embed/VzWDdDrU-8I?si=VTTyVVfcZU7IT-nG?autoplay=1

Autoplay videos are a useful tool, but it is important to use them wisely and consider user preferences. Some visitors want to control when videos start. If you need a convenient solution without having to write code, try the Qform video widget. It allows you to customize the display type, launch options (including autoplay), and add videos to your site with two lines of code.