HTML & CSS - Mastery / HTML Advanced Elements

Media: Adding Images, Audio, and Video

📸 Media Types

In modern web development, HTML allows us to easily embed media content like images, audio, and video directly into web pages. These media elements improve user experience by making websites more interactive and engaging.

🖼️ Images

  • Tag: <img>

  • Purpose: Used to display pictures on a webpage.

  • Attributes:

    • src: Specifies the path to the image file.

    • alt: Alternative text shown if the image doesn’t load (important for accessibility).

    • width and height: Define the image size.


🎙️Audio

  • Tag: <audio>

  • Purpose: Embeds sound or music into the page.

  • Attributes:

    • controls: Adds play, pause, volume controls.

    • autoplay, loop, muted: Control playback behavior.

    • src or <source> tag is used to link the audio file.

Example:


📷 Video

  • Tag: <video>

  • Purpose: Embeds video content.

  • Attributes:

    • controls, autoplay, muted, loop—similar to <audio>.

    • width, height—to define video size.

    • <source> is used to provide different video file types for compatibility.

Example:

<body>
  <h1>Video Player</h1>
  <video width="400" height="300" controls>
    <source src="movie.mp4" type="video/mp4" />
    Your browser does not support the video tag.
  </video>
</body>

✅ Why It Matters

  • Embedding media makes your website dynamic.

  • It helps in education, marketing, and entertainment.

  • Ensures better user interaction and retention.