How to Fix the 10 Most Common HTML Errors
Source: Dev.to
1. Missing alt attribute on “
Every “ needs an alt attribute. Screen readers depend on it, and Google Images indexes it. It’s the #1 accessibility violation on the web.
Invalid
Valid
[Image: Mountain landscape at sunset]For decorative images, use alt="".
2. Unclosed tags (or)
A missing closing tag can shift your entire layout. Browsers auto‑close silently, usually incorrectly.
Invalid
Some content
Valid
Some content
3. Deprecated elements (,, “)
These tags still render but signal outdated code.
Deprecated
Hello
Modern
Hello
4. Missing “
Without a proper doctype, browsers enter quirks mode, causing the box model, margins, tables, and other layout aspects to behave differently.
Always start with
…
5. Missing lang attribute on “
Screen readers may pick the wrong pronunciation, and browser translation can break. One attribute fixes it.
Invalid
Correct
6. Duplicate id attributes
getElementById() returns the first match only, causing anchor links to break and confusing screen readers.
Duplicate
Site header
Page headerUnique
Site header
Page header7. Invalid element nesting
cannot contain, and cannot contain. Browsers restructure the DOM silently.
Invalid
This breaks the paragraph
Correct
Paragraph text
Block content
8. Missing viewport meta tag
Without it, mobile browsers render pages at desktop width, preventing responsive CSS from taking effect. Google’s mobile‑first indexing checks for this.
Always include
9. Empty heading tags
An “ (or any heading) with no text breaks the document outline, wastes SEO value, and confuses screen readers.
Empty
##
With content
## Our Features
10. Inline styles instead of CSS classes
Inline styles are a code smell: they can’t be cached, reused, or maintained efficiently.
Avoid
Text
Better
Text
.error-message {
color: red;
font-size: 18px;
margin: 20px 0;
}Additional resources
You can paste your HTML or enter any URL in ValidateHTML; it catches all 10 of these errors automatically, shows line numbers, and gives you a quality score (0‑100 with letter grades). Free, no login required.
For detailed guides on each error with step‑by‑step fixes, see the HTML Errors Guide.