w3schools网站的HTML教程之HTML属性_html/css_WEB-ITnose
- HTML 元素允许具有属性
- 属性提供了有关一个 HTML 元素的额外信息
- 属性必须被定义在开始标签中
- 属性使用键值对进行定义,例如:name=”value”
lang 属性
HTML 页面所使用的语言可以被定义在 标签中。
使用 lang 属性定义当前 HTML 页面使用的语言。
定义语言对于应用程序的辅助功能(屏幕阅读器)和搜索引擎是很重要的。
<!DOCTYPE html><html lang="en-US"> <body> <h1 id="My-First-Heading">My First Heading</h1> <p>My first paragraph.</p> </body></html>
在上述示例中,前两个字母指的是语言(en),如果有方言,就再使用两个字母(US)。
title 属性
通过
标签定义 HTML 的段落。
在下述示例中,
标签定义了 title 属性,该属性的值为”About W3Schools”:
<p title="About W3Schools">W3Schools is a web developer's site.It provides tutorials and references coveringmany aspects of web programming,including HTML, CSS, JavaScript, XML, SQL, PHP, ASP, etc.</p>
当鼠标移动到
元素上时,title 属性值的内容作为工具提示内容进行显示。
href 属性
通过 标签定义 HTML 的链接,href 属性可以指定链接地址:
<a href="http://www.longestory.com">This is a link</a>
你将在后面的章节中学习到更多有关 标签的内容。
size 属性
通过 标签定义 HTML 的图像。
图像的链接地址(src)图像的大小(width和height)都是 标签的属性:
<img src="/static/imghw/default1.png" data-src="w3schools.jpg" class="lazy" style="max-width:90%" style="max-width:90%" alt="w3schools网站的HTML教程之HTML属性_html/css_WEB-ITnose" >
上述代码中的图像被定义以像素为单位:width=”104” 的意思是宽度为 104 像素。
你将在后面的章节中学习到更多有关 标签的内容。
alt 属性
当一个 HTML 元素无法正确地显示时,alt 属性被用来定义一个提示内容。
该属性的值可以被屏幕阅读器读取。通过这种方式,可以”听”页面,例如一个盲人,可以”听到”元素。
<img src="/static/imghw/default1.png" data-src="w3schools.jpg" class="lazy" alt="W3Schools.com" style="max-width:90%" style="max-width:90%">
建议:尽量使用小写属性
HTML5 的标准并没有规定必须使用小写属性名。
title 属性可以写成大写或者小写,例如 Title 或者 TITLE。
W3C 建议在 HTML4 和像 XHTML 这种严格定义文档类型使用小写。
小写是最常见的,更容易理解的写法。在 W3Schools,我们尽量使用小写的属性名。
建议:属性值尽量使用引号
HTML5 的标准并没有规定属性值必须使用引号。
如上述编写的 href 属性的值,也可以编写成如下形式:
<a href=http://www.w3schools.com>
W3C 建议在 HTML4 和像 XHTML 这种严格定义文档类型使用引号。
有时使用引号是必要的。例如下述示例,由于属性值中包含一个空格,导致将不能正确地显示:
<p title=About W3Schools>
使用引号是最常见的。省略引号会导致错误。在 W3Schools,我们尽量使用引号设置属性值。
单引号还是双引号?
在 HTML 中最常见的是使用双引号,但单引号也可以使用。
在某些情况下,当属性值本身包含双引号时,就必须使用单引号定义属性值:
<p title='John "ShotGun" Nelson'>
或者,也可以这样编写:
<p title="John 'ShotGun' Nelson">
本章小结
- 所有 HTML 元素都具有属性
- title 属性提供用于工具提示的信息
- href 属性提供链接的值信息
- width 和 height 属性提供图像的大小信息
- alt 属性提供屏幕阅读器的内容
- 在 W3Schools,我们尽量使用小写定义 HTML 的属性名
- 在 W3Schools,我们尽量使双引号定义属性值
HTML 的属性
下面的列表是按照字母顺序排列的常见的 HTML 属性:
属性名 | 描述 |
---|---|
alt | 用于指定图像的提示内容 |
disabled | 用于指定输入框不可用 |
href | 用于指定链接的 URL(web地址) |
id | 用于指定一个元素的标识 |
src | 用于指定一个图像的 URL(web地址) |
style | 用于指定一个元素的内联 CSS 样式 |
title | 用于指定一个元素的额外信息(作为工具提示的内容) |
本文翻译于《w3schools》网站提供的 HTML 教程。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...
