HTML Course 17.3 Common markup errors and how to avoid them


17.3 Common Markup Errors and How to Avoid Them

In real-world projects, small markup mistakes can cascade into broken layouts, accessibility gaps, SEO penalties and browser quirks. Below is a list of frequent HTML errors, why they happen and how you can prevent or fix them.

1. Missing or Unclosed Tags

Every opening tag needs a matching closing tag (unless it’s self-closing). Forgetting a closing <p>, <div> or list wrapper can invalidate the entire document.


This paragraph is never closed

  • Item A
  • Item B

This paragraph is properly closed.

  • Item A
  • Item B

2. Improperly Nested Elements

HTML maintains a hierarchy of block-level vs. inline elements. Placing a <div> inside an <a> was invalid until HTML5. Some browsers will auto-move or drop your tags.



  Text here
  
Invalid block inside inline

Text here
Valid block outside span

3. Missing alt Attribute on Images

Images without alt leave screen-reader users blind and trigger validation errors. Always provide meaningful alternative text or an empty string if decorative.





Company Logo
  

4. Duplicate IDs

An id must be unique within the document. Using the same id twice breaks JavaScript selectors and CSS specificity.


First section
Second section
First section
Second section

5. Incorrect Attribute Syntax

Attributes must be quoted and spelled correctly. Missing quotes or typos like srcsett will be ignored by browsers.


Photo



User Photo

  

6. Using Deprecated Tags and Attributes

Tags like <font>, <center> or attributes like bgcolor belong to HTML4 and are removed in modern standards. Use CSS instead.


Important!


Important!
  

7. Not Declaring Character Encoding Early

If you omit the <meta charset> or place it too late, special characters may render as garbage. Always put it at the very top of your <head>.



  Test
  




  
  Test

  

8. Forgotten <title> Element

Every HTML page must have a <title> for SEO and usability. A blank or missing title reduces discoverability.



  




  
  My Awesome App – Dashboard

  

Summary Table of Errors & Solutions

Error Symptoms Fix
Unclosed Tags Layout breaks, DOM shifts Close all opened tags or use validator
Bad Nesting Unexpected rendering, console warnings Follow content model, consult spec
No alt on <img> Accessibility fail, lint errors Add meaningful alt attribute
Duplicate IDs JS selector conflicts Use unique IDs or classes
Deprecated Tags Future incompatibility Replace with CSS/semantic HTML

Always run your code through an HTML validator (e.g. validator.w3.org), employ editor linting plugins and adopt semantic, accessible patterns. This practice prevents regressions, improves maintainability and ensures your markup remains future-proof.


Posted

in

by

Tags:

Comments

Leave a Reply