Anchor and Image tags in HTML
1.<a>
(Anchor Tag):
- a). The
<a>
tag is used to create hyperlinks, which allow users to navigate to other web pages or resources by clicking on the linked text or image. - b). The primary attribute used with the
<a>
tag ishref
(hypertext reference), which specifies the URL of the linked resource. - c).You can use the
<a>
tag to link to other web pages, external websites, local files, email addresses, and more.
Example:-
<a href="https://www.example.com">Visit google.com</a>
In this example, the <a>
tag creates a hyperlink that, when clicked, takes the user to the "https://www.google.com" web page.
The<a>
tag can also be used with an optionaltarget
attribute to control how the linked resource is displayed (e.g., in a new browser window or tab). For example:
<a href="https://www.google.com" target="_blank">Visit google.com in a new tab</a>
2. <img>
(Image Tag):
- a).The
<img>
tag is used to embed images in web pages. It allows you to display images on a web page by specifying the image file's source (URL). - b). The primary attribute for the
<img>
tag issrc
(source), which specifies the URL of the image file. - c).Additionally, you can use the
alt
attribute to provide alternative text for the image. This text is displayed if the image cannot be loaded or if a user is using a screen reader. - Example:
- <img src="image.jpg" alt="An example image">
In this example, the
<img>
tag embeds an image from the file "image.jpg" and provides alternative text.You can also specify other attributes to control the image's width, height, alignment, borders, and more. For instance:
<img src="image.jpg" alt="An example image" width="200" height="150" border="1" align="right">
These attributes control the image's dimensions, border, and alignment.
Both the
<a>
and<img>
tags are widely used in web development to create hyperlinks and display images, respectively. They are essential for enhancing the interactivity and visual appeal of web pages.Result:-