Anchor: <a href> MCQs Quiz | Class 10
This quiz covers Class X Computer Applications (Code 165), Unit 2: HTML, focusing on the topic Anchor: <a href> MCQs Quiz | Class 10. You will be tested on Hyperlink creation and absolute/relative URLs. Submit your answers at the end and download a PDF of your results.
Understanding HTML Anchors: The <a> Tag and Hyperlinks
The <a> tag, also known as the anchor tag, is fundamental to the web. It allows you to create hyperlinks, which are clickable connections from one web resource to another. Without hyperlinks, the internet would be a collection of isolated pages instead of an interconnected web.
Key Concepts
1. Hyperlink Creation with href Attribute
The primary attribute of the <a> tag is href (Hypertext REFerence). This attribute specifies the URL (Uniform Resource Locator) of the page or resource the link goes to.
<a href="https://www.example.com">Visit Example.com</a>
When a user clicks on “Visit Example.com”, their browser will navigate to https://www.example.com.
2. Absolute URLs
An absolute URL is a complete address that specifies the exact location of a resource on the internet. It includes the protocol (e.g., http://, https://), domain name (e.g., www.example.com), and path to the file or resource. Absolute URLs are used when linking to external websites or when the full path is needed regardless of the current page’s location.
Example: https://www.google.com/search?q=html+anchors
This URL explicitly tells the browser exactly where to find the resource, no matter where the current page is located.
3. Relative URLs
A relative URL specifies the location of a resource relative to the current document’s base URL. They are typically used for linking to other pages within the same website. Relative URLs are shorter and make website maintenance easier, as they don’t need to be updated if the domain name changes.
- Linking to a file in the same directory:
<a href="about.html">About Us</a> - Linking to a file in a subdirectory:
<a href="pages/contact.html">Contact Us</a> - Linking to a file in a parent directory:
<a href="../index.html">Home</a> - Linking to a specific section on the same page (fragment identifier):
<a href="#section-id">Go to Section</a>
The browser constructs the full URL by combining the base URL of the current page with the relative path.
Comparison of Absolute vs. Relative URLs
| Feature | Absolute URL | Relative URL |
|---|---|---|
| Completeness | Full web address (protocol, domain, path) | Path relative to current document |
| Usage | External websites, specific internal locations | Internal links within the same website |
| Flexibility | Less flexible if domain changes | More flexible, easier for site migration |
| Example | https://www.cbsequiz.in/class10/ |
../css/style.css |
Other Important Attributes
target="_blank": Opens the linked document in a new window or tab.title="Tooltip Text": Provides advisory information about the element.
Quick Revision Checklist
- The
<a>tag creates hyperlinks. - The
hrefattribute specifies the destination URL. - Absolute URLs provide a full, complete web address.
- Relative URLs provide a path relative to the current page.
- Use
target="_blank"to open links in a new tab.
Practice Questions
- Which attribute of the
<a>tag is used to specify the URL of the linked resource? - An absolute URL always starts with what?
- If you are on
example.com/blog/post1.htmland want to link toexample.com/about.html, what would be a suitable relative URL? - What is the purpose of setting
target="_blank"in an anchor tag? - Which type of URL is generally preferred for linking to pages within the same website to enhance portability?