Skip to content

Good Practices

Whether you are a beginner or an experienced developer, following HTML best practices helps keep documents readable, maintainable, accessible, and consistent across projects. A well-structured HTML document improves collaboration, scalability, and long-term maintenance.


Always include the standard document structure elements: doctype, html, head, and body. While browsers may still render pages without them, missing structure can cause inconsistent behavior across browsers and tools.

Every HTML document must start with a doctype declaration. This tells the browser which standards to use when rendering the page and ensures consistent behavior.


Always specify the language of the document using the lang attribute on the html tag. This improves accessibility, SEO, and helps screen readers and search engines correctly interpret the content.

Make websites usable by as many people as possible, regardless of their abilities or disabilities. This includes people with visual, auditory, motor, or cognitive impairments.


  • Use anchor (a) elements for navigation, linking to other pages, downloading files, or scrolling to sections.
  • Use button (button) elements for actions that trigger interactions such as opening menus, submitting forms, or triggering JavaScript behavior.
  • Internal links should generally open in the same tab.
  • External links should open in a new tab. When a link opens in a new tab, always include rel=”noopener noreferrer” attributes to prevent security and performance issues.

Inline styles make code harder to maintain and scale. Keep styling in external stylesheets and separate presentation from structure.

Group styles and scripts by purpose and maintain a consistent order. Avoid mixing CSS and JavaScript imports unnecessarily.


  • Use double quotes consistently.
  • Avoid unnecessary spaces inside attributes or tags.
  • Group related attributes together and avoid mixing custom attributes with native ones.

Always write HTML tags and attributes in lowercase. This improves readability and consistency across the codebase.

Indentation is not required for browsers, but it is essential for human readability. Proper indentation makes the document hierarchy easier to understand and maintain.


  • Use span elements only when no semantic alternative exists.
  • Avoid using br elements for layout or spacing; use CSS instead.

Knowledge Check

Test your understanding of this section

Loading questions...