Media in HTML
? Media in HTML
HTML supports embedding different types of media like images, audio, and video to make webpages rich and interactive.
1. Images
Use the <img> tag to embed images.
<img src="image.jpg" alt="Description of image" width="300" height="200">src: Path to the image filealt: Alternative text for accessibilitywidth&height: Size of the image (optional)
2. Audio
Use the <audio> tag to embed sound.
<audio controls> <source src="audio.mp3" type="audio/mpeg"> Your browser does not support the audio element.</audio>controls: Adds play/pause controls<source>allows multiple formats for browser compatibility
3. Video
Use the <video> tag to embed videos.
<video width="640" height="360" controls> <source src="video.mp4" type="video/mp4"> Your browser does not support the video tag.</video>controls: Shows video controlsCan include multiple
<source>for different formatsSupports attributes like
autoplay,loop,muted
4. Other Media Embedding
Embed YouTube Videos (via <iframe>)
<iframe width="560" height="315" src="https://www.youtube.com/embed/VIDEO_ID" frameborder="0" allowfullscreen></iframe>Summary
| Tag | Use |
|---|---|
<img> | Display images |
<audio> | Play audio files |
<video> | Play video files |
<iframe> | Embed external content (e.g., videos, maps) |
Want examples of styling media elements or handling media with JavaScript?