0
0
HTMLmarkup~20 mins

Linking to sections using IDs in HTML - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Section Link Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
rendering
intermediate
2:00remaining
What happens when you click this link?
Given the HTML below, what will the browser do when the user clicks the link labeled Go to Section 2?
HTML
<nav>
  <a href="#section2">Go to Section 2</a>
</nav>
<main>
  <section id="section1">
    <h2>Section 1</h2>
    <p>Welcome to section one.</p>
  </section>
  <section id="section2">
    <h2>Section 2</h2>
    <p>This is the second section.</p>
  </section>
</main>
AThe page reloads and shows Section 1 at the top.
BThe page scrolls to the top of Section 2.
CNothing happens because the link is broken.
DThe browser opens a new tab with Section 2 content.
Attempts:
2 left
💡 Hint
Look at the href attribute and the id attributes of the sections.
📝 Syntax
intermediate
2:00remaining
Which anchor tag correctly links to the section with id="contact"?
Choose the correct anchor tag that links to the section with id="contact".
A<a href="section#contact">Contact Us</a>
B<a href="contact">Contact Us</a>
C<a href="#contact">Contact Us</a>
D<a href="/contact">Contact Us</a>
Attempts:
2 left
💡 Hint
Links to sections on the same page use a hash (#) followed by the id.
selector
advanced
2:00remaining
Which CSS selector targets the section linked by <a href="#about">?
You have a link <a href="#about">About</a>. Which CSS selector will style the section it links to?
Asection[href="#about"]
Ba[href="#about"]
C#about a
Dsection#about
Attempts:
2 left
💡 Hint
The link points to an element with id="about". How do you select an element by id?
layout
advanced
2:00remaining
How to keep the linked section visible below a fixed header?
You have a fixed header 60px tall. When clicking a link to a section with an ID, the section's top is hidden behind the header. How can you fix this so the section content is fully visible below the header?
AAdd padding-top: 60px and margin-top: -60px to the section with the ID.
BAdd margin-bottom: 60px to the section with the ID.
CAdd padding-bottom: 60px to the fixed header.
DAdd margin-top: 60px to the fixed header.
Attempts:
2 left
💡 Hint
Think about shifting the section content down without changing layout flow.
accessibility
expert
2:00remaining
What ARIA attribute improves accessibility for links to page sections?
When linking to a section on the same page using an anchor with href="#sectionID", which ARIA attribute helps screen readers understand the link's purpose better?
Aaria-label="Jump to Section"
Baria-hidden="true"
Caria-live="polite"
Daria-disabled="true"
Attempts:
2 left
💡 Hint
Think about how to describe the link clearly for screen readers.