Use semantic HTML

Source: Internet
Author: User

Why use the

The reason is that <p> and

What is semantic HTML?

In short, semantic HTML is an HTML that uses the correct elements or tags to carry out a job. Take

Semantic HTML also uses qualitative content rather than simply the appearance to mark the content. For example, think about the ubiquitous blog archiving panel. It is a list of links linked to other blog pages, usually on the right side of the page. When you specify an ID for an archive or a class for a CSS style, you can use the name to reflect its position on the page, for example, rightpanel. Alternatively, you can use a name to indicate the role it plays in the content. For example, sidebar or archive is better.

Semantic HTML has the following features:

The text is wrapped in elements to reflect the content. For example:

The section is included in the <p> element.

The sequence table is included in the <ol> element.

Large text blocks referenced from other sources are included in the <blockquote> element.

HTML elements cannot be used for other purposes than semantic purposes. For example:

<H1> contains the title, but is not used to enlarge the text.

<Blockquote> it contains a large quote, but is not used for text indent.

A blank section (<p> </p>) is not used to skip a row.

Text does not directly contain any style information. For example:

Do not use format tags such as <font> or <center>.

The color or position is not referenced in the class or ID.

The purpose of all this is to enable code users, whether users, browsers, or screen readers, to use the content and easily parse it from the machine's objective and user's subjective perspectives.

Why do I want to introduce semantic HTML?

Traditionally, there are five main arguments that are conducive to semantic HTML.

Less code

The Semantic HTML of CSS styles usually requires less code than the HTML of table format. However, you cannot write HTML without a table. This is not the true meaning of semantic HTML. You can still reduce the code size, but it cannot make the code easier to understand.

Accessibility

Accessibility refers to helping people with disabilities use your website. Semantic code is often more accessible. When you mark all parts of the page as titles, titles, paragraphs, and lists, screen readers and other auxiliary technologies can easily parse and present content in a way that is understandable to people with disabilities. However, pay attention to the emphasis on the word "often. The Semantic HTML solution is not magical and does not make your website conform to the principle of accessibility. It is only used to simplify the process of building accessible websites.

Search Engine Optimization

Because of its accessibility, semantic HTML often improves the search engine optimization (SEO) feature by making it easier for your website to parse website content using software. The search engine scans HTML text contained in HTML files. They do not render CSS or run JavaScript. If your important content is not displayed in HTML format, the search engine may not be able to view it, and will not arrange it accordingly. In addition, by deleting HTML junk on the page, the search engine can easily identify the real subject of the website by leaving only the description content. This technology is called "White Hat" SEO. This is completely acceptable. No search engine will impose penalties on you because you have optimized the page in terms of semantics. On the contrary, the use of hidden text to enhance the relevance of a specific topic is called "Black Hat" SEO .)

It should be noted that no one can guarantee that semantic HTML is more suitable for SEO. Web developers regard search engines as the preferred semantic HTML. Google HTML5 inputs this operation as a recommended operation. However, search engines strictly abide by their own algorithms and have to allow highly relevant content to be written in non-semantic HTML.

Reuse

Semantic HTML makes full use of the following advantages: "News projects" are always news projects, and "Archives" are always archives, regardless of their location on the page. However, the rightbar is not always on the right. In addition, if you use an RSS feed to simultaneously publish content and include it in HTML, the fewer tags, the better. However, most websites and blogs do not directly publish content from specially processed HTML. They are often built separately and process the Union format to ensure that other users understand the content.

Developer explanation

You may have noticed that topics have been included in the semantic HTML parameters so far. All of this sounds like a good reason to use semantic HTML, but separately, none of them really make me feel at ease. Perhaps all the features add up to make you feel fascinated. If so, it would be great. But I admit that there is a good reason to write semantic HTML. For computer developers, this is a relatively easy part) and other developers, coding is communication. Semantic HTML is easier to understand than non-semantic HTML. The r1c4 div elements are not as easy to understand as the so-called pullquote elements. With semantic HTML, you can help other developers and HTML creators understand the purpose of the code.

It is worth noting that this field has a large degree of subjectivity. In this article on HTML semantics and front-end architecture, Nicholas Gallagher confirms that classes and IDs cannot be non-semantic because semantics and meaning are closely related, any element you place in the class or ID is meaningful. His logic is very reasonable, but in my opinion, this is not the best way to look at the problem.

The semantics is not binary. You cannot implement full semantics or completely maintain non-semantics. Semantics is a continuous feature. The Web content is between completely non-semantic and completely semantic, because these two extremes cannot be achieved. With this in mind, when you continue to simplify Web content users' understanding of the meaning of Web content fragments, you can move content across non-semantic to semantic gaps.

What new elements does semantic HTML provide?

One controversial part of the HTML semantics lies in the ID and class naming. Some problems are the difference between the content defined by the HTML specification and the content displayed on the actual page. For example, website navigation. Navigation menus were everywhere in the middle of 1990s, but there was a lack of a single standardized approach to marking navigation for a long time. The header, footer, and content in the form of an article or post are the same. Due to the lack of related standardization methods and the existence of a large number of possible ways of operation, there are considerable differences in operation methods.

Some of these problems have been mitigated through HTML5. During the development of HTML5 specifications, leading Web content enterprises share the analysis results of some common IDs and class names and use them as guidance for creating new HTML5 elements, these elements are very effective for marking many common Web content fragments. Generate a series of new elements, including:


There are many other elements that we will detail in the W3C HTML4 and HTML5 differences list.

The key is to establish a more standard content tagging method. The more unified the labeling method, the easier it is for users and devices to use content.

You are not serving the semantic service.

I think one of the biggest problems with HTML semantics is that people often regard semantic HTML functions as objective rules rather than guiding principles. You should, but not must, use valid semantics to compile HTML. If you want to use semantic HTML, using it to enhance the content will be better than following a series of best practices without understanding the theory behind it.

Semantics makes HTML easier to understand. This means that you must note that the

Next reading

Semantic methods are of great significance and can effectively enhance accessibility, SEO, reusability, and communication between developers. They exist continuously. Your Goals should be extended to more semantic content along with this continuity, but you cannot try to reach the out-of-the-box goal of perfect semantics. Otherwise, they are tantamount to suicide.

The following are some methods to help you improve the semantic HTML function.

For more information about General Semantics, see:

W3C HTML5 reference

The World Wide Web Alliance (W3C) is a Web standard organization. Therefore, they define all elements. They have unique or absolute opinions on the use of HTML elements, depending on the person you consulted ). Each element in HTML contains detailed documents, including the semantic usage of elements.

WhichElement.com

WhichElement.com is a website. I initially started to discuss appropriate content semantics from this point. For example, if you are looking to mark the calendar in semantic form, whichElement.com will bring you the gospel.

For more information about HTML5 semantics, see:

HMTL5 Doctor

HTML5 Doctor is a way to help developers use HTML5 resources because it is always in a state of engagement. This website provides a lot of good information about the semantic usage of HTML5 elements.

Adobe Developer Connection

Stefan (Sullivan) Rewis has written a great series of articles to learn about HTML5 semantics and help you understand how to use new semantic HTML elements.


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.