0
0
HTMLmarkup~20 mins

Nested elements in HTML - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Nested Elements Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
rendering
intermediate
2:00remaining
What is the visual output of nested
and
elements?
Consider this HTML code snippet:
<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>
AA heading 'Title' followed by two paragraphs: 'Paragraph inside article.' and 'Paragraph inside section but outside article.'
BOnly one paragraph with text 'Paragraph inside section but outside article.' is shown, the article content is hidden.
CTwo headings 'Title' and 'Paragraph inside article.' are shown, but no paragraphs.
DOnly the heading 'Title' is shown, paragraphs are ignored.
Attempts:
2 left
💡 Hint
Remember that nested elements inside
and
are all displayed unless hidden by CSS or scripts.
selector
intermediate
2:00remaining
Which CSS selector targets only paragraphs inside
elements nested in
?
Given this HTML structure:
<section>
  <article>
    <p>Text 1</p>
  </article>
  <p>Text 2</p>
</section>

Which CSS selector will style only the paragraph inside the
?
Asection p
Bsection > p
Carticle > p
Dsection article p
Attempts:
2 left
💡 Hint
Think about the full path from section to article to paragraph.
🧠 Conceptual
advanced
2:00remaining
What is the semantic meaning of nesting
Why would a developer nest a
ATo indicate that the navigation links are part of the page header, helping screen readers and SEO.
BTo hide the navigation from users but keep it in the code.
CTo apply default browser styles that only work when <nav> is inside <header>.
DTo make the navigation appear only on mobile devices automatically.
Attempts:
2 left
💡 Hint
Think about how HTML5 elements describe the page structure and help assistive technologies.
layout
advanced
2:00remaining
How does nesting
elements affect CSS Flexbox layout?
Given this HTML:
<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>
ABoth 'Box 1' and 'Box 2' are flex items arranged side by side directly.
BOnly 'Box 1' and the 'wrapper' div are flex items arranged side by side; 'Box 2' is inside 'wrapper' and not a flex item.
COnly 'Box 2' is arranged by Flexbox; 'Box 1' is ignored.
DNeither box is arranged by Flexbox because nested divs disable flex layout.
Attempts:
2 left
💡 Hint
Flexbox arranges direct children of the flex container only.
accessibility
expert
3:00remaining
Which 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.
A
&lt;nav&gt;
  &lt;header&gt;
    &lt;h1&gt;Main Menu&lt;/h1&gt;
  &lt;/header&gt;
  &lt;ul&gt;
    &lt;li&gt;&lt;a href="#home"&gt;Home&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
&lt;/nav&gt;
&lt;article&gt;
  &lt;h2&gt;Introduction&lt;/h2&gt;
  &lt;p&gt;Welcome text.&lt;/p&gt;
&lt;/article&gt;
B
&lt;div&gt;
  &lt;nav&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href="#home"&gt;Home&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/nav&gt;
  &lt;section&gt;
    &lt;h2&gt;Introduction&lt;/h2&gt;
    &lt;p&gt;Welcome text.&lt;/p&gt;
  &lt;/section&gt;
&lt;/div&gt;
C
&lt;header&gt;
  &lt;nav aria-label="Main navigation"&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href="#home"&gt;Home&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/nav&gt;
&lt;/header&gt;
&lt;main&gt;
  &lt;section aria-labelledby="intro"&gt;
    &lt;h2 id="intro"&gt;Introduction&lt;/h2&gt;
    &lt;p&gt;Welcome text.&lt;/p&gt;
  &lt;/section&gt;
&lt;/main&gt;
D
&lt;header&gt;
  &lt;div&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href="#home"&gt;Home&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
&lt;/header&gt;
&lt;section&gt;
  &lt;h2&gt;Introduction&lt;/h2&gt;
  &lt;p&gt;Welcome text.&lt;/p&gt;
&lt;/section&gt;
Attempts:
2 left
💡 Hint
Screen readers rely on semantic tags and ARIA labels to understand page structure.