30 tips for compiling HTML code _ HTML/Xhtml _ webpage Creation

Source: Internet
Author: User
This article summarizes 30 guidelines for compiling HTML code. As long as you keep them in mind and use them flexibly, you will surely write beautiful code and enter the ranks of professional developers as soon as possible. 1. Be sure to close the HTML Tag

In the previous page source code, we often see such statements:

  • Some text here.
  • Some new text here.
  • You get the idea.
  • We may have tolerated such non-closed HTML tags in the past, but in today's standards, this is very undesirable and must be completely avoided. Be sure to close your HTML Tag. Otherwise, the verification will fail and some unpredictable problems may occur.

    It is best to use this form:

    
      
      
    • Some text here.
    • Some new text here.
    • You get the idea.
    2. Declare the correct document type (DocType)

    I have previously joined many CSS forums. If a user encounters problems, we recommend that you do two things first:

    • 1. Verify the CSS file to solve all visible errors.
    • 2. Add the Doctype.

    The DOCTYPE Definition tells the browser whether the page contains HTML, XHTML, or both before the HTML Tag appears, so that the browser can correctly parse the tag.

    There are usually four types of documents to choose from:

    1. 2. 3. 4. 

    There are always different statements about the document type declaration to be used. It is generally considered that the strictest statement is the best choice, but research shows that most browsers use a common method to parse such statements, so many people choose to use the HTML4.01 standard. The bottom line for selecting a declaration is whether it is really suitable for you. Therefore, you need to consider the declaration that suits your project.

    3. Do not use embedded CSS styles

    When you write code in your head, you may often add some embedded css code, just like this:

    Foot home

    It seems convenient and no problem, but it will cause problems in your code.

    When writing code, it is best to add the style code after the content structure is complete.

    This encoding method is like guerrilla warfare. It is a very shanty practice. -- Chris Coyier

    A better way is to define the P style in the style sheet file:

    someElement > p {color: red;}
    4. Introduce all style sheet files in the head tab of the page.

    Theoretically, you can introduce CSS style sheets at any position. However, we recommend that you add HTML standards to the head mark of a webpage to speed up page rendering.

    During Yahoo's development, we found that introducing style sheets to head labels will speed up webpage loading,
    In this way, the page can be gradually rendered. -- YSlow team

    My Favorites Kinds of Corn
      
      
    5. Introduce JavaScript files at the bottom of the page

    Remember that the principle is to make the page appear in front of the user as quickly as possible. When a script is loaded, the page stops loading until the script is fully loaded. Therefore, it will waste more time for users.

    If your JS file only needs to implement some functions (such as clicking a button event), you can safely introduce it at the bottom of the body. This is definitely the best method.

    Example:

    And now you know my favorite kinds of corn.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.