HTML elements have content models: rules about what may appear inside them. For instance, li belongs inside a list, and a p element should contain phrasing content, not a complete section.
What You Need to Know
Browsers may silently rearrange invalid nesting. That can change the DOM and break styling, so structure content according to its meaning.
The goal is not to collect as many tags as possible. Pick the element that best describes what the content really is.
Example: See It in Action
Add this example to the appropriate part of a practice HTML page. Read each line before you open the page in your browser.
This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.
<ul>
<li>First idea</li>
<li>Second idea</li>
</ul>
<p>A list belongs in the right kind of parent.</p>
Let’s Understand the Example
- Ul groups items where the order does not matter.
- Li is one item inside a list. Keep each item inside its parent list.
- A p groups a paragraph of related text. Start another paragraph for a new thought.
You should see distinct list items. Ask whether their order carries meaning: if the order matters, use an ordered list; otherwise use an unordered list.
What Should You See?
The page should include “First idea”. If it looks different from what you expected, open developer tools and compare the source with the elements the browser created.
Try removing one piece of markup in a scratch copy, refresh the page, and compare the behavior. This is often the fastest way to understand what that piece contributes.
Try It Yourself
- Create a list with li children, then explain why li is not a direct child of p.
- Save your changes, open or refresh the page, and compare the result with the original example.
- Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.
Common Beginner Mistakes
- Putting a div or heading inside a paragraph and assuming the paragraph stays open.
- Avoid picking tags just for their default bold, italic or spaced appearance. Use CSS for presentation.
Key Takeaways
- HTML elements have content models: rules about what may appear inside them.
- Ul groups items where the order does not matter.
- Browsers may silently rearrange invalid nesting. That can change the DOM and break styling, so structure content according to its meaning.