In order to speed up loading times and enhance performance, responsive photos and videos change their dimensions and quality according to the viewing device. Compliant video formats and the srcset property in <img> tags aid in the responsiveness of multimedia material.
Code
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Responsive Images Example</title> </head> <body> <img src="small.jpg" srcset="small.jpg 500w, medium.jpg 1000w, large.jpg 1500w" alt="Responsive Image" sizes="(max-width: 500px) 100vw, (max-width: 1000px) 50vw, 33vw"> <video width="100%" controls> <source src="video.mp4" type="video/mp4"> <source src="video.webm" type="video/webm"> Your browser does not support the video tag. </video> </body> </html> |
Images: The browser can select from a variety of image files according to the screen width by using the srcset property, which guarantees that the right size picture loads. Additional information about the viewport width that the picture will occupy at various breakpoints can be found in the sizes property.
Videos: A 100% width ensures that the video is responsive, and offering a variety of video codecs (such as MP4 and WebM) guarantees compatibility with a variety of browsers and devices.
In order to speed up loading times and enhance performance, responsive photos and videos change their dimensions and quality according to the viewing device. Compliant video formats and the srcset property in <img> tags aid in the responsiveness of multimedia material.
Code
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Responsive Images Example</title> </head> <body> <img src="small.jpg" srcset="small.jpg 500w, medium.jpg 1000w, large.jpg 1500w" alt="Responsive Image" sizes="(max-width: 500px) 100vw, (max-width: 1000px) 50vw, 33vw"> <video width="100%" controls> <source src="video.mp4" type="video/mp4"> <source src="video.webm" type="video/webm"> Your browser does not support the video tag. </video> </body> </html> |
Images: The browser can select from a variety of image files according to the screen width by using the srcset property, which guarantees that the right size picture loads. Additional information about the viewport width that the picture will occupy at various breakpoints can be found in the sizes property.
Videos: A 100% width ensures that the video is responsive, and offering a variety of video codecs (such as MP4 and WebM) guarantees compatibility with a variety of browsers and devices.
Copyrights © 2024 letsupdateskills All rights reserved