Bird
Raised Fist0
HTMLmarkup~10 mins

Proper indentation in HTML - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to properly indent the <h1> tag inside the <header>.

HTML
<header>
[1]<h1>Welcome</h1>
</header>
Drag options to blanks, or click blank then click option'
A(2 spaces)
B(tab)
C(4 spaces)
D(no indent)
Attempts:
3 left
💡 Hint
Common Mistakes
Not indenting at all
Using tabs instead of spaces
2fill in blank
medium

Complete the code to properly indent the <li> elements inside the <ul>.

HTML
<ul>
  [1]<li>Home</li>
  <li>About</li>
</ul>
Drag options to blanks, or click blank then click option'
A(no indent)
B(2 spaces)
C(tab)
D(4 spaces)
Attempts:
3 left
💡 Hint
Common Mistakes
Using only two spaces
Not indenting the first <li> tag
3fill in blank
hard

Fix the error in indentation for the <p> tag inside the <section>.

HTML
<section>
[1]<p>This is a paragraph.</p>
</section>
Drag options to blanks, or click blank then click option'
A(2 spaces)
B(4 spaces)
C(no indent)
D(tab)
Attempts:
3 left
💡 Hint
Common Mistakes
No indentation
Using tabs instead of spaces
4fill in blank
hard

Fill both blanks to properly indent the <nav> and <a> tags inside the <header>.

HTML
<header>
[1]<nav>
[2]<a href="#">Link</a>
  </nav>
</header>
Drag options to blanks, or click blank then click option'
A(2 spaces)
B(4 spaces)
C(tab)
D(no indent)
Attempts:
3 left
💡 Hint
Common Mistakes
Indenting both tags the same amount
Using tabs instead of spaces
5fill in blank
hard

Fill all three blanks to properly indent the <article>, <h2>, and <p> tags.

HTML
<main>
[1]<article>
[2]<h2>Title</h2>
[3]<p>Content here.</p>
  </article>
</main>
Drag options to blanks, or click blank then click option'
A(2 spaces)
B(4 spaces)
C(6 spaces)
D(tab)
Attempts:
3 left
💡 Hint
Common Mistakes
Indenting all tags the same amount
Using tabs instead of spaces

Practice

(1/5)
1. Why is proper indentation important in HTML code?
easy
A. It changes how the webpage looks in the browser.
B. It makes the webpage load faster.
C. It helps make the code easier to read and understand.
D. It is required for the browser to display the page.

Solution

  1. Step 1: Understand the role of indentation

    Indentation organizes code visually but does not affect browser rendering.
  2. Step 2: Identify the main benefit

    Proper indentation helps developers read and maintain the code easily.
  3. Final Answer:

    It helps make the code easier to read and understand. -> Option C
  4. Quick Check:

    Indentation improves readability = B [OK]
Hint: Indent nested tags to show structure clearly [OK]
Common Mistakes:
  • Thinking indentation changes webpage appearance
  • Mixing tabs and spaces causing inconsistent look
  • Ignoring indentation making code hard to read
2. Which of the following HTML snippets shows proper indentation?
easy
A. <div>\n<p>Hello</p>\n</div>
B. <div>\n <p>Hello</p>\n</div>
C. <div>\n <p>Hello</p>\n </div>
D. <div>\n <p>Hello</p>\n </div>

Solution

  1. Step 1: Check indentation consistency

    <div>\n <p>Hello</p>\n</div> uses two spaces to indent the <p> tag inside <div>, showing clear nesting. Closing tag aligns with opening.
  2. Step 2: Compare other options

    B has no indentation for <p>; C incorrectly indents the closing </div> tag with four spaces; D indents both <p> and closing </div> with one space, misaligning the closing tag.
  3. Final Answer:

    <div>\n <p>Hello</p>\n</div> -> Option B
  4. Quick Check:

    Consistent two-space indent = A [OK]
Hint: Indent child tags inside parent tags with consistent spaces [OK]
Common Mistakes:
  • No indentation for nested tags
  • Using inconsistent spaces for indentation
  • Mixing tabs and spaces
3. What will the browser display when rendering this HTML code with proper indentation?
<ul>
  <li>Apple</li>
  <li>Banana</li>
</ul>
medium
A. An error message because of indentation.
B. Plain text showing the tags and words.
C. A numbered list with Apple and Banana.
D. A bulleted list with Apple and Banana items.

Solution

  1. Step 1: Understand HTML list tags

    The <ul> tag creates a bulleted list, and <li> tags are list items.
  2. Step 2: Recognize indentation effect

    Indentation does not affect rendering; it only helps readability.
  3. Final Answer:

    The browser shows a bulleted list with Apple and Banana items. -> Option D
  4. Quick Check:

    <ul> with <li> = bulleted list [OK]
Hint: Indent list items inside <ul> or <ol> tags [OK]
Common Mistakes:
  • Thinking indentation changes list style
  • Confusing <ul> with numbered lists (<ol>)
  • Expecting errors from indentation
4. Find the problem with indentation in this HTML snippet:
<div>
  <p>Welcome</p>
    <span>User</span>
</div>
medium
A. The <span> tag is over-indented compared to <p>.
B. There is no problem; indentation is correct.
C. The closing </div> tag is missing indentation.
D. The <p> tag is not indented inside the <div>.

Solution

  1. Step 1: Compare indentation of sibling tags

    The <p> tag is indented two spaces inside the <div>; <span> is indented four spaces.
  2. Step 2: Identify inconsistency

    Siblings inside <div> should have the same indentation level; here <span> is over-indented.
  3. Final Answer:

    The <span> tag is over-indented compared to <p>. -> Option A
  4. Quick Check:

    Siblings need equal indent = D [OK]
Hint: Indent sibling tags equally inside parent tags [OK]
Common Mistakes:
  • Indenting only some child tags
  • Ignoring sibling indentation consistency
  • Assuming closing tags need indentation
5. You have this HTML code:
<section>
  <article>
    <h2>Title</h2>
  </article>
</section>

How should you indent a new <p> tag inside <article> to keep proper indentation?
hard
A. Indent the <p> tag with 4 spaces inside <article>.
B. Indent the <p> tag with 2 spaces inside <section>.
C. Do not indent the <p> tag; keep it at the same level as <section>.
D. Indent the <p> tag with 1 space inside <article>.

Solution

  1. Step 1: Analyze current indentation levels

    <section> is at 0 spaces, <article> is indented 2 spaces, <h2> inside <article> is indented 4 spaces.
  2. Step 2: Determine correct indent for new <p>

    Since <p> is inside <article>, it should match <h2> indentation, which is 4 spaces.
  3. Final Answer:

    Indent the <p> tag with 4 spaces inside <article>. -> Option A
  4. Quick Check:

    Child tags indent 2 spaces more than parent [OK]
Hint: Indent child tags 2 spaces more than their parent [OK]
Common Mistakes:
  • Indenting less than parent level
  • Indenting siblings inconsistently
  • Using odd number of spaces
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