Bird
Raised Fist0
HTMLmarkup~20 mins

Anchor tag basics in HTML - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Anchor Tag Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ rendering
intermediate
1:30remaining
What is the visible text of this anchor tag?
Look at the anchor tag below. What text will you see on the webpage?
HTML
<a href="https://example.com">Visit Example</a>
Ahttps://example.com
BClick here
Cexample.com
DVisit Example
Attempts:
2 left
💡 Hint
The text between and tags is what shows on the page.
🧠 Conceptual
intermediate
1:30remaining
What does the href attribute do in an anchor tag?
Choose the best description of the href attribute in an anchor tag.
AIt defines the URL the link points to.
BIt sets the color of the link text.
CIt makes the link open in a new tab.
DIt adds a tooltip when hovering over the link.
Attempts:
2 left
💡 Hint
Think about what happens when you click a link.
📝 Syntax
advanced
2:00remaining
Which anchor tag opens the link in a new browser tab?
Select the anchor tag code that opens the link in a new tab when clicked.
A<a href="https://example.com" newtab>Open in new tab</a>
B<a href="https://example.com" target="new">Open in new tab</a>
C<a href="https://example.com" target="_blank">Open in new tab</a>
D<a href="https://example.com" open="new">Open in new tab</a>
Attempts:
2 left
💡 Hint
The target attribute controls where the link opens.
❓ accessibility
advanced
2:00remaining
Which anchor tag is best for accessibility?
Choose the anchor tag that improves accessibility by describing the link purpose clearly.
A<a href="https://example.com">Click here</a>
B<a href="https://example.com" aria-label="Visit Example website">Example</a>
C<a href="https://example.com">Example</a>
D<a href="https://example.com" title="Example">Link</a>
Attempts:
2 left
💡 Hint
Screen readers use aria-label to describe links better.
❓ selector
expert
2:30remaining
Which CSS selector styles only anchor tags inside a nav element?
Select the CSS selector that applies styles only to anchor tags inside a
Anav a { color: blue; }
Ba nav { color: blue; }
Cnav > a { color: blue; }
Da > nav { color: blue; }
Attempts:
2 left
💡 Hint
Think about how CSS selects child elements inside parents.

Practice

(1/5)
1. What does the <a> tag do in HTML?
easy
A. Creates a clickable link to another page or resource
B. Defines a paragraph of text
C. Inserts an image into the page
D. Adds a heading to the page

Solution

  1. Step 1: Understand the purpose of the <a> tag

    The <a> tag is used to create links that users can click to go to other pages or resources.
  2. Step 2: Compare with other tags

    Other tags like <p>, <img>, and <h1> serve different purposes such as paragraphs, images, and headings.
  3. Final Answer:

    Creates a clickable link to another page or resource -> Option A
  4. Quick Check:

    Anchor tag = clickable link [OK]
Hint: Anchor tag always creates clickable links [OK]
Common Mistakes:
  • Confusing <a> with <p> or <img>
  • Thinking <a> adds images or text formatting
  • Ignoring the clickable nature of <a>
2. Which of the following is the correct syntax to create a link to "https://example.com" with the text "Visit Example"?
easy

Solution

  1. Step 1: Identify the correct attribute for link destination

    The correct attribute to specify the link URL is href inside the <a> tag.
  2. Step 2: Check the tag and attribute usage

    <a href="https://example.com">Visit Example</a> uses <a> with href and link text correctly. Other options use wrong attributes or tags.
  3. Final Answer:

    <a href="https://example.com">Visit Example</a> -> Option A
  4. Quick Check:

    Use <a href="URL">text</a> for links [OK]
Hint: Use href attribute inside <a> for links [OK]
Common Mistakes:
  • Using url instead of href attribute
  • Using <link> tag instead of <a>
  • Omitting href attribute
3. What will the following HTML code display in the browser?
<a href="#section2">Go to Section 2</a>
<h2 id="section2">Section 2</h2>
medium
A. A link that opens a new tab to a page named 'section2'
B. An error message because href cannot start with #
C. A clickable link labeled 'Go to Section 2' that scrolls to the heading 'Section 2' on the same page
D. Plain text 'Go to Section 2' with no link

Solution

  1. Step 1: Understand href with # and id attribute

    The href="#section2" links to an element with id="section2" on the same page, causing the page to scroll there.
  2. Step 2: Check the displayed content

    The link text 'Go to Section 2' is clickable and scrolls to the heading labeled 'Section 2'.
  3. Final Answer:

    A clickable link labeled 'Go to Section 2' that scrolls to the heading 'Section 2' on the same page -> Option C
  4. Quick Check:

    href="#id" scrolls to element with that id [OK]
Hint: href="#id" links inside same page [OK]
Common Mistakes:
  • Thinking # means new page or error
  • Expecting new tab to open
  • Ignoring id attribute connection
4. Find the error in this anchor tag code:
<a href="www.example.com">Example</a>
medium
A. href attribute should be written as link
B. Incorrect closing tag, should be <a />
C. Text 'Example' should be inside quotes
D. Missing protocol like https:// in href URL

Solution

  1. Step 1: Check href URL format

    The href value 'www.example.com' lacks the protocol (http:// or https://), so the browser treats it as a relative link.
  2. Step 2: Understand correct URL usage

    To link to an external site, the URL must include the protocol like 'https://www.example.com'.
  3. Final Answer:

    Missing protocol like https:// in href URL -> Option D
  4. Quick Check:

    External links need full URL with protocol [OK]
Hint: Always include https:// for external links [OK]
Common Mistakes:
  • Omitting https:// causes relative link errors
  • Using self-closing tag incorrectly
  • Misnaming href attribute
5. You want to create an email link that opens the user's email program to send mail to "contact@example.com". Which anchor tag is correct?
hard

Solution

  1. Step 1: Identify the correct protocol for email links

    Email links use the mailto: protocol in the href attribute to open the email client.
  2. Step 2: Check each option's syntax

    <a href="mailto:contact@example.com">Send Email</a> uses mailto:contact@example.com correctly. <a href="email:contact@example.com">Send Email</a> uses wrong protocol 'email:', while others lack the protocol or use incorrect formats like 'mailto://'.
  3. Final Answer:

    <a href="mailto:contact@example.com">Send Email</a> -> Option B
  4. Quick Check:

    Email links use mailto: prefix [OK]
Hint: Use mailto: before email address in href [OK]
Common Mistakes:
  • Using email: instead of mailto:
  • Omitting mailto: prefix
  • Adding extra slashes after mailto:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard