Even experienced developers fall into bad habits when coding in HTML. A single missing alt attribute, an overused <div>, or a deprecated tag can quietly harm your site’s accessibility, SEO rankings, and page performance. With over 94% of websites now running on HTML5 (W3Techs, 2025), the standards are clear — yet the 2025 WebAIM Million report found that 94.8% of the top one million homepages still have detectable accessibility failures. Many of these errors trace back to preventable HTML mistakes. This guide covers ten critical things to avoid when coding in HTML, complete with code examples, real-world impact, and modern alternatives that will keep your markup clean, accessible, and search-engine friendly.
Table of Contents
1. Using Deprecated HTML Elements
Deprecated HTML elements like <font>, <center>, <marquee>, and <strike> were removed from the HTML5 specification for good reason. Modern browsers may still render them, but they produce invalid markup, confuse screen readers, and signal to search engines that your code is outdated. When coding in HTML, always replace these legacy tags with their CSS equivalents.
What not to do:
<font color="red" size="5">Warning!</font> <center>Centered content</center> <strike>Old price: $49.99</strike>
The modern approach:
<p class="warning-text">Warning!</p> <div class="text-center">Centered content</div> <del>Old price: $49.99</del>
.warning-text {
color: red;
font-size: 1.5rem;
}
.text-center {
text-align: center;
}
The <del> element is the semantic replacement for <strike> — it conveys meaning to assistive technologies by indicating that text has been deleted or is no longer accurate. Always separate presentation (CSS) from structure (HTML) to keep your codebase maintainable and standards-compliant. You can quickly validate your markup using the W3C Markup Validation Service.
2. Relying on Inline Styles Instead of External CSS
Inline styles — added directly to HTML elements via the style attribute — may seem like a quick fix, but they create serious problems at scale. They override external stylesheets, make global design changes tedious, bloat your HTML file size, and violate the principle of separation of concerns. When coding in HTML, keeping your styles in an external CSS file is a fundamental best practice.
What not to do:
<div style="float:left; margin:10px; padding:15px; background-color:#f0f0f0; border:1px solid #ccc;"> <p style="font-size:14px; color:#333; line-height:1.6;">Card content</p> </div>
The modern approach:
<div class="card"> <p class="card-content">Card content</p> </div>
.card {
float: left;
margin: 10px;
padding: 15px;
background-color: #f0f0f0;
border: 1px solid #ccc;
}
.card-content {
font-size: 14px;
color: #333;
line-height: 1.6;
}
By using external stylesheets, you gain browser caching (the CSS file loads once and is reused across pages), easier maintenance, and the ability to update your entire site’s look from a single file. Tools like our CSS Beautifier can help you keep your stylesheets organized and readable.
3. Using Tables for Page Layout
Using <table> elements for page layout is a relic of 1990s web development. Tables were designed for tabular data — think spreadsheets, comparison charts, and data grids. When used for layout, they confuse screen readers (which announce table structures row by row), produce bloated HTML, and make responsive design nearly impossible. The 2025 WebAIM Million report found that only 16.6% of tables on the web had valid data table markup, suggesting widespread misuse of the element.
What not to do:
<table>
<tr>
<td>Sidebar navigation</td>
<td>Main content area</td>
<td>Right sidebar</td>
</tr>
</table>
The modern approach using CSS Grid:
<div class="page-layout"> <aside class="sidebar">Sidebar navigation</aside> <main>Main content area</main> <aside class="sidebar-right">Right sidebar</aside> </div>
.page-layout {
display: grid;
grid-template-columns: 200px 1fr 200px;
gap: 20px;
}
@media (max-width: 768px) {
.page-layout {
grid-template-columns: 1fr;
}
}
CSS Grid and Flexbox give you complete control over layout while keeping your HTML semantic and accessible. Reserve <table> exclusively for presenting actual data. If you need to create data tables, our HTML Table Generator can help you build properly structured, accessible tables quickly.
4. Ignoring Semantic HTML Elements
HTML5 introduced a set of semantic elements — <header>, <nav>, <main>, <article>, <section>, <aside>, and <footer> — that clearly communicate the purpose of content to browsers, search engines, and assistive technologies. Yet a 2025 survey by W3Techs found that only about 23% of websites fully implement the <main> tag. Relying on generic <div> elements for everything deprives your pages of structural meaning.
What not to do:
<div id="header">Site Header</div> <div id="nav">Navigation</div> <div id="content">Main Content</div> <div id="sidebar">Sidebar</div> <div id="footer">Footer</div>
The modern approach:
<header>Site Header</header> <nav>Navigation</nav> <main> <article>Main Content</article> </main> <aside>Sidebar</aside> <footer>Footer</footer>
Semantic markup provides several tangible benefits. Search engines use these elements to better understand content hierarchy and relevance, with studies showing a 15–20% improvement in crawl efficiency when proper semantic structure is applied (MoldStud, 2025). Screen readers use semantic landmarks to help users navigate directly to the content they need. And for developers, semantic HTML is simply easier to read and maintain than a wall of nested <div> elements. For a deeper understanding of how structure affects your pages, explore our guide on HTML editors and best practices.
5. Omitting Alt Attributes on Images
Missing image alt text is one of the most common accessibility failures on the web. The 2025 WebAIM Million report found that 42.3% of images across the top million websites lacked proper alternative text. Alt attributes serve multiple purposes: they describe images for screen reader users, appear as fallback text when images fail to load, and help search engines understand visual content for image search rankings.
What not to do:
<img src="dashboard-screenshot.png"> <img src="hero-banner.jpg" alt=""> <!-- Empty alt on a meaningful image -->
The correct approach:
<!-- Meaningful image: describe what the image conveys --> <img src="dashboard-screenshot.png" alt="Analytics dashboard showing monthly traffic trends and conversion rates"> <!-- Decorative image: use an empty alt to hide from screen readers --> <img src="decorative-border.svg" alt="" role="presentation">
The key distinction is intent. If an image conveys information or context, the alt text should describe that information concisely. If the image is purely decorative (a background pattern or divider line), use an empty alt="" so screen readers skip it entirely. When coding in HTML, always include the alt attribute — even if it is intentionally empty for decorative images.
6. Skipping the DOCTYPE Declaration and Proper Document Structure
Every HTML document should begin with <!DOCTYPE html>. Without it, browsers fall into “quirks mode,” rendering your page using legacy, unpredictable layout algorithms. This can cause inconsistent styling, broken layouts, and harder-to-debug issues across different browsers. Proper document structure also includes the lang attribute on the <html> tag, a complete <head> section with character encoding, and a <body> element.
A properly structured HTML document:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Page Title — Brand Name</title> <meta name="description" content="A concise description of the page content."> <link rel="stylesheet" href="styles.css"> </head> <body> <!-- Page content here --> </body> </html>
The lang attribute is especially important for accessibility. It tells screen readers which language to use for pronunciation, and it helps search engines index your content for the right audience. The WebAIM Million report flagged missing document language as one of the six most common WCAG failures, affecting roughly 17% of pages tested. This is a small addition that prevents a significant category of errors.
7. Excessive Nesting and Div Soup
“Div soup” is the informal term for HTML that relies on deeply nested <div> elements instead of meaningful, semantic tags. This pattern increases DOM complexity, slows down browser rendering, makes CSS targeting more difficult, and hinders readability for both developers and machines. Accessibility experts recommend keeping nesting depth to a maximum of three to four levels for main content areas to maintain semantic clarity.
What not to do:
<div class="outer-wrapper">
<div class="inner-wrapper">
<div class="content-wrapper">
<div class="text-wrapper">
<div class="paragraph-wrapper">
<p>Finally, the actual content.</p>
</div>
</div>
</div>
</div>
</div>
A cleaner approach:
<section class="content"> <p>The actual content — no unnecessary wrappers.</p> </section>
Before adding another <div>, ask yourself two questions: Does this element need to exist for styling or layout purposes? Is there a semantic element that better describes this content? If the answer to both is no, remove it. Using our HTML Beautifier can help you visualize your nesting depth and spot unnecessary wrapper elements.
8. Missing Form Labels and Poor Form Accessibility
Forms are one of the most interactive elements on any website, and they are also one of the most common sources of accessibility failures. The 2025 WebAIM report found that 54.2% of forms across the top million websites had missing input labels. Without proper <label> elements, screen reader users cannot determine what information a field expects, and all users lose the ability to click the label to focus the input.
What not to do:
<input type="text" placeholder="Enter your email"> <input type="password" placeholder="Password">
The accessible approach:
<form> <label for="email">Email Address</label> <input type="email" id="email" name="email" required autocomplete="email"> <label for="password">Password</label> <input type="password" id="password" name="password" required autocomplete="current-password"> <button type="submit">Sign In</button> </form>
Notice the use of proper type attributes (email, password), the autocomplete attribute for browser autofill support, and the required attribute for built-in HTML validation. Placeholder text is not a substitute for labels — it disappears as soon as the user starts typing, leaving them with no context. When coding in HTML forms, always pair every input with an explicit label.
9. Ignoring Performance-Related HTML Attributes
HTML offers several built-in attributes that directly impact page speed and Core Web Vitals — the metrics Google uses as a ranking signal. According to the HTTP Archive CrUX Report (October 2025), only 49.7% of mobile websites pass all three Core Web Vitals assessments. Many of these failures could be improved by using native HTML performance features correctly.
Key performance attributes to use:
<!-- Lazy load offscreen images to improve LCP --> <img src="photo.webp" alt="Product photo" loading="lazy" width="800" height="600"> <!-- Always set width and height to prevent layout shift (CLS) --> <img src="hero.webp" alt="Hero banner" width="1200" height="400"> <!-- Preload critical resources --> <link rel="preload" href="critical-font.woff2" as="font" type="font/woff2" crossorigin> <!-- Defer non-critical JavaScript --> <script src="analytics.js" defer></script> <!-- Use async for independent scripts --> <script src="widget.js" async></script>
The loading="lazy" attribute is natively supported in all modern browsers and tells the browser to defer loading offscreen images until the user scrolls near them. Always include explicit width and height attributes on images and videos to prevent Cumulative Layout Shift (CLS). Using defer or async on script tags prevents JavaScript from blocking page rendering, directly improving Largest Contentful Paint (LCP) and Interaction to Next Paint (INP). For tips on minifying your HTML to reduce file size, try our free tool.
10. Using Browser-Specific or Non-Standard Features
Vendor-prefixed CSS properties (like -webkit- or -moz-) and browser-specific HTML attributes may work in one browser but fail silently in others. Relying on them without fallbacks creates an inconsistent experience for your users. While some prefixes were necessary during the early days of CSS3, most modern features are now standardized and supported across all major browsers.
Best practices for cross-browser compatibility:
- Check Can I Use before using new HTML or CSS features to verify browser support levels.
- Always provide standard properties alongside any vendor prefixes, and place the standard property last so it takes priority when supported.
- Test your pages across Chrome, Firefox, Safari, and Edge — and do not forget mobile browsers.
- Use feature detection (such as
@supportsin CSS) rather than browser detection to apply progressive enhancements. - Run your HTML through a validator to catch non-standard attributes and elements.
Writing standards-compliant HTML ensures that your pages render consistently for the broadest possible audience. When coding in HTML, always prioritize cross-browser compatibility and progressive enhancement over shortcuts that only work in a single rendering engine.
Quick Reference: Common HTML Mistakes vs. Modern Solutions
| Common Mistake | Why It Matters | Modern Solution |
|---|---|---|
Using <font>, <center>, <marquee> | Invalid HTML5, accessibility barriers | CSS for all presentation |
| Inline styles on elements | Unmaintainable, no caching, specificity conflicts | External or embedded stylesheets |
| Tables for page layout | Breaks screen readers, no responsive support | CSS Grid and Flexbox |
Generic <div> for everything | No semantic meaning for bots or assistive tech | Semantic elements: <header>, <main>, <article> |
| Missing image alt text | WCAG violation, poor SEO for image search | Descriptive alt attributes on all images |
| No DOCTYPE or lang attribute | Quirks mode rendering, screen reader errors | <!DOCTYPE html> + lang="en" |
| Deeply nested divs | Slow rendering, hard to maintain | Flat, semantic structures (3–4 levels max) |
| Placeholder-only form inputs | Fails WCAG, frustrates all users | Explicit <label> elements paired with inputs |
| No lazy loading or size attributes | Poor Core Web Vitals, slow page loads | loading="lazy", explicit width/height |
| Browser-specific features | Inconsistent experience, future breakage | Standards-first with progressive enhancement |
How to Catch HTML Errors Before They Go Live
Prevention is always better than debugging in production. Here are the most effective tools and techniques for catching HTML mistakes during development:
W3C Markup Validation Service: The official validator from the World Wide Web Consortium checks your HTML against the current specification and flags deprecated elements, missing attributes, and structural errors. Bookmark validator.w3.org and run every page through it before deployment.
Browser Developer Tools: Chrome, Firefox, Safari, and Edge all include built-in developer tools with an Elements panel for inspecting the DOM, a Console for catching HTML parsing errors, and an Accessibility panel for auditing ARIA roles and landmark regions.
Google Lighthouse: Available in Chrome DevTools and as a command-line tool, Lighthouse audits your page for performance, accessibility, best practices, and SEO — providing actionable recommendations with direct links to documentation.
Linters and IDE Extensions: Tools like HTMLHint, the W3C Web Validator VS Code extension, and ESLint (with HTML plugins) catch errors as you type, preventing mistakes from ever reaching your repository.
You can also use our WYSIWYG HTML Editor to write and preview your HTML in real time, or paste existing code into our HTML Code Editor to quickly spot structural issues.
FAQ: Coding in HTML Best Practices
Why should I avoid deprecated HTML tags if browsers still render them?
While browsers try to maintain backward compatibility, deprecated tags produce invalid HTML5 markup. This hurts your page’s accessibility because screen readers may not interpret them correctly, and it signals to search engines that your code is outdated. Deprecated elements can also be removed from future browser versions without warning, potentially breaking your pages.
Are inline styles ever acceptable when coding in HTML?
There are a few limited situations where inline styles make sense: dynamically generated styles from JavaScript (such as positioning a tooltip), HTML email templates (where external CSS support is limited), and one-off overrides during rapid prototyping. For production websites, external stylesheets should handle virtually all styling.
How does semantic HTML improve SEO rankings?
Semantic elements help search engine crawlers understand your content’s structure and hierarchy. When you use <article>, <nav>, <header>, and <main>, crawlers can efficiently identify your primary content versus navigation, sidebars, and footers. Research suggests that pages with proper semantic structure see up to 15–20% better crawl efficiency (MoldStud, 2025), which can translate to faster indexing and improved rankings.
What makes a good alt text for images?
Good alt text is concise (typically under 125 characters), descriptive of the image’s content and function, and avoids redundant phrases like “image of” or “picture of” (screen readers already announce the element as an image). For complex images like charts or infographics, provide a brief summary in the alt text and a longer description nearby or via an aria-describedby attribute.
How does HTML structure affect Core Web Vitals?
HTML directly impacts all three Core Web Vitals. Missing width and height attributes on images cause Cumulative Layout Shift (CLS). Render-blocking scripts without defer or async attributes slow Largest Contentful Paint (LCP). An excessively deep DOM with thousands of elements increases Interaction to Next Paint (INP) because the browser must traverse more nodes to process user interactions.
How can I validate my HTML for errors?
Use the W3C Markup Validation Service to check your pages against current standards. You can validate by URL, file upload, or direct code input. Google Lighthouse (built into Chrome DevTools) also flags accessibility and best-practice HTML issues. For real-time validation as you code, use IDE extensions like HTMLHint or the W3C Web Validator plugin for VS Code.
When should I use a div versus a section or article element?
Use <section> for thematic groupings of content that share a heading (like chapters or tabbed content areas). Use <article> for self-contained content that could be independently distributed — blog posts, news articles, or product cards. Use <div> only when no semantic element fits and you need a generic container for styling or scripting purposes. When in doubt, choose the semantic option.
What is WCAG compliance and why does it matter for HTML?
The Web Content Accessibility Guidelines (WCAG) are the global standard for web accessibility. The current version, WCAG 2.2 (released October 2023), defines success criteria for making web content perceivable, operable, understandable, and robust. With the European Accessibility Act in effect since June 2025 and ongoing ADA litigation in the United States, WCAG compliance is increasingly a legal requirement — not just a best practice. Proper HTML structure (semantic elements, form labels, alt text, heading hierarchy) forms the foundation of WCAG compliance.
Write Cleaner HTML Starting Today
Avoiding these ten common mistakes will make a measurable difference in your website’s accessibility, search performance, and code maintainability. The good news is that every fix on this list is straightforward — you do not need a framework or a build tool to write clean, semantic, standards-compliant HTML.
Start by running your current pages through the W3C Validator and a Lighthouse audit. Replace deprecated elements, add missing alt text and form labels, switch to semantic elements, and include performance attributes like loading="lazy" and explicit image dimensions. These changes take minutes per page but yield lasting improvements in both user experience and search visibility.
For hands-on practice and instant feedback, try our online WYSIWYG HTML Editor to write and preview coding in HTML in real time. Pair it with our HTML Code Editor for full syntax highlighting, and use the HTML Beautifier to clean up your output before deploying to production.
Related reading:
- HTML Editors: A Comprehensive Guide
- Why is WYSIWYG Important?
- The Importance of CSS in Web Development: Using an Online CSS Editor
- Design Your Blog Easily: The Best Online HTML Editors To Use
Sources: WebAIM Million Report (February 2025), W3Techs HTML5 Usage Statistics (2025), MoldStud Research on Semantic HTML (October 2025), HTTP Archive CrUX Report (October 2025), W3C WCAG 2.2 Specification (October 2023), DebugBear 2025 Web Performance Review (December 2025).

