Back to course

Lesson 13: Embedding Images (`<img>`)

The HTML Masterclass: From Zero to Web Developer

13. Embedding Images (<img>)

Images are embedded using the self-closing <img> tag. It requires two mandatory attributes.

13.1 Mandatory Attributes

  1. src (Source): Specifies the path (absolute or relative) to the image file.
  2. alt (Alternate Text): Provides a text description of the image. This is vital for accessibility (screen readers) and SEO, and appears if the image fails to load.

html A large group of people collaborating on a computer project.

13.2 Defining Size

While you will primarily use CSS to control image size, you can set the default dimensions using the width and height attributes (in pixels, without the px unit).

html Company Logo

Best Practice: Always define the width and height for performance reasons. This allows the browser to reserve the space before the image is loaded, preventing layout shifts.