<span> HTML 元素是一个通用的行级容器,本身不具备特殊含义。它可被用于对元素进行编组,以便于添加样式(通过使用 classid 属性),或共享属性值(例如 lang 属性)。该元素仅应在无其他合适语义元素时使用。<span> 与 {{HTMLElement("div")}} 元素非常相似,但是 {{HTMLElement("div")}} 是块级元素,而 <span> 是一个行级元素

{{InteractiveExample("HTML Demo: <span>", "tabbed-shorter")}}

```html interactive-example

Add the basil, pine nuts and garlic to a blender and blend into a paste.

Gradually add the olive oil while running the blender slowly.


```css interactive-example span.ingredient { color: #f00; }

属性

这个元素只包含全局属性

示例

示例 1

HTML

<p><span>一些文本</span></p>

结果

{{EmbedLiveSample('示例_1')}}

示例 2

HTML

<li>
  <span>
    <a href="portfolio.html" target="_blank">查看我的作品集</a>
  </span>
</li>

CSS

li span {
  background: gold;
}

结果

{{EmbedLiveSample('示例_2')}}

技术概要

内容分类 短语内容流式内容
允许的内容 短语内容
标签省略 不允许,开始标签和结束标签都不能省略。
允许的父元素 任何接受短语内容流式内容的元素。
隐含的 ARIA 角色 没有对应的角色
允许的 ARIA 角色 任意
DOM 接口 HTMLSpanElement