HTML has gone through nearly 20 of the development process. From HTML4 to XHTML to the most recent fiery HTML5, it has almost witnessed the development of the entire Internet. However, even now, there are many basic concepts and principles that still require the developer to be highly aware. Below, we introduce the development principles that should be followed. 1, use Div to layout
When developing a Web page, the first thing to consider is to differentiate the page from the main point. By including the content in div tags, the code of the page will show a neat, well-indented style.
< div id = "header" ></ div > < div id = "Body-container" > < div id = "content" > <!-- Content--> </div> <div id= "Right-side-bar" > <!--right side bar Conte NT Area--></div> </div> <div id= "Footer" ></DIV>
2. Separating HTML tags from CSS style sheets
A good page should separate the HTML tag from the CSS style sheet. This is a principle that every web developer should know when they first touch web development. However, until today, there are still many developers who do not strictly follow this principle.
Do not embed style sheet code in HTML tags. Developers should get into the habit of creating files separately to store CSS stylesheets. This will also make it easier for other developers to get the job done quickly when modifying your code.
<style= "color: #CCC; font-size:16px; font-family:arial"> an Example to illustrate inline style in HTML</p>
3. Optimize CSS Code
Adding more than one CSS file to a Web site is now a common practice. However, when a Web site contains too many CSS files, it can slow down the response time of the site. The workaround is to streamline the code and optimize multiple CSS files to merge them into one file. This method can significantly improve the loading speed of the website. In addition, there are many tools that can be used to optimize CSS files, such as CSS Optimizer, clean CSS, and so on. 4. Optimize JavaScript files and place them at the bottom of the page
As with CSS, it is common practice to add multiple JavaScript files to a page. But it also reduces the responsiveness of the site. To do this, developers should streamline and optimize these JavaScript files.
However, unlike CSS, browsers typically do not support parallel loading. This means that when a browser loads a JavaScript file, it will no longer load other content at the same time. This causes the page to load as if it were slowing down.
A good solution is to put JavaScript files in the last order of loading. To achieve this, developers can put JavaScript code at the bottom of the HTML document, and the best place to put it is near the </body> tag. 5. Use the TITLE element
< H1 > The topmost heading</H1><H2>This is a Sub-heading underneath the topmost heading. </ H2 > < H3 > This is a sub-heading underneath the H2 heading. </ H3 >
6. Use appropriate HTML tags in the right place
HTML tags are the key to constructing a canonical content structure. For example,,<em> tags are used to emphasize emphasis. <p> tags apply to highlight article paragraphs. If you want to empty lines between paragraphs, do not use the <BR/> label.
< em >emphasized text</em><strong> Strongly emphasized text</strong>
For a set of related elements, it is recommended to use the <ul>, <ol>, or <dl> tags. However, do not use the <blockquote> tag incorrectly because it was originally used to define the block application. 7. Avoid Misuse <div> labeling
Not all block elements should be created with the <div> tag. For example, you can add a display:block to an inline element's properties to display it as a block element. 8. Create a navigation using the list
You can create beautiful navigation menus by using the <ul> List tab, with the corresponding CSS style. 9, do not forget to close the label
Now, whenever I recall the first lesson I learned about web development in college, the importance of the HTML structure that the Professor mentions always comes to mind. According to the standard, labels should be closed. That is because, in some browsers, if you do not follow the standard to close the label, there will be a problem showing the abnormal. This is particularly evident in IE6, 7 and 8. 10. Label lowercase syntax
The use of lowercase syntax for labels is an industry standard. Although the uppercase syntax does not affect the display of the page, the code is poorly readable. The following code is very poor in readability:
<DIV><IMGSRC= "Images/demo_image.jpg"alt= "Demo image"/><AHREF="#"TITLE= " click here">Click here</A><P>Some sample text</P></DIV>
11. Add alt attribute for picture label
In the tab, the ALT attribute is often useful. Because search engines are often unable to crawl image files directly. However, if the developer adds a description of the image to the ALT attribute, it will be convenient for the search engine to crawl.
<!-- Have an alt attribute, which would validate, but Alt value is meaningless--><!--the correct-->
12. Use <label> and <fieldset> in the form
To improve code quality and make it easier for users to understand table content, we should create table elements with <label> and <fieldset> tags.
<fieldset><legend>Personal particular</legend><label for= "Name">Name</label><inputtype= "text"ID= "Name"name= "Name" /><label for= "Email">E-Mail</label><inputtype= "text"ID= "Email"name= "Email" /><label for= "Subject">Subject</label><inputtype= "text"ID= "Subject"name= "Subject" /><label for= "message" >Message Body</label> <textarearows= "Ten"cols= " the"ID= "message"name= "message" ></textarea></fieldset>
13, the browser-compatible code to identify information and separate from each other
Cross-browser compatibility is a key concern for a web developer. In general, developers will code for different browsers, which is CSS hack. However, if the developer is coding, it can be noted that the code for which version of the browser is written, will be very convenient for future maintenance work. Here's a good example:
<!-- [If IE 7]><link rel= "stylesheet" href= "Css/ie-7.css" media= "All" ><! [EndIf] -
<!-- [If IE 6]><link rel= "stylesheet" href= "Css/ie-6.css" media= "All" ><script type= "Text/javascript" src= " Js/dd_belatedpng_0.0.8a-min.js "></script><script type=" Text/javascript ">DD_belatedPNG.fix (' #logo '); </script><! [EndIf] -
14. Avoid excessive annotation
As a developer, adding comments to your code is a good habit, easy to understand and easy to maintain. This is common in other programming languages such as PHP, JAVA, and C #. However, html/xhtml is a text markup language that is very easy to understand. Therefore, there is no need to add comments for each line of code. 15. Test Code
Developers are recommended to test the code using the text tag verification service. It is an efficient test tool that can help you find errors in the page. It also allows you to navigate to the appropriate code, starting with a page fault. This is often difficult to do after the coding is complete. However, developers need to be aware that the code passed by the validation is not the code that performs well.
15 coding principles that Web developers should know