Good HTML is not about knowing every element. It is about building habits that keep your pages clear and dependable.
Document
- Always start with
<!DOCTYPE html>and alangon<html>. - Include
charsetandviewportmeta tags and a uniquetitle. - Save files as UTF-8.
Elements
- Use the element that matches the meaning: headings for headings,
buttonfor buttons, lists for lists. - Close elements and nest them correctly.
- Prefer semantic elements over
divandspan.
Style and scripts
- Keep styles in a stylesheet, not in
styleattributes. - Load scripts with
defer, or put them at the end of the body.
Content
- Write
alttext, oralt=""for decoration. - Use one
h1and keep the heading order. - Give each form field a label.
- Write link text that makes sense alone.
Code style
- Use lowercase tags and attribute names.
- Quote attribute values.
- Indent two spaces per level.
- Keep one idea per line when it improves reading.
- Choose clear names for
idandclass, based on purpose.
<article class="book-card">
<h2>The Slow Garden</h2>
<p>A quiet novel about a neighbourhood plot.</p>
<a href="/books/the-slow-garden">Read more about The Slow Garden</a>
</article>