搜尋
首頁web前端html教學HTML5 語意元素

HTML5 語意元素

Sep 04, 2024 pm 04:37 PM
htmlhtml5HTML TutorialHTML PropertiesHTML tags

以下的文章將為您提供HTML5中的各種語意元素。語義是關於不同類型的標籤,其功能將根據其標籤名稱描述並執行相同的功能。標籤的功能很容易透過其名稱來理解,該名稱採用使用者可理解的名稱/格式。 HTML 中的大多數元素通常都是語意元素。

HTML5 中語意元素的優點

語意元素的優點如下:

  • 輕鬆理解程式碼。
  • 維護可以快速且適當地進行。
  • 無需專門為任何標籤添加任何描述。

HTML5 中的各種語意元素

現在讓我們進入語意元素:

1.

這個標籤讓我們知道這個標籤內的資料是專門針對類似內容的。這也取決於我們通常擁有的不同類型的文章。可以是部落格、論壇、報紙專欄文章等

代碼:


<article>
<h2 id="HTML">HTML5</h2>
<p>New Updated version of HTML</p>
</article>
<article>
<h2 id="Learning-HTML">Learning HTML</h2>
<p> We are learning through EDUCBA</p>
</article>

輸出:

HTML5 語意元素

2.

這個標籤是關於提供總資料的一個部分內容。在了解如何使用文章標籤和章節標籤後,可以在每個標籤內使用這些標籤。也就是說,節標籤可以在文章標籤內使用,反之亦然。

代碼:


<section>The section here is about:
<p></p>
<h4 id="Learning-and-practising"> Learning and practising</h4> 
</section>

輸出:

HTML5 語意元素

3.

這個標籤給了所有的標題資料。我們想要放置在標頭格式中的任何資料都在此標頭標籤下使用。而這個標籤可以在整個 HTML 腳本中使用多次。

代碼:


<header>
<h3 id="This-is-header">This is header #1</h3>
<p> First one</p>
</header>
<p> next one ...</p>
<header>
<h3 id="This-is-header">This is header #2</h3>
<p> Second one </p>
</header>

輸出:

HTML5 語意元素

4.

這是 HTML 腳本中的頁腳部分。一般來說,我們會看到所有版權資料以及我們在任何優惠下找到的一小部分,例如任何優惠的「條件適用」。所以這些東西都是在頁腳標籤下定義的。

代碼:


<p> Inside Body and above footer tag</p>
<footer>
<p> Inside footer tag.</p>
</footer>
<footer>
<p></p>
<h4 id="Another-footer-tag"> Another footer tag</h4>
<p></p>
<h6 id="Conditions-Apply">Conditions Apply</h6> 
</footer>

輸出:

HTML5 語意元素

5.

這個標籤為我們提供了導航元素。任何 HTML 文件腳本中的 URL,我們通常希望透過此標籤從一個頁面導航到另一個頁面。此標籤下給出的任何數據都可以作為超連結提供。這些超連結可用於從一個部分導航到另一部分。

代碼:


<h4 id="About"> About </h4>
<nav><a href="#"> About link 1</a>
<a href="#"> About link 1</a>
</nav>
<h4 id="Contact"> Contact </h4>
<nav>
<a href="#"> Contact Link 1</a>
<a href="#"> Contact Link 2</a>
</nav>

輸出:

HTML5 語意元素

練習時,點擊這些連結並檢查點擊時超連結的顏色如何變化。

6.

這是一個用於在 HTML 文件兩側顯示資料的標籤。在許多網站上,我們可以找到側邊欄中存在的內容,這些內容是使用此aside標籤顯示的。此內容應與文件中存在的其他數據一致。

代碼:


<p>How aside tag is used </p>
<aside>
<h4 id="Inside-aside-tag">Inside aside tag</h4>
<p>Content inside aside tag</p>
</aside>

輸出:

HTML5 語意元素

無法用同樣的方式完全指定具體的內容;只有使用整個 HTML 頁面才能清楚地記錄和理解它。

7.

此標籤指定我們要附加圖像。此標籤可用於指定圖像來源並顯示 gif 或圖像。

代碼:


<figure>
<img  src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/172543905337030.png?x-oss-process=image/resize,p_40" class="lazy" alt="HTML5 語意元素" >
</figure>

如上所述,這就是我們定義figure標籤的方式。在figure標籤內,我們可以使用source標籤指定我們的映像指令。在這個圖形標籤內,我們可以依序使用圖形標題標籤。

8.

此標籤用於在所提供的圖像下提供標題。它可以在figure標籤內使用。其用法可以在下面的範例中看到。


<figure>
<img  src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/172543905337030.png?x-oss-process=image/resize,p_40" class="lazy" alt="HTML5 語意元素" >
<figcaption>This is description of the image attached.</figcaption>
</figure>

您可以嘗試透過提供影像來源來執行相同的操作,並檢查輸出的顯示方式。

9.

該標籤指定了 HTML 網站的所有屬性和完整內容。它包含所有獨特的內容。對於此特定標記需要注意的重要一點是,此標記在整個頁面建立中只能使用一次。我們發現其他標籤在建立網頁時可以多次使用,但這個主標籤是單次使用標籤。

代碼:


<main>
<h1 id="Learning-HTML-Semantic-Tags">Learning HTML Semantic Tags</h1>
<article>
<h4 id="Studying">Studying</h4>
<p> Reading would help to understand different topics</p>
</article>
<article>
<h4 id="Practising">Practising</h4>
<p> With Studying , Practising is a must thing to do in learning</p>
</article>
</main>

輸出:

HTML5 語意元素

10.

This tag is for highlighting specific content or data. In other words, this tag is helpful in marking data.

Code:


<p> In this whole text which I am writing now, <mark> I want to mark this text </mark></p>

Output:

HTML5 語意元素

11.

This tag contains additional details that users can hide any details on their wish. Through this tag, users can open/close any content which they need. If we want that tag to disclose its details at the start itself, then the attribute “open” can be used.

Code:


<details open="true">
<p>Is this displayed?</p>
</details>

Output:

HTML5 語意元素

Now, what would be the output if we did not use the open attribute?

Code:


<details>
<p>Is this displayed?</p>
</details>

Output 1:

HTML5 語意元素

Output 2:

HTML5 語意元素

12.

This tag is used inside the details tag. Under the details tag, we can have a summary tag that specifies the entire summary of the web page or the HTML document. An important thing to note here is that the summary tag is the first child tag that has to come under the details tag.

Code:


<details>
<summary> Have written this inside summary tag which is inside details tag</summary>
<p>This text only comes under details tag</p>
</details>
<p> This text data is written after completion of details tag</p>

Output 1:

HTML5 語意元素

We had highlighted the arrow in the above output, as we get our output 2 once we expand it.

Output 2:

HTML5 語意元素

This tag might not be giving out any difference

13.

This tag defines date/time in such a format that users can easily understand. But a thing to note is that this tag may not give us a changed output in many of the browsers.

Code:


<p>At present time is <time>11:00</time> pm in the night.</p>

Output:

HTML5 語意元素

14.

As the name already suggests, this tag is for writing any content in a box. This tag should have an open attribute for displaying the dialog box once the source code is executed.

Code:


<dialog open="true">
<p> The data written here gets displayed in a dialog box </p>
</dialog>

Output:

HTML5 語意元素

15.

This tag gives the progress of a certain task in a graphical representation. We here need to have the maximum number for which the progress has to be represented. This tag mainly consists of two attributes. Max and value are the two attributes. Max represents the total count that has to be completed, and Value gives us the count percent that is finished with respect to the maximum count value.

Code:


<h1 id="EDUCBA">EDUCBA</h1>
Your learning progress is:
<progress value="72" max="100">
</progress>

Output:

HTML5 語意元素

16.

This tag is for measurement. This can be utilized for the space taken by a query or usage of disk space also. There are a few attributes that are to be used with this tag. The attributes are max, min, and value. Based on their usage, we can definitely figure out their purpose and usage.

Code:


<h2 id="EDCUBA">EDCUBA</h2>
<p>Usage of Meter tag</p>
In a 6 floors apartment, I live in 2nd floor:
<meter value="2" min="0" max="6">2 out of 6</meter>

Output:

HTML5 語意元素

17.

This is a tag that has been introduced to add video files to our HTML page. Until this tag was introduced, developers used plugins to introduce video files into HTML page content. There are a few attributes that can be used along with the tag. Autoplay, Preload, Muted are some of these.

Code:


<video>
<source src="video_name.mp4" type="video/mp4">
</source></video>

We just need a source tag to give the source from where we need to upload the video content to our page.

18.

This tag is for adding audio files to our Html page. The usage and the source tag would be the same as that of the video tag. As an exercise, try using all the semantic elements and create e HTML 5 version web page to learn better and faster.

Conclusion

In this article, we have got to see many semantic elements and their usage in HTML5. One important thing to note here is, many of these tags are supported by internet explorer versions greater than 9 and chrome versions greater than 3.

以上是HTML5 語意元素的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
如何在標籤上設置lang屬性?為什麼這很重要?如何在標籤上設置lang屬性?為什麼這很重要?May 08, 2025 am 12:03 AM

設置標籤的lang屬性是優化網頁可訪問性和SEO的關鍵步驟。 1)在標籤中設置lang屬性,如。 2)在多語言內容中,為不同語言部分設置lang屬性,如。 3)使用符合ISO639-1標準的語言代碼,如"en"、"fr"、"zh"等。正確設置lang屬性可以提高網頁的可訪問性和搜索引擎排名。

HTML屬性的目的是什麼?HTML屬性的目的是什麼?May 07, 2025 am 12:01 AM

htmlattributeseresene forenhancingwebelements'functionalityandAppearance.TheyAdDinformationTodeFineBehavior,外觀和互動,使網站互動,響應式,visalalyAppealing.AttributesLikutesLikeSlikEslikesrc,href,href,href,類,類型,類型,和dissabledtransfransformformformformformformformformformformformformformformforment

您如何在HTML中創建列表?您如何在HTML中創建列表?May 06, 2025 am 12:01 AM

toCreateAlistInHtml,useforforunordedlistsandfororderedlists:1)forunorderedlists,wrapitemsinanduseforeachItem,RenderingeringAsabulletedList.2)fororderedlists,useandfornumberedlists,useandfornumberedlists,casundfornumberedlists,casundfornthetthetthetthetthetthetthetttributefordforderfordforderforderentnumberingsnumberingsnumberingStys。

HTML行動:網站結構的示例HTML行動:網站結構的示例May 05, 2025 am 12:03 AM

HTML用於構建結構清晰的網站。 1)使用標籤如、、定義網站結構。 2)示例展示了博客和電商網站的結構。 3)避免常見錯誤如標籤嵌套不正確。 4)優化性能通過減少HTTP請求和使用語義化標籤。

您如何將圖像插入HTML頁面?您如何將圖像插入HTML頁面?May 04, 2025 am 12:02 AM

toinsertanimageIntoanhtmlpage,usethetagwithsrcandaltattributes.1)usealttextforAcccessibilityandseo.2)instementRcsetForresponSiveImages.3)applylazyloadingWithLoadingWithLoading =“ lazy” tooptimizeperformance.4)tooptimizeperformance.4)

HTML的目的:啟用Web瀏覽器可以顯示內容HTML的目的:啟用Web瀏覽器可以顯示內容May 03, 2025 am 12:03 AM

HTML的核心目的在於讓瀏覽器理解並展示網頁內容。 1.HTML通過標籤定義網頁結構和內容,如、到、等。 2.HTML5增強了多媒體支持,引入了和標籤。 3.HTML提供了表單元素,支持用戶交互。 4.優化HTML代碼可提升網頁性能,如減少HTTP請求和壓縮HTML。

為什麼HTML標籤對Web開發很重要?為什麼HTML標籤對Web開發很重要?May 02, 2025 am 12:03 AM

htmltagsareessentialforwebdevelopmentastheyandendenhancewebpages.1)semantictagsimproveaccessibilityandseo.2)semanteLayOut,語義和互動性。 3)poseriblesibilityandseoandseo.3)poseriblesoftagscanoftagscanoftagscanoptagscanoptimizeperefeneandimizeanDenSuroceRecRoscRoss-BrowserCrowserCercerComercompatibility。

說明將一致的編碼樣式用於HTML標籤和屬性的重要性。說明將一致的編碼樣式用於HTML標籤和屬性的重要性。May 01, 2025 am 12:01 AM

一致的HTML編碼風格很重要,因為它提高了代碼的可讀性、可維護性和效率。 1)使用小寫標籤和屬性,2)保持一致的縮進,3)選擇並堅持使用單引號或雙引號,4)避免在項目中混合使用不同風格,5)利用自動化工具如Prettier或ESLint來確保風格的一致性。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器