Challenge - 5 Problems
Nested Elements Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ rendering
intermediateWhat is the visual output of nested and elements?
Consider this HTML code snippet:
What will the browser display?
<section>
<article>
<h2>Title</h2>
<p>Paragraph inside article.</p>
</article>
<p>Paragraph inside section but outside article.</p>
</section>What will the browser display?
HTML
<section> <article> <h2>Title</h2> <p>Paragraph inside article.</p> </article> <p>Paragraph inside section but outside article.</p> </section>
Attempts:
2 left
💡 Hint
Remember that nested elements inside and are all displayed unless hidden by CSS or scripts.
✗ Incorrect
The contains an with a heading and paragraph, plus another paragraph outside the article but inside the section. All these elements render in order.
❓ selector
intermediateWhich CSS selector targets only paragraphs inside elements nested in ?
Given this HTML structure:
Which CSS selector will style only the paragraph inside the?
<section>
<article>
<p>Text 1</p>
</article>
<p>Text 2</p>
</section>Which CSS selector will style only the paragraph inside the
Attempts:
2 left
💡 Hint
Think about the full path from section to article to paragraph.
✗ Incorrect
The selector 'section article p' targets paragraphs inside articles that are inside sections. 'section > p' targets paragraphs directly inside section, not inside article.
🧠 Conceptual
advancedWhat is the semantic meaning of nesting
Why would a developer nest a
Attempts:
2 left
💡 Hint
Think about how HTML5 elements describe the page structure and help assistive technologies.
✗ Incorrect
Nesting
❓ layout
advancedHow does nesting
elements affect CSS Flexbox layout?
Given this HTML:
With CSS:
Which boxes will be arranged side by side by Flexbox?
<div class="container">
<div class="box">Box 1</div>
<div class="wrapper">
<div class="box">Box 2</div>
</div>
</div>With CSS:
.container { display: flex; }Which boxes will be arranged side by side by Flexbox?
HTML
<div class="container"> <div class="box">Box 1</div> <div class="wrapper"> <div class="box">Box 2</div> </div> </div>
Attempts:
2 left
💡 Hint
Flexbox arranges direct children of the flex container only.
✗ Incorrect
Flexbox applies only to direct children of the container. 'Box 1' and 'wrapper' are direct children; 'Box 2' is nested inside 'wrapper' and not a flex item.
❓ accessibility
expertWhich nested HTML structure best supports screen reader navigation?
Choose the HTML snippet that uses nested semantic elements correctly to help screen readers understand page sections and navigation.
Attempts:
2 left
💡 Hint
Screen readers rely on semantic tags and ARIA labels to understand page structure.
✗ Incorrect
Option C uses semantic elements ,
Practice
1. What does it mean to have
nested elements in HTML?easy
Solution
Step 1: Understand the meaning of nested elements
Nested elements mean placing one HTML tag inside another to organize content.Step 2: Compare options with this meaning
Only Putting one HTML tag inside another tag describes putting one tag inside another, which matches nested elements.Final Answer:
Putting one HTML tag inside another tag -> Option AQuick Check:
Nested elements = tags inside tags [OK]
Hint: Nested means inside another tag, like boxes inside boxes [OK]
Common Mistakes:
- Confusing nesting with styling
- Thinking nesting means missing closing tags
- Assuming nesting means one tag per page
2. Which of the following is the correct way to nest elements in HTML?
easy
Solution
Step 1: Check tag order and closing
Correct nesting means tags open and close in order: parent opens, child opens, child closes, parent closes.Step 2: Validate each option
Text
follows correct order: <div> <p> Text </p> </div>. Others have mismatched or missing closing tags.Final Answer:
<div><p>Text</p></div> -> Option BQuick Check:
Tags must close in reverse order of opening [OK]
Hint: Tags must close in reverse order they open [OK]
Common Mistakes:
- Closing parent before child
- Swapping tag order
- Forgetting closing tags
3. What will the browser display for this HTML code?
<div>Hello <strong>World</strong>!</div>
medium
Solution
Step 1: Identify nested tags and their effect
The <strong> tag inside <div> makes the word 'World' bold.Step 2: Understand browser rendering
Browser shows 'Hello ' normal, 'World' bold, and '!' normal, all inside a block.Final Answer:
Hello World! (with 'World' bolded) -> Option AQuick Check:
<strong> makes text bold inside parent [OK]
Hint: Tags inside text change style of that part only [OK]
Common Mistakes:
- Thinking tags show as text
- Ignoring effect of <strong>
- Assuming error due to nesting
4. Find the error in this nested HTML snippet:
<ul> <li>Item 1 <li>Item 2</li> </ul>
medium
Solution
Step 1: Check each list item tag
The first <li> tag has no closing </li> before the second <li> starts.Step 2: Confirm proper list structure
Each <li> must be closed inside <ul>. Missing closing tag causes invalid HTML.Final Answer:
Missing closing tag for first <li> -> Option DQuick Check:
Every <li> needs a matching </li> [OK]
Hint: Close each list item before starting next [OK]
Common Mistakes:
- Assuming <li> auto-closes
- Confusing <ul> and <li> roles
- Ignoring missing closing tags
5. You want to create a navigation menu with nested submenus using HTML. Which structure correctly nests a submenu inside a main menu item?
hard
Solution
Step 1: Understand submenu nesting
A submenu is a <ul> inside a <li> of the main menu to group related items.Step 2: Check each option's structure
nests <ul> with 'Team' and 'History' inside the 'About' <li>, which is correct. Others break nesting rules or place <ul> outside <li>.Final Answer:
<nav><ul><li>Home</li><li>About<ul><li>Team</li><li>History</li></ul></li><li>Contact</li></ul></nav> -> Option CQuick Check:
Submenu <ul> inside <li> = correct nesting [OK]
Hint: Put submenu <ul> inside main menu <li> [OK]
Common Mistakes:
- Placing submenu <ul> outside <li>
- Not closing <li> before submenu
- Mixing order of <ul> and <li>
Recommended
Ready to prove it?
Pass the test and this pattern moves unknown
10 questions ~5 mineasy hard
