HTML Attributes

HTML Attributes (case-insensitive 大小寫不敏感)

  • Attributes provide additional information about an element, always specified in the start tag
  • Attributes come in name/value pairs like: name="value"


land 屬性

The document language can be declared in the <html> tag with the lang attribute.

Declaring a language is important for accessibility applications (screen readers) and search engines.

文檔語言可以被定義在 <html> 標籤裏。定義文檔語言,對於屏幕閱讀器和搜索引擎可獲取性很重要。


alt 屬性

The alt attribute specifies an alternative text to be used, when an HTML element cannot be displayed. The value of the attribute can be read by "screen readers".
該屬性設定了可被使用的替換文本,當該元素的內容無法展示時。同時 alt 的值還能被屏幕閱讀器讀取。


引號

HTML 5 並沒有要求屬性的值要被引號限制起來,但是,最好記得使用引號。

<p title=About W3Schools>

避免由屬性值裏面的空格引起的顯示錯誤。


單/雙引號

Double style quotes are the most common, but single style quotes are also allowed

通常使用雙引號,但是單引號也是被允許的。

Tip: In some rare situations, when the attribute value itself contains quotes, it is necessary to use single quotes

<p title='John "ShotGun" Nelson'>

當屬性值包含雙引號,則必須使用單引號把它括起來。


小寫

W3C recommends lowercase in HTML4, and demands lowercase for stricter document types like XHTML.

因此,儘管HTML 5沒有要求屬性要小寫,通常使用小寫的屬性名稱。


HTML Global Attributes(常用的適用於任何HTML元素的屬性):

class one or more class names for an element (refers to a class in a style sheet)
id a unique id for an element
style an inline CSS style for an element
title extra information 額外信息 about an element (when mouse over the element, title displayed as a tool tip 提示框)



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章