As a document grows, make its source easy to understand. An HTML comment leaves a note in the source:
<!-- Club introduction -->
<p>New members are welcome.</p>Comments start with <!-- and end with -->. They do not appear as page content, but visitors can still read them in the source. Never put secrets or private information in comments. You can temporarily comment out markup; do not nest comments inside other comments.
Indentation is for the reader
We usually indent nested elements by two spaces. A p inside body is indented one level further than body. This makes relationships visible but does not replace correct closing tags.
In normal HTML text, consecutive whitespace characters and source line breaks usually collapse into one space. Two source lines do not necessarily become two visible lines. Use separate p elements for separate paragraphs, or br for a meaningful line break within one paragraph. CSS will later control layout and spacing.
Display the characters of a tag
Writing <p> directly creates markup. To display its brackets, use character references: < for less-than, > for greater-than and & for an ampersand. Each starts with & and ends with a semicolon.
<p>A paragraph starts with <p>.</p>
<p>Tea & books</p>The browser displays the tag characters as text; it does not parse those displayed characters again as a new element.
Compare indented and compact code in the Lab. Their page structure is the same. Add a comment, check that it is absent from the page, then use character references to show literal tag characters. You now have the syntax foundation needed for the following HTML chapters.
Page experiment: Comments and code formatting
Compare the examples, then change one part of the HTML using the observation prompt. Compare the source with the real rendered page.
The comment is hidden; character references become visible text. Extra indentation does not change paragraph structure.
The preview uses native browser headings, paragraphs and form controls. Switching examples replaces your edits; Reset lab restores the initial state. Follow in-page links, type and select options. This practice preview does not send form data or run scripts. To try locally, save the complete code as index.html and open it in a browser.
KNOWLEDGE QUIZ
Build it yourself: Comments and code formatting
Create index.html, write a complete page using the requirements below, then save and open it in a browser. Interact with the page to check it. The reference is one possible implementation; wording may differ.
- Write a document with a comment labeling the introduction, one heading and one paragraph.
- Display “Use <p> for a paragraph.” in the paragraph, and indent body contents consistently.