Blog

  • Ten Principles For Clean HTML Code

    Posted by Rajan Rawat | Last Updated: 30-Apr-18

    Ten Principles For Clean HTML Code

    HTML is base and the foundation of a webpage or website. Whenever I tell the developers about the CSS, I always tell them you should write the good HTML before the case. Because if the foundation is strong automatically the house will be strong. So always write the clean HTML code with the help of semantics.

    Now I am going to share with you some important point that will help you to make your code clean and tidy

     

    1. Use Strict DOCTYPE


    Whenever i write my HTML code i always use <!DOCTYPE> declaration before HTML tag. <!DOCTYPE> is not a HTML tag but i will help the browser to detect HTML version that written in the code

     

    2. Encoding characters & Character set

     
    In our <head> we use the character set UTF-8 and this first we must declare in out web-page, but this is declared after the title. Because with the help of this our browser detects any funny character if we use in the web-page

     

    3. Indentation should be proper


    Many of the developers are not aware of coding style and the syntax of HTML . Always the make the code tidy as much as possible and well-formed. I recommend you being consistent with your approach whatever you are using and because a well-written code is very easy to understand to other developers as well.

     

    4. JavaScript and CSS must be external


    Always import youCss and javascript file externally

    <link href="mystyle.css" rel="stylesheet" type="text/css">

     

    5. Always nest your tags properly

     

     

    As the per the norms always make your clean and nest your tags proper make the code like that, so it is easy to understand the other developers where the tag is starting and where the tag is closing

     

    6. Eliminate all the unnecessary divs in code

     

    Most of the developers wrap the Underorder list in the div tag which makes no sense. My opinions is to refuse the overuse of div tags in the HTML code. You must know about the element before wrapping into the div tag

     

    7. Better naming conventions for classes and id

     

    Always use the classes which relevant to the element or easy to recognize like for side bar use class sidebar

     

    8. Do the typography always in CSS 

     

    Typography means like if you change the case text "home" use CSS text- transform property for don't do it like "HOME" in HTML code

     

    9. Validation 

     

    Whenever you are the writing the code make sue that your code always go through a validator to find out minor mistakes

     

    10. Classes and id

     

    Always write the CSS the use the parent class or id to make easy to understand make the CSS unique for every element

Tags: html