Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to HTML Notes
Topic #106

HTML Syntax Basics

HTML syntax comes down to a small set of consistent rules: elements are made of tags, tags can carry attributes, and elements nest inside each other in a strict, closable order.

Anatomy of an Element

<a href="https://codingnowai.in" target="_blank">Visit CodingNow</a>
PartExample
Opening tag<a href="..." target="_blank">
Attributeshref="...", target="_blank"
ContentVisit CodingNow
Closing tag</a>

Nesting Must Be Properly Closed

<!-- Correct: tags close in reverse order of opening -->
<p>This is <strong>important <em>text</em></strong>.</p>

<!-- Incorrect: overlapping tags -->
<p>This is <strong>important <em>text</strong></em>.</p>

The second example is invalid — <em> opened after <strong>, so it must close before <strong> closes. Browsers will often try to recover from this, but the result can be unpredictable.

Void (Self-Closing) Elements

Some elements never have content or a closing tag — <img>, <br>, <hr>, <input>, <meta>, <link>:

<img src="photo.jpg" alt="A student coding">
<br>
<hr>

Case Sensitivity

Tag and attribute names are case-insensitive in HTML5 (<DIV> and <div> both work), but lowercase is the universal convention and what every style guide expects.

Common Mistakes

  • Overlapping tags instead of properly nested ones (see example above)
  • Forgetting to close a tag that requires closing (like <div> or <p>), which can silently break the layout of everything after it
  • Writing a closing slash on void elements out of habit (<img ... />) — harmless in HTML5, but unnecessary

Interview Relevance

Spotting invalid/overlapping markup in a code review question is a common practical test — practice reading nested tags and identifying exactly where they should close.

Practice Question

Find and fix the error: <p>Click <a href="#">here</p></a>

Related HTML Notes

Want to go beyond the notes?

Join CodingNow's HTML course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →