Why choose HTML5 semantic tags instead of div tags?
P粉806834059
P粉806834059 2023-08-22 23:00:37
0
2
509
<p>Why use HTML5 semantic tags, such as <code>headers</code>, <code>section</code>, <code>nav</code> and <code>article</ code> instead of simply using <code>div</code> and setting it to the preferred <code>css</code>? </p> <p>I created a page and used these tags, but they are no different from <code>div</code>. What is their main purpose? </p> <p>Are they just providing the appropriate label name when used, or do they do something else? </p> <p>Please explain. I checked many websites but couldn't find these basics. </p>
P粉806834059
P粉806834059

reply all(2)
P粉262926195

There is a good article about HTML5 semantics on HTML5Doctor.

Semantics have always been part of HTML, existing in some form. It helps you understand what's happening on the page.

In the old days, when almost everything used <div>, we still achieved semantics by giving it a "semantic" class name or id name.

These tags help in structuring and understanding the layout correctly.

If you do this:

<div class="nav"></div>

and

<nav></nav>

or

<div class="sidebar"></div>

and

<aside></aside>
There is no problem with

, but the latter provides better readability for you, crawlers, readers, etc.

P粉200138510

Oxford Dictionary states the following:

As their name suggests, these tags are designed to enhance the meaning of your web pages. Good semantics play an important role in automatic processing of documents. This automatic processing happens more often than you realize - every website ranked by search engines is derived from the automatic processing of all websites.

If you visit a (well designed) web page, as a human reader you can immediately (visually) distinguish all the page elements and more importantly understand the content. On the top left you can see the company logo, next to the site navigation, there is a search bar and some text about the company, a link to products you can buy and a legal disclaimer at the bottom.

However, the machine is stupid and cannot do this: Looking at the same page as yours, a web crawler will only see an image, a series of anchor tags, a text node, an input field, and an image with a link. There is another text node at the bottom. Now, how are they supposed to know which part of the document you intend to be the navigation or the main article, or some less important footnote? They can guess hints for specific elements by analyzing your document structure using some common criteria. For example, the

    list of internal links is most likely some kind of page navigation, and the text at the end of the document is necessary but not too important content for the everyday viewer (legal disclaimer).

    Now imagine if a normal

    was used instead of the
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!