XHTML Best Practices Guide
Advertisement
Ad
XHTML Best Practices
Whether maintaining legacy XHTML or applying its discipline to HTML5, these practices keep your markup clean and valid.
Core Practices
- Always close tags, including self-closing ones (
<br />). - Use lowercase for all tags and attributes.
- Quote every attribute value.
- Nest elements correctly.
- Provide
alton every image.
Encode Special Characters
& for &
< for <
> for >
Validate Often
Use the W3C Markup Validator to catch errors early. Valid markup renders consistently across browsers.
Separate Concerns
Keep structure in XHTML, styling in CSS, and behaviour in JavaScript — never mix inline styles or scripts.
FAQs
Do these apply to HTML5?
Most are good HTML5 habits too, even though HTML5 is more lenient. More in our XHTML guides.
Why validate?
Invalid markup causes inconsistent rendering and accessibility problems.
