Common Html Media Elements
HTML media refers to multimedia elements in web pages that involve various types of content like images, audio, video, and other interactive features. These elements enhance the user experience and make websites more engaging and informative. Here is an overview of common HTML media elements
Images <img>
Audio <audio>
Video <video>
Embed <embed>
Object <object>
Iframe <iframe>
Images <img>:
Images are used to enhance the visual appeal of a website and can serve multiple purposes such as decoration, illustration, or conveying specific information
Key attributes of <img> include:
‘src’:Specifies the source of the image which can be a relative or absolute URL.
‘alt’: Provides alternative text for accessibility and search engine optimization(SEO)
‘height’ and ‘width’: Define the dimensions of the image this helps with layout and performance optimization
‘title’:Offers a tooltip when users hover the image.
<img src="example.jpg" alt="An example image" width="500" height="300">
Audio <audio>:
The <audio> element allows embedding of audio files in web pages. you can specify one or more audio sources and define the controls
Important attributes of <audio> include
‘Controls’: Displays playback controls allowing users to play, pause and adjust volume.
‘Autoplay’: plays the audio automatically when the page loads, this is avoided to prevent annoying users
‘Loop’: causes the audio to repeat when it reaches the end
‘Muted’: mutes audio by default
‘preload’:Determines how much audio is preloaded before playback begins. Options are “none”,” metadata” or “auto”
<audio controls>
<source src="example.mp3" type="audio/mpeg">
</audio>
Video <video>:
The <video> element is used to embed video files. It has similar attributes to <audio> but with additional ones for visual aspects
Key attributes include
‘Controls’: Displays playback controls.
‘Poster’: Specifies an image to display while the video is loading or if it cannot be played
‘preload’:Like with audio it determines how much data is preloaded.
‘Autoplay’,’ loop’,’ muted’: This works the same as for audio.
<video controls poster="poster.jpg">
<source src="example.mp4" type="video/mp4">
</video>
Embed <embed>:
The <embed> element is used to embed content from other sources like PDFs Flash files or videos. It has fewer attributes than <object> making it simpler to use. However, this element is very limited today due to the decline of Flash and better alternatives for embedding content
<embed src="source_url" type="mime_type" width="width" height="height">
Object <object>:
The <object> element is a versatile way to embed different types of content such as PDFs or other multimedia files. It can also be used for embedding Java applets and Flash content, though these are less common due to security issues
Key attributes include
‘Data’: specifies the source of content.
‘Type’: Defines the MIME type of the embedded content.
‘Width’ and ‘height’: determine the dimensions of the embedded content
<object data="source_url" type="mime_type" width="width" height="height">
<!-- Optional fallback content -->
Fallback content or message
</object>
Iframe<iframe>:
The <iframe> element is used to embed another web page or external content within a webpage. This is commonly used for embedding YouTube videos, Google Maps or other interactive content important attributes of iframe include
‘Src’: Specifies the source of the embedded content.
‘Width’ and ‘height’: Define the dimensions of the iframe.
‘Sandbox’: Restricts what the embedded content can do to enhance security
‘Allowfullscreen’: Allows the embedded content to go fullscreen.
<iframe src="https://www.example.com" width="600" height="400"></iframe>
Subscribe to my newsletter
Read articles from Reagan Mwangi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by