IMAGE TAGS

The image tag in HTML is represented by <img> and is used to embed images into a webpage.

Basic Syntax

This is how the syntax to embed an image in html looks like:

app/index.html
1  <img src="image's path" />

Setting Mandatory Attributes

The "src" and "alt" attributes are essential for the proper functioning of the <img> tag.

  • src attribute: Specifies the path to the image file.
  • alt attribute: Provides a text description for the image.
app/index.html
1 <img src="images/profile_picture.jpg" alt="Profile Picture" />

Setting Image Dimensions

Although dimensions can be set using the "width" and "height" attributes in the <img> tag, modern best practices recommend using CSS for this purpose.

app/index.html
1<img src="image.png" alt="Description" width="300" height="100" />

Setting the width and height attributes for images in HTML can have a positive impact on Search Engine Optimization (SEO). Specifying these dimensions in the <img> tag allows browsers to allocate the correct amount of space on a web page even before the image is fully loaded. This prevents layout shifts, improving the Cumulative Layout Shift (CLS) score—a key metric in Google's Core Web Vitals. A better CLS score can lead to a higher page ranking in search engine results.

Tip : Styling dimensions and other properties are now more commonly managed through CSS for better flexibility and maintainability.