1. Don’t use section as a replacement for div One of the most common mistakes people make when using tags is to arbitrarily equate HTML5's <section> to <div> - specifically, to use it as a direct replacement (for styling). In XHTML or HTML4, we often see code like this:
Now in HTML5, it will look like this: Please do not copy this code! It is wrong!
This is incorrect: it is not a style container. The section element represents a semantic section of content that helps build the outline of the document. It should contain a header. If you are looking for an element that acts as a page container (in the style of HTML or XHTML), then consider writing styles directly to the body element as Kroc Camen suggests. If you still need additional style containers, stick with divs. Based on the above ideas, the following is an example of the correct use of HTML5 and some ARIA roles features (note that depending on your own design, you may also need to add divs)
If you are still unsure which element to use, I recommend referring to the HTML5 sectioning content element flowchart. 2. Use header and hgroup only when needed It is pointless to write tags that are not needed. Unfortunately, I often see header and hgroup elements being misused. You can read two articles about header and hgroup elements for a detailed understanding, but I will briefly summarize the content as follows:
Abuse of headers Since headers can be used multiple times in a document, this coding style may be popular: Please do not copy this code! The header is not needed here –>
If your header element only contains one header element, then discard the header element. Since the article element already guarantees that the header will appear in the document summary, and the header cannot contain multiple elements (as defined above), why write extra code? Simply write it like this:
Incorrect use of On the topic of headers, I also often see the incorrect use of hgroup. Sometimes you shouldn't use hgroup and header together:
The first question usually goes something like this: Please do not copy this code! hgroup is not needed here –>
In this case, just remove the hgroup and let the heading run as is.
The second question is another example of something unnecessary: Please do not copy this code! No header is needed here –>
If the only child element of the header is hgroup, what is the point of the header? If there are no other elements in the header (such as multiple hgroups), just remove the header. (Web front-end learning exchange group: 328058344 No idle chat, no entry if you don't like it!)
For more examples and explanations, see the related article 3. Don’t put all list links in nav With HTML5 introducing 30 new elements (at the time of this post), our choices in constructing semantic and structural markup have become somewhat imprudent. That is, we should not abuse hyper-semantic elements. Unfortunately, nav is an example of such abuse. The specification of the nav element describes it as follows: The nav element represents a block in the page that links to other pages or other parts of the page; a block that contains navigation links. Note: Not all links on a page need to be placed in the nav element - this element is intended to be used as the main navigation block. For example, there are often many links in the footer, such as the terms of service, home page, copyright notice page, etc. The footer element itself is sufficient for these situations, and although the nav element can also be used here, it is generally considered unnecessary. The key word is "primary" navigation. Of course, we can argue all day about what "primary" means. Here's how I define it:
Since there is no absolute right or wrong, based on an informal vote and my own interpretation, I will not put the following in your opinion, regardless of whether you put it in or not. middle: Paging Control Social links (although some social links are also primary navigation, such as "About" and "Favorites")
If you’re unsure whether to place a series of links in a nav, ask yourself: “Is it the primary navigation?” To help you answer this question, consider these first principles: Don't use nav if section and hx are equally appropriate — Hixie on IRC
If the answer to these questions is "no", then follow
IV. Common mistakes with figure elements The correct use of figures and figcaptions can be difficult to master. Let's look at some common mistakes. Not all images are figures. Earlier, I told you not to write unnecessary code. This mistake is the same. I see a lot of websites that label all images as figure. Please don't add extra tags for the sake of the image. You're just annoying yourself and not making your page clearer. The specification describes a figure as "a piece of flowing content, sometimes with its own caption. It is generally referenced as a separate unit in the document flow." This is the beauty of a figure - it can be moved from the main content page to the sidebar without affecting the document flow. These issues are also covered in the HTML5 element flowchart mentioned earlier. If the figure is purely for presentation and is not referenced elsewhere in the document, then it is definitely not. The rest depends, but a good place to start is to ask yourself: "Does this figure have to be relevant to the context?" If not, then it's probably not (maybe it is). Follow up with: "Can I move it to an appendix?" If both questions are true, then it probably is. A logo is not a figure Furthermore, logo is not suitable for figure. Here are some common code snippets I use:
There's not much else to say. This is a very common mistake. We can argue over whether a logo should be an H1 tag or not, but that's not the point. The real problem is the misuse of the figure element. Figures should only be referenced within a document, or surrounded by section elements. I don't think your logo is referenced in this way. Simple, don't use a figure. You just need to do this:
Figure is not just a picture Another common misconception about figures is that they are only used for images. Figures can be video, audio, a chart, a quote, a table, a piece of code, a piece of prose, or any combination of these or others. Don't limit figures to images. It is the job of web standards to accurately describe content with tags. 5. Don’t use unnecessary type attributes This is a common problem, but it is not a mistake, and I think we should avoid this style through best practices. In HTML5, script and style elements no longer require type attributes. However, these are likely to be added automatically by your CMS, so it is not easy to remove them. But if you are hand-coding or you have full control over your templates, there is really no reason to include type attributes. All browsers assume that scripts are javascript and styles are CSS styles, so there is no need to do this.
In fact, you only need to write:
Even the code that specifies the character set can be omitted, as Mark Pilgrim explains in the Semantics chapter of Dive into HTML5. 6. Incorrect use of form attributes HTML5 introduces some new form attributes. Here are some notes on their use: Boolean properties Some multimedia elements and other elements also have Boolean attributes. The same rules apply here. Some of the new form attributes are boolean, meaning that their presence in the markup ensures that the corresponding behavior is set. These attributes include:
Frankly speaking, I rarely see this. Taking required as an example, the following is common:
Strictly speaking, this is fine. As long as the browser's HTML parser sees the required attribute appear in the tag, its functionality will be applied. But what if you write required="false" in reverse?
The parser will still treat the required attribute as valid and perform the corresponding behavior, even if you try to tell it not to. This is obviously not what you want. There are three valid ways to use Boolean attributes. (The last two are only valid in XTHML)
The correct way to write the above example should be:
|
<<: How to compile iOS projects 5 times faster
>>: Serialize the Intent and pass it like a Uri!!!
This article combines nearly a hundred case studi...
185-6916-1745 Micro.Q Synchronization The masseus...
In order to ensure that the developed mini progra...
Great Wall Motors' recent sales are not optim...
Ever since the Wei Zexi incident broke out last y...
Expert: Dr. Xie Qiang, Geotechnical Engineer, Off...
The bargaining and free-getting activities that h...
On October 12, Tmall, one of the online sales cha...
1. What is a good province? Answer: Haosheng is a...
In recent days, Taiwan has been a very hot word, ...
Everyone knows that BAT is eyeing the automotive ...
The scientific spirit can help us find relative c...
The new graduates have a good understanding of th...
First look at this picture: I divided the operati...
We try to reflect the value of our product throug...