Here are some best practices in HTML and CSS coding settled out in everyday's life. All this may to feel trivial and so elementary. From the other hand, there are hard core programmers who haven't had any contact with the front end stuff previously. They want to hear about some basic rules. Without any reasoning what and why.
Do not nest inside <p> element other block level elements like <p> or <div>.
It's OK to nest inside <p> inline elements like <span> <em> <strong>.
Do not nest inside <ul> or <ol> elements anything other than <li> elements.
It's OK to nest inside <li> element other elements like <p> <div> <span> <em> <strong>.
Do not nest inside <a> element other <a> elements or block level elements like <p> or <div>.
Keep the whole <a> element - start tag, content and end tag, on one line.
Keep the whole <span> element - start tag, content and end tag, on one line.
No line breaks in inline elements.
No line breaks inside attribute declarations.
In empty elements (element without a closing tag) leave 1 space before the closing slash. Like <br /> <img /> <input />.
Do not leave inside tags any loose quotation marks or any other characters.
Replace special characters with HTML entities, like "&" is "&" and ">" is ">" and "£" is "£" etc. Encouraged - learn and use numeric values instead on alphabetic aliases.
Allow common sense and exceptions.
Free-flow vs float:
Positioning through floated divs. Apply to elements:
float:[left][right]; width:[auto][100%][px];
Float requires a width declared, always. If no width is set, the results can be unpredictable.
Prefer unique class names over generic and universal ones. Use camelCase. Think of hierarchy.
Prefer classes in styling.
Prefer identifiers (id) in scripting.
To make the CSS more readable, each selector has to have it's own set of declarations. Do not bundle selectors.
To make the CSS more readable, put on each line only one declaration.
Arrange attributes in tags, and properties in selectors, alphabetically.
Insert new bits of styling in the beginning of the style sheet, right after the defaults. So the new declarations can't override and change previous styling elsewhere.
Syling of basic elements <p> <ul> <table> etc. is used for
Styling through classes is used for
<span> elements through classes are used to style
<div> elements through classes are used for
Starting with a new website, there are four steps in setting up a style sheet.
Sounds like banging up, but over again, avoid generic class names like "label". On a medium website there are 58 totally different in appearance items that can be named semantically a "label". Use unique names as much as possible. The "commentLabel" and "commentorLabel" and productLabel are still semantic.
Do not use in file names spaces and/or upper-case letters, even not in the names of images.
Do not style HTML elements for individual bahavior, like a{font-size:1em;}.