logo

Very Short Question and Answers - Anchor tag <a>


Q 1.
What is the main purpose of the anchor (`<a>`) tag in HTML?

Ans:

The anchor tag is used to create hyperlinks that enable navigation between web pages, sections of a page, email addresses, phone numbers, or files.

Q 2.
Write the basic syntax of the anchor tag.

Ans:

The basic syntax is:

<a href="URL">Link Text</a>
Q 3.
What does the 'href' attribute specify in the `<a>` tag?

Ans:

The 'href' attribute specifies the destination or the URL to which the link points.

Q 4.
What will happen if you do not include the 'href' attribute in an `<a>` tag?

Ans:

Without the 'href' attribute, the anchor tag will not create a functional hyperlink; it will just be plain text (or styled text if CSS is used).

Q 5.
Explain the use of the 'target' attribute in the anchor tag with an example.

Ans:

The 'target' attribute defines where to open the linked document. For example, target="_blank" opens the link in a new tab or window.

Q 6.
What is the difference between target="_self" and target="_blank"?

Ans:

target="_self" opens the link in the same tab (default), while target="_blank" opens it in a new tab or window.

Q 7.
How would you create a link that allows users to download a file instead of opening it?

Ans:

By adding the 'download' attribute to the anchor tag, e.g.,

<a href="notes.pdf" download>Download Notes</a>
Q 8.
Describe how to create an internal link that jumps to a specific section within the same page.

Ans:

First, assign an 'id' to the target element e.g.,

<h2 id="section1">

Then, create a link like

<a href="#section1">Go to Section 1</a>
Q 9.
What is the purpose of the 'title' attribute in an anchor tag?

Ans:

The 'title' attribute provides extra information (a tooltip) for the link when hovered by the mouse.

Q 10.
Give an example of a 'mailto:' link and explain its use.

Ans:

Example:

<a href="mailto:teacher@example.com">Email Teacher</a> 

This link opens the user's default email client to send an email to the provided address.

Q 11.
How can you create a clickable phone number link in HTML?

Ans:

By using

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

which allows users to call the number directly from devices that support calling.

Q 12.
What is the use of the 'rel' attribute in an anchor tag?

Ans:

The 'rel' attribute defines the relationship between the current page and the linked page, often used for security and SEO (e.g., 'noopener', 'noreferrer', 'nofollow').

Q 13.
When should you use rel="noopener" or rel="noreferrer" with an anchor tag?

Ans:

They should be used when using target="_blank" to prevent security and privacy risks.

Q 14.
Can the text between the opening and closing <a> tags be anything other than plain text?

Ans:

Yes, it can be any HTML content such as images, spans, or formatted text.

Q 15.
What is a bookmark in the context of anchor tags and how is it achieved?

Ans:

A bookmark refers to a specific place within the same page, achieved by assigning an 'id' to an element and linking to it with href="#id".

Q 16.
Write an HTML link that opens 'https://www.cbse.gov.in' in a new tab and displays 'CBSE Website'.

Ans:

<a href="https://www.cbse.gov.in" target="_blank">CBSE Website</a>
Q 17.
How do you add a tooltip saying "Go to CBSE Official Website" when hovering over a link?

Ans:

By using the title attribute:

<a href="https://www.cbse.gov.in" title="Go to CBSE Official Website">Visit CBSE Website</a>
Q 18.
What does href="#top" do?

Ans:

It links to the element with id="top" on the same page, typically used to jump to the top section.

Q 19.
Why is the anchor tag called the 'glue of the internet'?

Ans:

Because it connects documents, websites, and various resources together, making seamless navigation possible.

Q 20.
Can you use an anchor tag to link to a file for downloading? If yes, how?

Ans:

Yes, by using the 'href' to point to the file and adding the 'download' attribute, e.g.,

<a href="notes.pdf" download>Download Notes</a>