In HTML, media refers to content such as images, audio, and video that can be embedded in web pages to enhance user experience and provide visual or auditory context. HTML provides various elements and attributes to include, control, and manipulate media.


Create a directory imagesunder src. Download sample image from interent and add to the images directory.

Images

Used to display pictures or graphics.

img[src="images/sample.png" alt="Description of the image"]
img[src="images/sample.png" alt="Sample" width="200" height="100"]

Audio

Used to embed sound or music.

Create a directory audio under src. Download sample audio from interent and add to the audio directory.

audio[controls]>source[src="audio/sample.mp3" type="audio/mpeg"]{Your browser does not support the audio element.}
audio[controls]>source[src="audio/sample.mp3" type="audio/mpeg"]^{Your browser does not support the audio element.}

Video

Used to embed videos.

Create a directory video under src. Download sample video from interent and add to the video directory.

 video[controls]>source[src="video/sample.mp4" type="video/mp4"]^{Your browser does not support the video element.}
video[controls width=640 height=360 poster="poster.jpg"]>source[src="video/sample.mp4" type="video/mp4"]^{Your browser does not support the video element.}

Embedding Other Media (iframe)

Used to embed external media, such as YouTube videos, maps, or other websites.

iframe[src="https://www.youtube.com/embed/VIDEO_ID" width=560 height=315 allowfullscreen]
iframe[src="https://www.youtube.com/embed/dQw4w9WgXcQ" width=560 height=315 allowfullscreen]

Attributes Common to Media Elements

controls: Adds playback controls (play, pause, volume).

autoplay: Media starts automatically when the page loads.

loop: Media plays repeatedly.

muted: Starts the media in a muted state.

preload: Instructs the browser about how to load the media:


Example of All Media Together

html:5>head>meta[charset=UTF-8]+meta[name=viewport content="width=device-width, initial-scale=1.0"]+title{Media in HTML}^body>h1{HTML Media Examples}+h2{Image}+img[src=example.jpg alt="Example Image" width=300]+h2{Audio}+audio[controls]>source[src=example.mp3 type=audio/mpeg]^{Your browser does not support the audio element.}+h2{Video}+video[controls width=500]>source[src=example.mp4 type=video/mp4]^{Your browser does not support the video element.}+h2{YouTube Video}+iframe[src="https://www.youtube.com/embed/dQw4w9WgXcQ" width=560 height=315 allowfullscreen]


Classes
Quiz
Videos
References
Books