CSS 属性 word-spacing 用于设置单词之间以及标签之间的空格长度。

{{InteractiveExample("CSS 演示:word-spacing")}}

```css interactive-example-choice word-spacing: normal;


```css interactive-example-choice word-spacing: 1rem;

```css interactive-example-choice word-spacing: 4px;


```css interactive-example-choice word-spacing: -0.4ch;

```html interactive-example

As much mud in the streets as if the waters had but newly retired from the face of the earth, and it would not be wonderful to meet a Megalosaurus, forty feet long or so, waddling like an elephantine lizard up Holborn Hill.


```css interactive-example @font-face { src: url("/shared-assets/fonts/variable-fonts/AmstelvarAlpha-VF.ttf"); font-family: Amstelvar; font-style: normal; } section { font-size: 1.2em; font-family: Amstelvar, serif; }

语法

/* 关键字值 */
word-spacing: normal;

/* <length> 值 */
word-spacing: 3px;
word-spacing: 0.3em;

/* 全局值 */
word-spacing: inherit;
word-spacing: initial;
word-spacing: revert;
word-spacing: revert-layer;
word-spacing: unset;

  • normal
    • : 由当前字体或浏览器定义的正常单词间距。
  • {{cssxref("length")}}
    • : 指定在字体所定义的固有单词间距之外,额外增加的间距。

无障碍

较大的正值或负值的 word-spacing 会使应用该样式的句子变得不可读。如果文本使用了非常大的正值,单词之间的间距会被拉得过远,以至于看起来不像是一句话。如果文本使用了很大的负值,则单词之间会相互重叠,以至于无法辨别各单词的开头和结尾。

易读的 word-spacing 必须根据具体情况逐一确定,因为不同的字体族具有不同的字符宽度。没有一个通用的数值能够保证所有字体族都能自动保持良好的可读性。

示例

HTML

<div id="mozdiv1">Lorem ipsum dolor sit amet.</div>
<div id="mozdiv2">Lorem ipsum dolor sit amet.</div>

CSS

#mozdiv1 {
  word-spacing: 15px;
}

#mozdiv2 {
  word-spacing: 5em;
}

{{ EmbedLiveSample('示例') }}

形式定义

{{CSSInfo}}

形式语法

{{CSSSyntax}}