HTML
Best practices for HTML.
Table of contents
General
Define important document properties
- Doctype - Enforce standards mode and consistent rendering.
- Language - Help search engines, translation tools and speech synthesis tools.
- Character encoding - Ensure proper text rendering.
- Page title - Help humans and bots to understand what the page is about.
Good
Bad
Put stylesheets at the top
Ensure that styles are applied as early as possible during page render by placing all stylesheet links in the <head>
section.
Good
Bad
Put scripts at the bottom
Prevent content being rendered from being blocked by placing all scripts just before the closing </body>
tag.
Good
Bad
Prefer specific elements to generic elements
Less markup, better readability.
Good
Bad
Omit value for boolean attributes
Values for boolean attributes are obsolete and should be omitted.
Good
Bad
Images
- Define width and height - Prevent content from flickering during page load.
- Define alt attribute - Help bots and search engines to properly index images.
Good
Bad