This HTML page uses proper indentation to show the structure clearly. The <article> is inside the <section>, and the heading and paragraph are inside the article.
HTML
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<title>Proper Indentation Example</title>
</head>
<body>
<section>
<article>
<h1>Welcome</h1>
<p>This paragraph is inside an article, which is inside a section.</p>
</article>
</section>
</body>
</html>
OutputSuccess
Important Notes
Consistent indentation makes your code easier to maintain and understand.
Most code editors can auto-indent your code to save time.
Proper indentation does not affect how the webpage looks but helps with code clarity.
Summary
Indent nested HTML elements to show their relationship.
Use spaces consistently for indentation, not tabs mixed with spaces.
Proper indentation helps you and others read and maintain code easily.
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
Step 1: Understand the role of indentation
Indentation organizes code visually but does not affect browser rendering.
Step 2: Identify the main benefit
Proper indentation helps developers read and maintain the code easily.
Final Answer:
It helps make the code easier to read and understand. -> Option C
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
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.
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.