HSNCRC.
TRTell Me About Your Project

Services

  1. Blog
  2. Web Development

Adding Images With HTML: The img Tag And Its Correct Use

To add an image to an HTML page, you use the img tag. src specifies the address of the file, and alt specifies the text equivalent of the image. You can start with the small example below.

The Simplest Code For Adding An Image

<img
  src="/gorseller/atolye.webp"
  alt="Team preparing products in the workshop"
  width="1200"
  height="800"
>

Replace the file name here with your own image. The width and height values are the actual dimensions of the file in the example; use the ratio of your own file. No separate closing tag is written for img.

Do not turn the alt text into a keyword list. “Team preparing products in the workshop” describes the content of the photo. “Best workshop quality cheap product,” on the other hand, does not describe the image.

If the image serves only a decorative purpose, alt="" can be used. For a product, team or service photo, however, a description that carries information is needed.

How Should You Write The File Path?

<!-- File in the same folder -->
<img src="urun.webp" alt="Ceramic coffee cup">

<!-- Path starting from the site root -->
<img src="/gorseller/urun.webp" alt="Ceramic coffee cup">

A local path on your computer such as C:\fotograflar\urun.jpg does not work on the visitor’s device. The image needs to be uploaded together with the site.

When I prepare a product card, my order of checks is the existence of the file, its address and then its appearance. Trying to solve an address error by changing CSS only makes the work longer.

CSS That Prevents Overflow On Mobile

.icerik-gorseli {
  display: block;
  max-width: 100%;
  height: auto;
}

Add this class to the img tag as class="icerik-gorseli". This way the image can fit into a narrow space and keeps its ratio. Forcing all images to the same height can crop portraits or products unnecessarily.

For images further down the screen, loading="lazy" can be considered. Do not, however, automatically delay the large image that carries the main content on the first screen. Google’s LCP guide recommends that the LCP image not be lazy-loaded.

If The Image Does Not Appear, Check These

  • Are the file name and the extension really the same?
  • Is there an uppercase/lowercase difference?
  • Can you open the image address in a separate tab?
  • Has the file been included in the published folder?
  • Is CSS hiding the image or zeroing out its area?

Get a single image working first. Then add the gallery, effects and animation. This way you can tell which step causes the problem.

Frequently Asked Questions

Yes. You can place the img tag inside an a link. The purpose of the link should be clear from the image’s alt text or from the text next to it.

Is Using WebP Mandatory?

No. Choose the format according to the image and the needs of the project. I decide by comparing file size with visible quality.

Is Alt Text Enough For SEO On Its Own?

No. Descriptive alt text is one part of preparing accessible content. The content of the page and its technical structure matter too.

You can continue with HTML link code and the mobile site check.

Sources

Would You Like Help With Corporate Website?

A website that presents your brand accurately and is easy to use on mobile.

Let’s Talk About What You Have In Mind.

A new website, better organized digital communication, or an idea you want to develop… We can work out where to start together.

Tell Me About Your ProjectWhatsApp