Their are some rules that you have to follow if you want to write a good code in html.
Unless you want to write good code, then you probably should stick to some form of standards.
Rule of tags:
- Tags are always surrounded by angle brackets (less-than/greater-than characters).
- If it is possible make sure that the name of the tages are lower case.
- Most tags come in pairs and surround the material they affect, they work like a light switch: the first tag turns the action on, and the second turns it off
- The second tag--the "off switch"--always starts with a forward slash.
- First tag on, last tag off, tags are embedded, so when you start a tag within another tag, you have to close that inner tag before closing the outer tag
- Many tags have optional attributes that use values to modify the tag's behavior.
The rules of the way that you write your code:
- Write readable yet efficient code.
-
Try to write the best element, for exapmle instead of using a (
<input>) element use (<button>) (button element can have content whereas input can not). - When you write table code make sure that you use the right element.(eg:instead of using summary, use caption)
- For login form code, make sure that you use the best choice (eg: when should you use radio and when should you use button).
- Leave typography to the CSS.
- If avoidable, do not hard-code! (The only things that should be hard-coded are constants. That’s it)
- Write test cases (this will help you a lot)
- Write comments and documentation (commiting your code and providing proper documentation)
- Save and back up your code on some kind of version controle system is a simple way to ensure that your code stays safe.
- Keep your code portable.
- Split your code into short.
- Be consistent!
- Validate your code.
- Make sure that you write a proper indentation.
- Make sure that you set the character properly.
-
Respect syntax and semantics.
- Define a doctype at the top.
- You can not have an end tag without a start tag.
-
Every start tag needs:
- Start with a <
- End with a >
-
Every end tag needs
- Start with a < with /
- Ends with a >
- You should use lower case for element name.
- Should indent child element.
- Nest element properly.