font-optical-sizing

Baseline 已廣泛支援

此功能已經成熟,並可在許多裝置和瀏覽器版本上使用。自 ⁨2020 年 3 月⁩起,它已在各瀏覽器中推出。

font-optical-sizing CSS 屬性設定是否針對在不同大小下檢視文字進行最佳化。

試一試

font-optical-sizing: auto;
font-optical-sizing: none;
<section id="default-example">
  <div id="example-element">
    <h2>Chapter 3</h2>
    <p>
      On this particular Thursday, something was moving quietly through the
      ionosphere many miles above the surface of the planet; several somethings
      in fact, several dozen huge yellow chunky slablike somethings, huge as
      office blocks, silent as birds.
    </p>
  </div>
</section>
@font-face {
  src: url("/shared-assets/fonts/variable-fonts/AmstelvarAlpha-VF.ttf");
  font-family: "Amstelvar";
  font-style: normal;
}

#example-element {
  font-family: "Amstelvar", serif;
  text-align: left;
}

#example-element h2 {
  font-size: 36px;
}

#example-element p {
  font-size: 12px;
}

語法

css
/* keyword values */
font-optical-sizing: none;
font-optical-sizing: auto; /* default */

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

none

瀏覽器不會修改字形的形狀以實現最佳顯示。

auto

瀏覽器將修改字形的形狀以實現最佳顯示。

描述

對於具有光學尺寸可變軸的字型,預設啟用光學尺寸調整。光學尺寸可變軸在 font-variation-settings 中以 opsz 表示。

使用光學尺寸調整時,小文字通常會以更粗的筆畫和更大的襯線呈現,而大文字通常會呈現得更精緻,粗細筆畫之間的對比度更高。

正式定義

初始值auto
應用於所有元素和文字。它也適用於 ::first-letter::first-line
繼承性
計算值同指定值
動畫型別離散

正式語法

font-optical-sizing = 
auto |
none

示例

停用光學尺寸調整

html
<p class="optical-sizing">
  This paragraph is optically sized. This is the default across browsers.
</p>

<p class="no-optical-sizing">
  This paragraph is not optically sized. You should see a difference in
  supporting browsers.
</p>
css
@font-face {
  src: url("AmstelvarAlpha-VF.ttf");
  font-family: "Amstelvar";
  font-style: normal;
}

p {
  font-size: 36px;
  font-family: "Amstelvar", serif;
}

.no-optical-sizing {
  font-optical-sizing: none;
}

注意: 上述引用的字型(包含光學尺寸調整功能並免費許可)非常適合測試。您可以在 GitHub 上下載它

規範

規範
CSS 字型模組第 4 級
# font-optical-sizing-def

瀏覽器相容性

另見