文字是網頁最核心內容,透過 CSS 字型與文字屬性,能讓排版更美觀、閱讀體驗更佳。本文系統整理 font 與 text 相關屬性,附上支援度、適用元素、可用值、預設值、繼承性與範例,方便查閱與實作。
font-family: "Microsoft JhengHei", "PingFang TC", sans-serif;normal(預設)、italic(斜體)、oblique(傾斜)font-style: italic;normal(400)、bold(700)、bolder/lighter(相對父元素)、100~900(九級數值)font-weight: 600;xx-small~xx-large)、相對關鍵字(larger/smaller)、長度單位(px、em、rem、pt)、百分比mediumfont-size: 1.2rem;normal、small-caps(小寫轉小型大寫)font-variant: small-caps;順序:font-style → font-variant → font-weight → font-size/line-height → font-family。font-size 與 font-family 為必填。
font: italic small-caps bold 1rem/1.5 "Noto Sans TC", sans-serif;
normal、數值(倍數)、長度、百分比line-height: 1.6;left、right、center、justifytext-align: justify;baseline、top、middle、bottom、sub、super、text-top、text-bottom、長度/百分比vertical-align: middle;none、underline、overline、line-through、blink(已棄用)text-decoration: underline;none、capitalize(首字大寫)、uppercase、lowercasetext-transform: uppercase;normal、長度(可負值)letter-spacing: 0.1em;0text-indent: 2em;熟練這些屬性,即可精準掌控網頁文字表現。建議搭配 rem 單位與系統字體堆疊,打造跨裝置一致的閱讀體驗。