HTML Attributes
All HTML elements can have attributes
Attributes provide additional information about an element
Attributes are always specified in the start tag
Attributes usually come in name/value pairs like: name="value" 屬性總是以名稱/值對的形式出現(xiàn)牲蜀,比如:name="value"。
雙引號是最常用的在辆,不過使用單引號也沒有問題峭判。
提示: 在某些個別的情況下开缎,比如屬性值本身就含有雙引號林螃,那么您必須使用單引號,例如:name='John "ShotGun" Nelson'
The href Attribute
<a >This is a link</a>
---> This is a linkThe src Attribute
<img src="img_girl.jpg">
The width and height Attributes
<img src="img_girl.jpg" width="500" height="600">
--> The image size is specified in pixels: width="500" means 500 pixels wide.The alt Attribute (The alt attribute specifies an alternative text to be used, when an image cannot be displayed.The value of the attribute can be read by screen readers. This way, someone "listening" to the webpage, e.g. a blind person, can "hear" the element.)
<img src="img_girl.jpg" alt="Girl with a jacket">
--> If we try to display an image that does not exist, the value of the alt attribute will be displayed instead.The style Attribute (The style attribute is used to specify the styling of an element, like color, font, size etc.)
<p style="color:red">I am a paragraph</p>
The lang Attribute (The language of the document can be declared in the <html> tag. The language is declared with the lang attribute. Declaring a language is important for accessibility applications (screen readers) and search engines.)
<!DOCTYPE html>
<html lang="en-US">
<body>
...
</body>
</html>
- The title Attribute (Here, a title attribute is added to the <p> element. The value of the title attribute will be displayed as a tooltip when you mouse over the paragraph.)
<p title="I'm a tooltip">
This is a paragraph.
</p>
Summary
- All HTML elements can have attributes
- The title attribute provides additional "tool-tip" information
- The href attribute provides address information for links
- The width and height attributes provide size information for images
- The alt attribute provides text for screen readers
Attribute Description
alt
Specifies an alternative text for an image, when the image cannot be displayed
disabled
Specifies that an input element should be disabled
href
Specifies the URL (web address) for a link
id
Specifies a unique id for an element 定義元素的唯一id
src
Specifies the URL (web address) for an image
style
Specifies an inline CSS style for an element 規(guī)定元素的行內(nèi)樣式(inline style)
title
Specifies extra information about an element (displayed as a tool tip) 描述了元素的額外信息 (作為工具條使用)
A complete list of all attributes for each HTML element, is listed in our: HTML Attribute Reference.
更多 HTML 標準屬性說明: HTML 標準屬性參考手冊.