HTML Links and Images: Hyperlinks, Anchors, Img Tag, Alt Text & Best Practices 2025
1. How do you create a hyperlink in HTML?
To create a hyperlink, use the <a> (anchor) tag with the href attribute specifying the destination URL. The text or content inside the <a> tag becomes clickable.
<a href="https://www.example.com">Visit Example</a>
2. How can you make a link open in a new browser tab or window?
Add the target="_blank" attribute to the <a> tag. This instructs the browser to open the link in a new tab or window.
<a href="https://www.example.com" target="_blank">Open in new tab</a>
3. How do you create a link that opens the user's email client to send an email?
Use the mailto: protocol in the href attribute of the <a> tag.
<a href="mailto:someone@example.com">Send Email</a>
4. How can you link to a specific section within the same webpage?
Assign an id attribute to the target element and create a link referencing that id with a hash (#).
<a href="#section1">Go to Section 1</a>
...
<div id="section1">Section 1 content</div>
5. How do you insert an image into an HTML page?
Use the <img> tag with the src attribute specifying the image file's URL or path. The alt attribute provides descriptive alternative text for accessibility and cases where the image cannot be displayed.
<img src="image.jpg" alt="Description of the image">
6. What is the purpose of the alt attribute in an image tag?
The alt attribute provides alternative text that describes the image content. This text is displayed if the image fails to load and is read by screen readers to assist visually impaired users. Including meaningful alt text improves accessibility and SEO.
7. How can you control the size of an image in HTML?
You can specify the image's width and height using the width and height attributes directly in the <img> tag or by applying CSS styles.
<img src="image.jpg" alt="Description" width="300" height="200">
8. How do you make an image act as a clickable link?
Wrap the <img> tag inside an <a> tag. This makes the image itself clickable and navigates to the specified URL.
<a href="https://www.example.com">
<img src="image.jpg" alt="Clickable image">
</a>