Common HTML Errors & How to Fix Them

Learn about the most frequent HTML mistakes developers make and how to fix them. Use our validator below to check your own code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Ctrl+Enter to validate

The Most Common HTML Errors

1. Unclosed Tags

Every opening tag should have a corresponding closing tag. Unclosed tags can cause content to inherit unexpected styles and break your layout.

Wrong
<p>First paragraph
<p>Second paragraph
Correct
<p>First paragraph</p>
<p>Second paragraph</p>

2. Missing Alt Attributes

The alt attribute is required on all <img> elements. It provides text for screen readers, displays when images fail to load, and helps search engines understand your image content.

Wrong
<img src="hero.jpg">
Correct
<img src="hero.jpg" alt="Mountain landscape at sunset">

3. Deprecated Elements

Elements like <center>, <font>, <big>, <strike>, and <marquee> were deprecated in HTML5. Use CSS for styling instead.

Wrong
<center>Centered text</center>
<font color="red">Red text</font>
Correct
<div style="text-align: center">Centered text</div>
<span style="color: red">Red text</span>

4. Incorrect Tag Nesting

HTML has strict rules about which elements can be nested inside others. Inline elements generally cannot contain block elements.

Wrong
<a href="/"><div>Click me</div></a>
Correct
<a href="/">Click me</a>

5. Missing DOCTYPE

The DOCTYPE declaration tells the browser which version of HTML to use. Without it, browsers enter 'quirks mode' which can cause inconsistent rendering.

Wrong
<html>
<head><title>Page</title></head>
Correct
<!DOCTYPE html>
<html>
<head><title>Page</title></head>

6. Duplicate IDs

Each ID must be unique within a page. Duplicate IDs break JavaScript selectors, cause accessibility issues, and produce invalid HTML.

Wrong
<div id="main">First</div>
<div id="main">Second</div>
Correct
<div id="main">First</div>
<div id="secondary">Second</div>