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











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.

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 roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.
