Note: This article focuses on how to ensure the player iframe keeps the 16:9 aspect ratio. This is a widely used technique and can be used with other aspect ratios.
The width & height of the video determines the aspect ratio. We recommend an aspect ratio of 16:9.
There may be instances when you are viewing a video on a mobile site or a responsive web page and the video appears with black bars on the side or won't fit the layout. These small issues may be caused by the web page not being configured to maintain the correct scale and size of the player. As websites are responsive and fluid, we want to ensure the player is flexible working with dynamic pages. We recommend the following technique to keep the player responsive and to preserve the aspect ratio of the video.
How to keep the aspect ratio?
Example 1. With HTML & CSS
This is a simple and common CSS trick to preserve the aspect ratio. The below example is for a 16:9 ratio, however, this can be changed to work for other aspect ratios.
- In the HTML, put the player <iframe> in a <div> container.
- In the CSS for the <div>, add a percentage value for padding-bottom and set the position to relative, this will maintain the aspect ratio of the container. The value of the padding determines the aspect ratio. ie 56.25% = 16:9.
- In the CSS for the <iframe>, set the position to absolute, it will take a fixed position relative to the parent <div>.
<iframe frameborder="0" width="100%" height="100%" src="https://www.dailymotion.com/embed/video/Your_dailymotion_embed_URL" allowfullscreen allow="autoplay">
/* 16:9, for an aspect ratio of 1:1 change to this value to 100% */}
Example 2. Manual Embed with HTML only
This example is similar to example 1, but all the configuration and styling is configured within the HTML.
frameborder="0" width="100%" height="100%"
This technique can work with other aspect ratios (1:1, 4:3, 3:2, 8:5). The padding value ('padding-bottom:') determines the ratio, change the percentage padding-bottom values to change the ratio.