font-kerning

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2020 年 1 月⁩ 起,所有主流浏览器均已支持。

font-kerning CSS 属性设置是否使用字体中存储的字偶间距信息。

试一试

font-kerning: auto;
font-kerning: normal;
font-kerning: none;
<section class="default-example" id="default-example">
  <div class="transition-all" id="example-element">
    “We took Tracy to see ‘THE WATERFALL’ in W. Virginia.”
  </div>
</section>
section {
  font-family: serif;
}

字偶间距 影响字母间的间距。在经过良好调整字偶间距的字体中,此功能通过减少某些字符组合之间的空白,使字符间距更均匀、更易于阅读。

例如,在下面的图片中,左侧的示例不使用字偶间距,而右侧的示例使用字偶间距。

Example of font-kerning

语法

css
font-kerning: auto;
font-kerning: normal;
font-kerning: none;

/* Global values */
font-kerning: inherit;
font-kerning: initial;
font-kerning: revert;
font-kerning: revert-layer;
font-kerning: unset;

auto

浏览器决定是否使用字偶间距。例如,某些浏览器会在小字体上禁用字偶间距,因为应用它可能会损害文本的可读性。

normal

必须应用字体中存储的字偶间距信息。

none

字体中存储的字偶间距信息已禁用。

正式定义

初始值auto
应用于所有元素和文本。它也适用于 ::first-letter::first-line
继承性
计算值同指定值
动画类型离散

正式语法

font-kerning = 
auto |
normal |
none

示例

启用和禁用字偶间距

HTML

html
<div id="kern"></div>
<div id="no-kern"></div>
<textarea id="input">AV T. ij</textarea>

CSS

css
div {
  font-size: 2rem;
  font-family: serif;
}

#no-kern {
  font-kerning: none;
}

#kern {
  font-kerning: normal;
}

JavaScript

js
const input = document.getElementById("input");
const kern = document.getElementById("kern");
const noKern = document.getElementById("no-kern");

input.addEventListener("keyup", () => {
  kern.textContent = input.value; /* Update content */
  noKern.textContent = input.value;
});

kern.textContent = input.value; /* Initialize content */
noKern.textContent = input.value;

规范

规范
CSS 字体模块第 4 级
# font-kerning-prop

浏览器兼容性

另见