Skip to main content

Introduction to Responsive Web Design - Media Videos

Responsive Web Design - Videos

Videos are an important element in web design and can be made responsive using various techniques.

One technique is to use HTML5 video tags with the max-width property set to 100%. This allows the video to scale with the width of its container while maintaining its aspect ratio.

As an example:


<video controls style="max-width: 100%;">
<source src="video.mp4" type="video/mp4">
<source src="video.webm" type="video/webm">
Your browser does not support the video tag.
</video>

Another technique is to use CSS to control the video's size and aspect ratio using media queries. For example, you can set different widths and heights for the video based on the screen size.

As an example:

video {
width: 100%;
height: auto;
}

@media (min-width: 768px) {
video {
width: 50%;
height: auto;
}
}

In this example:

  • The video takes up the full width of the container by default, but when the screen width is at least 768 pixels, its width is set to 50% of the container.
optimize video

It's important to optimize video file sizes to reduce page load times, especially for mobile devices with slower internet connections.