Creating Links & Adding Images in HTML (With Practical Examples)

After learning HTML basics and common tags, the next important step is understanding how to create links and add images to a webpage. These two elements are essential for building real, usable websites.

In this blog, we’ll learn how the <a> (anchor) and <img> (image) tags work, along with practical examples you can try yourself.


Creating Links in HTML (<a> Tag)

The <a> tag is used to create clickable links that take users to another page, website, or location.

Basic Link Example

<a href="https://example.com">Visit Example</a>

Important Attributes

  • href → The destination URL

  • Link text → The clickable text users see


Opening Links in a New Tab

To open a link in a new browser tab, use the target attribute:

<a href="https://example.com" target="_blank"> Open Example in New Tab </a>

Use Case

  • External websites

  • References

  • Social media links


Linking to Internal Pages

You can also link to pages within your website:

<a href="about.html">About Us</a>

Use Case

  • Navigation menus

  • Multi-page websites


Email & Phone Links

Email Link

<a href="mailto:contact@example.com">Email Us</a>

Phone Link

<a href="tel:+911234567890">Call Us</a>

Use Case

  • Contact pages

  • Business websites


Adding Images in HTML (<img> Tag)

The <img> tag is used to display images on a webpage.
It is a self-closing tag.

Basic Image Example

<img src="image.jpg" alt="Sample image">

Important Attributes

  • src → Path to the image

  • alt → Text shown if the image fails to load


Setting Image Width & Height

<img src="logo.png" alt="Website Logo" width="200" height="100">

Use Case

  • Logos

  • Thumbnails

  • Banners


Using Images from a Folder

If your image is inside a folder:

<img src="images/profile.png" alt="Profile Image">

Best Practice

Keep images organized inside folders like images/ or assets/.


Making an Image Clickable

You can wrap an image inside a link:

<a href="https://example.com"> <img src="banner.jpg" alt="Click to visit"> </a>

Use Case

  • Advertisement banners

  • Clickable logos


Why alt Text Is Important

The alt attribute:

  • Helps screen readers
  • Improves SEO
  • Displays text if image fails to load

Always write meaningful alt text.


Common Mistakes to Avoid

  • Missing alt attribute
  • Incorrect file path in src
  • Using very large image files
  • Opening all links in new tabs unnecessarily


Conclusion

Links and images bring life to a webpage. Using the <a> and <img> tags correctly allows you to:

  • Connect pages

  • Navigate users

  • Display visual content

  • Build real-world websites

Once you master these tags, you’re ready to move into CSS styling and layouts.

Comments

Popular posts from this blog

Numbers & Numeric Operations in C++: Data Types & cmath Functions

Introduction to C++: Your First Program & Hello World

Intro to C++ for Beginners

User Input in C++: Reading Data from Keyboard with cin & getline()

Mad Libs Game in C++: Build Your First Interactive Program

Strings in C++: Basics, Methods & Examples

Variables & Data Types in C++: Basics with Examples

Printing Patterns in C++: Shape Output with Loops & Logic

Return Statement in C++: Syntax, Purpose & Examples

Functions in C++: Syntax, Use & Examples