Chapters
HTML Coding Standards
Writing HTML
We loosely follow the Block Element Modifier (BEM) convention here at True Market. It’s a bit ugly, though the benefit is in its intelligibility; as a developer can you understand what’s going on and how layout/components fit together by looking at your code? That’s the benefit of BEM. Here’s a cheatsheet to get you started if you are not familiar with it and here’s a good explanation by Free Code Camp.
The Golden Rule of HTML
Add targetable classes (even if you don’t need to add styles!) to your HTML. Your future self and team will thank you for it later. Otherwise we’ll have to break our workflow just to tweak a layout slightly.
Validation
All HTML pages should be verified against the W3C validator to ensure that the markup is well formed. This in and of itself is not directly indicative of good code, but it helps to weed out problems that are able to be tested via automation. It is no substitute for manual code review.
Attributes and Tags
All tags and attributes must be written in lowercase and surrounded in double or single quotes.
Correct:
Incorect:
Indentation
As with PHP, HTML indentation should always reflect logical structure. Use tabs and not spaces.
When mixing PHP and HTML together, aim to indent HTML blocks once, this will help with readability.
Correct:
This is also accepted:
Incorrect: