font
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
font
は CSS の一括指定プロパティで、要素のフォントの様々なプロパティをすべて設定します。また、要素のフォントにシステムフォントを設定することもできます。
試してみましょう
font:
1.2rem "Fira Sans",
sans-serif;
font:
italic 1.2rem "Fira Sans",
serif;
font: italic small-caps bold 16px/2 cursive;
font: small-caps bold 24px/1 sans-serif;
font: caption;
<section id="default-example">
<p id="example-element">
London. Michaelmas term lately over, and the Lord Chancellor sitting in
Lincoln's Inn Hall. Implacable November weather. 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.
</p>
</section>
@font-face {
font-family: "Fira Sans";
src:
local("FiraSans-Regular"),
url("/shared-assets/fonts/FiraSans-Regular.woff2") format("woff2");
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: "Fira Sans";
src:
local("FiraSans-Italic"),
url("/shared-assets/fonts/FiraSans-Italic.woff2") format("woff2");
font-weight: normal;
font-style: italic;
}
section {
margin-top: 10px;
font-size: 1.1em;
}
他の一括指定プロパティ同様、個別の値が指定されなかった場合は、それぞれの初期値が設定されます (おそらく一括指定ではないプロパティを使用して設定された以前の値を上書きします)。 font
によって直接設定できない個別指定の font-size-adjust
, font-kerning
も初期値に設定されます。
構成要素のプロパティ
このプロパティは以下の CSS プロパティの一括指定です。
構文
/* font-size font-family */
font: 1.2em "Fira Sans", sans-serif;
/* font-size/line-height font-family */
font: 1.2em/2 "Fira Sans", sans-serif;
/* font-style font-weight font-size font-family */
font: italic bold 1.2em "Fira Sans", sans-serif;
/* font-stretch font-variant font-size font-family */
font: ultra-condensed small-caps 1.2em "Fira Sans", sans-serif;
/* システムフォント */
font: caption;
font
プロパティはシステムフォントを選択するための単一のキーワード、又は様々なフォント関連プロパティの一括指定のどちらかで指定することができます。
font
をシステムキーワードとして指定する場合は、 caption
, icon
, menu
, message-box
, small-caption
, status-bar
のうちの一つでなければなりません。
font
を様々なフォント関連プロパティの一括指定とする場合は、次のようになります。
-
次の値を含めなければなりません。
-
次の値は任意で含めることができます。
-
font-style
,font-variant
,font-weight
はfont-size
よりも前になければなりません。 -
font-variant
は CSS 2.1 で定義された値、つまりnormal
およびsmall-caps
のみ指定できます。 -
font-stretch
は単一のキーワード値のみを指定することができます。 -
line-height
はfont-size
の直後に、 "/" で区切って、 "16px/3
" のように指定します。 -
font-family
は指定される最後の値である必要があります。
値
<'font-style'>
-
font-style
プロパティを参照。 <'font-variant'>
-
font-variant
プロパティを参照。 <'font-weight'>
-
font-weight
プロパティを参照。 <'font-stretch'>
-
font-stretch
プロパティを参照。 <'font-size'>
-
font-size
プロパティを参照。 <'line-height'>
-
line-height
プロパティを参照。 <'font-family'>
-
font-family
プロパティを参照。
システムフォント値
caption
-
キャプション付きコントロールに使われるシステムフォント (ボタン、ドロップダウンなど)。
icon
-
ラベルアイコンに使用されるシステムフォント。
-
メニューに使われるシステムフォント (ドロップダウンメニュー、メニューリストなど)。
message-box
-
ダイアログボックスに使われるシステムフォント。
small-caption
-
小さいコントロールのラベルに使われるシステムフォント。
status-bar
-
ウィンドウのステータスバーに使われるシステムフォント。
- 接頭辞付きのシステムフォントキーワード
-
ブラウザーは他にも、接頭辞付きのキーワードをいくつか実装していることがあります。 Gecko は、
-moz-window
,-moz-document
,-moz-desktop
,-moz-info
,-moz-dialog
,-moz-button
,-moz-pull-down-menu
,-moz-list
,-moz-field
を実装しています。
公式定義
初期値 | 一括指定の次の各プロパティとして
|
---|---|
適用対象 | すべての要素とテキスト。 ::first-letter および::first-line にも適用されます。 |
継承 | あり |
パーセント値 | 一括指定の次の各プロパティとして
|
計算値 | 一括指定の次の各プロパティとして
|
アニメーションの種類 | 一括指定の次の各プロパティとして
|
形式定義
font =
[ [ <'font-style'> || <font-variant-css2> || <'font-weight'> || <font-width-css3> ]? <'font-size'> [ / <'line-height'> ]? <'font-family'># ] |
<system-family-name>
<font-style> =
normal |
italic |
oblique <angle [-90deg,90deg]>?
<font-variant-css2> =
normal |
small-caps
<font-weight> =
<font-weight-absolute> |
bolder |
lighter
<font-width-css3> =
normal |
ultra-condensed |
extra-condensed |
condensed |
semi-condensed |
semi-expanded |
expanded |
extra-expanded |
ultra-expanded
<font-size> =
<absolute-size> |
<relative-size> |
<length-percentage [0,∞]> |
math
<line-height> =
normal |
<number [0,∞]> |
<length-percentage [0,∞]>
<font-family> =
[ <family-name> | <generic-family> ]#
<system-family-name> =
caption |
icon |
menu |
message-box |
small-caption |
status-bar
<font-weight-absolute> =
normal |
bold |
<number [1,1000]>
<length-percentage> =
<length> |
<percentage>
<family-name> =
<string> |
<custom-ident>+
<generic-family> =
<generic-script-specific> |
<generic-complete> |
<generic-incomplete>
<generic-script-specific> =
generic( fangsong ) |
generic( kai ) |
generic( khmer-mul ) |
generic( nastaliq )
<generic-complete> =
serif |
sans-serif |
system-ui |
cursive |
fantasy |
math |
monospace
<generic-incomplete> =
ui-serif |
ui-sans-serif |
ui-monospace |
ui-rounded
例
フォントのプロパティの設定
/* フォントの大きさを 12px に設定し、行の高さを 14px にする。
フォントファミリは sans-serif に設定する */
p {
font: 12px/14px sans-serif;
}
/* フォントの大きさを親要素の 80% または既定値
(親要素がない場合) に設定する。
フォントファミリは sans-serif に設定する */
p {
font: 80% sans-serif;
}
/* フォントの太さを太字に、
フォントスタイルを斜体に、
フォントの大きさを large に、
フォントファミリーは serif に設定する */
p {
font: bold italic large serif;
}
/* ウィンドウのステータスバーと同じフォントに設定する */
p {
font: status-bar;
}
ライブサンプル
仕様書
Specification |
---|
CSS Fonts Module Level 4 # font-prop |