HTML Attributes

HTML属性提供元素的附加信息,大小写不敏感。关键属性包括:lang用于声明文档语言,对无障碍应用和搜索引擎重要;alt为无法显示的元素提供替代文本,利于屏幕阅读器读取;引号虽非必需,但推荐使用以避免显示错误;单双引号均可,特殊情况下需用单引号包围含双引号的值;W3C推荐HTML4使用小写属性,XHTML则要求必须小写。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 提示框)



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值