What does the HTML Syntax Validator & Lint Checker do?
The HTML Syntax Validator & Lint Checker parses HTML code to detect syntax errors, unclosed elements, mismatched closing tags, malformed brackets, and invalid tag names. It provides line-level diagnostics, recognizes all HTML5 void elements, and identifies nesting issues that cause layout breaks and broken DOM trees in web browsers.
Core Concepts
Understanding how browser parsers handle malformed HTML helps debug rendering bugs:
- Unclosed Elements: Browsers attempt error recovery by guessing where unclosed elements end, frequently leading to layout shifts, broken CSS cascading, and corrupted DOM hierarchies.
- HTML5 Void Elements: Tags like
<img>,<input>,<meta>,<hr>,<br>,<link>, and<source>do not require closing tags (</img>). The validator recognizes all standard void tags to avoid false positives. - Quoted Attribute Escaping: Angle brackets (
<and>) inside quoted attributes (e.g.data-template="<span>") are masked during validation to prevent false tag delimiter errors.
How to use the tool?
- Paste HTML Markup: Paste your HTML snippet, template, or full webpage document into the input editor.
- Click Validate HTML Syntax: The validator checks element hierarchies, tag names, and closures across every line.
- Review Diagnostic Results:
- If errors exist, the diagnostic box pinpoints the exact line number and error message for each unclosed or mismatched tag.
- If markup is valid, a green confirmation badge confirms clean syntax.
Related Developer Utilities
If you are writing or formatting HTML and frontend markup, explore these complementary tools:
- HTML Formatter & Beautifier: Indent, clean, and format unaligned HTML markup.
- HTML Minifier: Strip comments and whitespace to optimize production webpage byte size.
- HTML to Markdown Converter: Convert HTML documents and articles into clean GitHub Flavored Markdown.
- HTML Entity Encoder: Convert reserved characters into named and numeric HTML entities.
REST API Integration
Blueutils provides a free REST API endpoint (POST https://blueutils.com/api/html/html-validator) to programmatically validate HTML syntax, detect unclosed tags, and inspect tag nesting errors.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
rawText |
String | Raw HTML markup code payload to validate. | "<div class=\"card\"><h1>Title\n</div>" |
options.checkHtml5Elements |
Boolean | Whether to validate element names against the HTML5 tag specification. Defaults to true. |
true |
options.checkAttributes |
Boolean | Whether to check for common attribute syntax issues. Defaults to true. |
true |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/html/html-validator \
-H "Content-Type: application/json" \
-d '{
"rawText": "<div class=\"card\"><h1>Title\n</div>"
}'Python
import requests
url = "https://blueutils.com/api/html/html-validator"
payload = { "rawText": "<div class=\"card\"><h1>Title\n</div>" }
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String jsonPayload = """
{
"rawText": "<div class=\\"card\\"><h1>Title\\n</div>"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/html/html-validator"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}API Response Parameters
| Name | Type | Description | Example |
|---|---|---|---|
isValid |
Boolean | Indicates whether the HTML syntax is valid. | false |
errorCount |
Integer | Total number of syntax and tag nesting errors detected. | 1 |
errors |
Array | Detailed line-level diagnostic error objects (line, message). |
[{"line": 2, "message": "Unclosed tag <h1> opened on line 2..."}] |
error |
String | Summary error message for quick assertions. | "Unclosed tag <h1> opened on line 2 missing closing </h1> tag." |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"errorCount": 0,
"errors": [],
"error": null
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"errorCount": 1,
"errors": [
{
"line": 2,
"message": "Unclosed tag <h1> opened on line 2 missing closing </h1> tag."
}
],
"error": "Unclosed tag <h1> opened on line 2 missing closing </h1> tag."
}Rate Limit Exceeded Response (HTTP 429 Too Many Requests)
{
"error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}Why use an API to validate HTML syntax?
Integrating the HTML validator API into CI/CD build gates, web crawlers, or headless scrapers provides key advantages:
- Rapid Script Validation: Enables developers and QA engineers to automatically validate server-rendered templates and generated HTML pages before deploying to production.
- Optimized Token Efficiency for AI Agents: Autonomous agents generating HTML components can verify syntax and unclosed tags via API without consuming LLM reasoning tokens on linting passes.
- Deterministic Accuracy Without Hallucinations: Catches missing closing tags and malformed angle brackets deterministically without relying on probabilistic LLM assertions.
Native Usage
How to validate HTML and XML markup syntax locally using terminal tools:
Windows (CMD / PowerShell)
# Validate HTML/XML syntax in PowerShell
try {
[xml]$doc = Get-Content -Path .\index.html -ErrorAction Stop
Write-Output "Valid HTML/XML markup"
} catch {
Write-Output "Syntax Error: $($_.Exception.Message)"
}Linux / Unix (Bash)
# Validate HTML file syntax using xmllint or html5validator
xmllint --html --noout index.htmlPython
Using Python standard library html.parser to validate tag closure:
from html.parser import HTMLParser
class SyntaxValidator(HTMLParser):
def __init__(self):
super().__init__()
self.stack = []
self.void_tags = {'br', 'img', 'input', 'hr', 'meta', 'link'}
def handle_starttag(self, tag, attrs):
if tag not in self.void_tags:
self.stack.append(tag)
def handle_endtag(self, tag):
if self.stack and self.stack[-1] == tag:
self.stack.pop()
validator = SyntaxValidator()
validator.feed('<div class="card"><h1>Title</div>')
if validator.stack:
print(f"Unclosed tags detected: {validator.stack}")
else:
print("HTML syntax is valid.")Java
Using standard Java XML/HTML parsers to validate structure:
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.xml.sax.InputSource;
import java.io.StringReader;
public class HtmlSyntaxCheck {
public static void main(String[] args) {
String html = "<root><div class=\"card\"><h1>Title</h1></div></root>";
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
builder.parse(new InputSource(new StringReader(html)));
System.out.println("Markup syntax is valid!");
} catch (Exception e) {
System.err.println("Syntax Error: " + e.getMessage());
}
}
}