December 3, 2026 - 08:49
HTML Lesson 09 — img, src and alt: Add Images to a Page Image
HTML & CSS Tutorials

HTML Lesson 09 — img, src and alt: Add Images to a Page

0 Comments

Putting an image file in your project folder does not automatically show it on the page. We need to tell the browser where it is and how it contributes to the content. This lesson uses an included drawing, so no external image download is required.

Place the source file

Create a gorseller folder beside index.html and copy the supplied notlar.svg into it. SVG is an image format browsers can display; the same img principle applies to JPEG or WebP files. Renaming an extension does not convert an image to another format.

HTML
<img src="gorseller/notlar.svg"
     alt="Açık defterin sol sayfasında üç not satırı"
     width="640" height="420">

src is the source address. Here it means “notlar.svg inside the gorseller folder next to this page.” img has no closing tag. We refer to a separate file through an attribute rather than placing the picture between tags.

Alternative text depends on purpose

alt provides a text alternative in this context. The Turkish example describes an open notebook with three lines on its left page. An alternative such as “image” conveys little, and repeating notlar.svg only repeats the file name.

If an image is the only content of a link, its alternative may need to describe the link's purpose. If the relevant information is already fully supplied by neighboring text, or the image is purely decorative, an empty alternative can be appropriate:

HTML
<img src="gorseller/notlar.svg" alt="" width="640" height="420">

An empty alt and a missing alt are different choices. The empty value explicitly indicates that there is no additional text alternative to announce. Alternative text is not a keyword container or a guaranteed tooltip.

Compare size with proportion

The drawing is 640 by 420. Its width and height help the browser reserve space. Changing them to 320 and 210 preserves the proportion. Changing them to 640 and 100 squashes the drawing.

Displaying an image smaller does not reduce the file's download size. We will handle fitting images to containers and narrow screens with CSS later. For now, distinguish the source file from its displayed dimensions.

Choose alternative text for the image's job

The same notebook drawing can convey details in an illustration lesson, act as the only content of a link, or merely decorate a heading. The right alternative depends on that role rather than on the filename.

HTML
<a href="notlar.html">
  <img src="gorseller/notlar.svg" alt="Open the lesson notes" width="160" height="105">
</a>

This demonstrates a linked image. Supply the destination file if using it. Its alternative describes the destination. If the link already has sufficient visible text, avoid making the image repeat it unnecessarily.

Title does not replace alt

Title may appear as a hover tooltip in some desktop browsers. Do not assume equivalent access by touch or keyboard. Alt supplies an alternative for the image's content or function, which is a different purpose.

A diagram requiring a long explanation can use visible text for details and a concise alternative identifying its purpose. Hiding all that information in a long attribute is not automatically more accessible. We will meet figure and figcaption when organizing document content.

Reserve the right proportions

Accurate width and height attributes can help reserve proportionate space before loading, reducing movement of neighboring text. Incorrect numbers can describe the wrong ratio, so they are not arbitrary decoration.

Later CSS can constrain width and calculate height automatically without requiring us to remove every HTML dimension. Both 640×420 and 320×210 preserve this drawing's ratio; 320×420 does not. Predict the difference before trying it.

Display size is not download size

A large source can still be expensive to download when displayed at 200 pixels. CSS resizing does not recompress it. WebP, PNG, JPEG and SVG suit different needs; changing the extension is not conversion.

We may later consider loading hints for off-screen images. Automatically making an immediately visible main cover lazy is not a universal optimization. This lesson first establishes a correct source, useful meaning and accurate proportions.

Break the path deliberately

Change src to gorseller/yok.svg and refresh. The image fails to load and the browser may display its alternative text. A reserved rectangle alone is not evidence of a successful load. Restore the correct path afterwards.

Preserve the exact spelling and capitalization when uploading the project. A case difference tolerated on Windows may point to a nonexistent file on a Linux host.

References: Reference 1 · Reference 2

Related Articles

Comments (0)

No comments yet. Be the first to comment!

Leave a Comment