Incorporating Images into HTML

Images enhance the visual appeal of webpages, making them more engaging. These images could range from a company's logo on its homepage to a gallery of photos on a portfolio website. To incorporate images into an HTML page, we use the <img> tag. Notice that the tag does not have a closing </img> tag. Here's the syntax:

HTML
<img src="" alt="">
Source Attribute (`src`)

The src attribute specifies the image source or URL. A webpage can add a diverse range of images, from a product image for an online store to an icon indicating a caution sign or even a background image to enhance the webpage's artistic appeal. Here's how to specify the source of an image using the src attribute:

<img src="https://codesignal-staging-assets.s3.amazonaws.com/uploads/1702500465136/html-placeholder1.png">
Alt Attribute (`alt`)

The alt attribute provides alternative text in case the image doesn't load or is processed by screen readers. This attribute is particularly crucial when the image fails to load for any reason or when visually impaired users use screen readers to comprehend the content of the page. Here's how to use it:

<img src="https://codesignal-staging-assets.s3.amazonaws.com/uploads/1702500465136/html-placeholder1.png" alt="A placeholder image">

In scenarios where the image doesn't load, the text "A placeholder image" is displayed instead.

Exploring File Paths

File paths are the addresses of files on your computer or online, guiding your HTML code to determine the file's location. Working with local files, such as images stored on your computer, necessitates an understanding of absolute or relative file paths.

Absolute File Paths

An 'absolute' path is like giving someone the full address to your house by starting with the city name, progressing to the area, street, and concluding with the house number. Absolute paths include the full directory path to the file. In the image example above, we used an absolute path, which is the full URL to the image.

Relative File Paths
Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal