When adding images to your website, there are a few key attributes you should know about to make sure they display correctly and provide useful information.
src
: Source of the ImageThe src
attribute tells the browser where to find the image file. Think of it as the image's address. It's essential for the image to show up.
Example:
<img src="https://codersmile.com/codersmile.svg">
alt
: Alternative TextThe alt
attribute provides a text description of the image. This is important for accessibility (helping people who use screen readers) and also helps with SEO.
Example:
<img src="https://codersmile.com/codersmile.svg" alt="CoderSmile logo">
title
: Tooltip TextThe title
attribute gives extra information about the image. When someone hovers over the image, this text appears as a tooltip.
Example:
<img src="https://codersmile.com/codersmile.svg" alt="CoderSmile logo" title="Welcome to CoderSmile!">
The width
attribute sets how wide the image should be. You can use pixels or percentages.
Example:
<img src="https://codersmile.com/codersmile.svg" alt="CoderSmile logo" width="200">
The height
attribute sets how tall the image should be. Like width, it can be in pixels or percentages.
Example:
<img src="https://codersmile.com/codersmile.svg" alt="CoderSmile logo" width="200" height="100">
Putting it all together, here’s a complete example:
<img src="https://codersmile.com/codersmile.svg" alt="CoderSmile logo" title="Welcome to CoderSmile!" width="200" height="100">