There are many ways you can write your code better so without many comments your code looks fine and explain itself to others without any hassle.
When you write your own code for you this is much easy for you to understand how this code is going on and which section is doing what? But when someone else has to edit your code they can be in a mess if you have not followed good practice for coding.
So to write code in better way few things you have to follow.
First of all whenever you start a tag close that on same time and then give line breaks inside and start typing inner tags. Like when you start <html> end it immediately so you don’t need to remember what needs to be closed and you don’t forget. Write like <html></html> then give line breaks inside this tag and type inner tags but close them immediately as you start them as well. Same for brackets if you are doing any programming code and starting an if statement if() {} start brackets and close them immediately and start writing inside them so you don’t forget which bracket needs to be closed.
In html when you are giving names to classes and ids those should be self explainers like for content wrapper div your class name should be class=”contentWrapper” see first word’s first letter is small and second word’s first letter is capital when you close its div like <div class=”contentWrapper”></div> give a comment there which tell code readers cotnentWrapper div is closed here like <div class=”contentWrapper”></div><!—contentWrapper- ->
Remember you should write code so this can be re useable. Lets talk about CSS code as you know default styles for all tags like body, headings, paragraphs, unordered lists we define them in CSS with 0 margin and 0 padding by default cause in html they have some padding and margins these type of things you can reuse. You can make classes of float left, with name alignleft, alignright so you can use them again, you can make clearIt class which clear both sides which are floating as well to use again. In HTML you can make copy of header tags which are same in all documents.
Your code should be very clearn, well aligned and with proper names and comments to explain itself better way so one who read your code can understand it. Even you when you code 1000 lines you would not able to understand yourself if you have not aligned your code nicely, named them nicely.
How to write better CSS code?
The CSS code should be on start of document all default tags CSS like, body, headings, paragraphs and other html tags, after that the classes which are repeating in html document, then give comment layout styling and make layout under that then navigation header body content footer and give them comments and their all CSS should come under their comment which can be said their section as well.
Remember in your html document you can repeat classes how many time you want but your ids should not repeat because javaScript use id’s and that can mess. Better way not to repeat id when you need to repeat something use class.