Chapter 4. HTML: Add Links and Images

In this chapter, you will learn how to enhance your web pages by adding links and images. These elements are essential for navigation and visual appeal. We will cover how to use the <a>
tag for links, the <img>
tag for images, and explore various attributes and best practices for both. Additionally, we’ll introduce you to other HTML tags that assist with linking and embedding external resources.
What We Cover in This Chapter
The following topics are covered in this chapter:
Overview of Adding Links and Images
Links and images are fundamental to web design. Links help users navigate between pages and resources, while images enhance the visual appeal of your site. In this chapter, we’ll explore how to effectively incorporate these elements into your HTML code, enabling a more interactive and engaging user experience.
Embed Images – <img>
The <img>
tag is used to embed images into your HTML pages. In this section, we’ll cover the essential attributes of this tag, focusing on the src
attribute, which points to the location of the image file. We’ll also look at the alt
attribute, which is crucial for accessibility, providing alternative text descriptions for images when they can’t be displayed.
Image File Format
Choosing the right image format is crucial for web performance and quality. In this section, we’ll explore common formats such as JPEG, PNG, and GIF. We’ll discuss the strengths and weaknesses of each format and when to use them for optimal website performance and visual quality.
Add Hyperlinks – <a>
Hyperlinks allow users to navigate between pages, websites, and even specific sections within the same page. The <a>
tag is used to create links, and the href
attribute defines the target destination. In this section, we’ll explore how to link to both internal and external URLs effectively.
Add Hyperlinks to Images
You can also use the <a>
tag to create clickable images. This is commonly used for linking to other pages or external sites through image-based navigation. In this section, we’ll demonstrate how to wrap an <img>
tag inside an <a>
tag to make the image a clickable link.
Add Hyperlinks to Specific Location on Web Page
Anchor links allow users to navigate to specific sections of the same page. You can create anchor links by using id
attributes on elements and linking to those IDs within the <a>
tag’s href
attribute. In this section, we’ll explore how to create internal navigation menus or jump to specific content on long pages.
Link Tag – <link>
The <link>
tag is used to link external resources, such as stylesheets, to your HTML document. Typically placed inside the <head>
section, this tag is essential for connecting your HTML pages to external CSS files. We’ll explore its role in styling your web pages.
Script Tag – <script>
The <script>
tag is used to include JavaScript files or inline JavaScript code in your HTML. In this section, we’ll explore how to integrate JavaScript into your web pages, whether by linking to an external JavaScript file or embedding inline code. We’ll also discuss the best practices for placing <script>
tags in your HTML for optimal performance.
Learn offline for better focus!
A book for this course is available on Amazon.
HTML & CSS Visual Guide
Step By Step Manual for Complete Beginners with Zero Coding Experience to Build Stunning Websites from Scratch
Get the Book Now