CSS3

@規則用記述子

src

  編集:2022.07.14 by T.A.

[Edge]△→srcmdn

フォント参照指定。

名前 src
用途 @font-face
<url>#
初期値 なし(必須)
<url>#
<url>=[format(<font-format>)]? [tech(<font-tech>#)]?
| local(<font-face-name>)

カンマで分離された成分値のリストを構文解析する [CSS-SYNTAX-3] アルゴリズムに則って構文解析するものとする。

以下のCSSが組み込んであります:

<SPAN style="font-size:30px;
 font-family:メイリオ;
">ABCabc012T.…あいう</SPAN>
メイリオがインストールしてある場合に表示される

<SPAN style="font-size:30px;
 font-family:Font_url;
">ABCabc012T.…あいう</SPAN>

format()
format(<font-format>)
<font-format>
<string> | collection | embedded-opentype | opentype | svg | truetype | woff | woff2
<string>

以下のCSSが組み込んであります:

<SPAN style="font-size:30px;
 font-family:Font_string;
">ABCabc012T.…あいう</SPAN>

collection
embedded-opentype
opentype
svg
truetype

以下のCSSが組み込んであります:

<SPAN style="font-size:30px;
 font-family:Font_truetype;
">ABCabc012T.…あいう</SPAN>

woff
woff2
tech() [Edge]⛌?
tech(<font-tech>#)
<font-tech>
<font-feature-tech> | <color-font-tech> | variations | palettes | incremental
<font-feature-tech>
<color-font-tech>
variations
palettes
incremental
local()
local(<font-face-name>)
<font-face-name>
¶空白を含む場合はクォーテーションで括ったほうがよい。

以下のCSSが組み込んであります:

<SPAN style="font-size:30px;
 font-family:Font_local;
">ABCabcefghi012T.…あいう</SPAN>

<font-feature-tech>
feature-opentype
| feature-aat
| feature-graphite
feature-opentype
feature-aat
feature-graphite
<color-font-tech>
color-COLRv0
| color-COLRv1
| color-SVG
| color-sbix
| color-CBDT
color-COLRv0
color-COLRv1
color-SVG
color-sbix
color-CBDT
src: url(fonts/simple.woff);   /*  スタイルシートの所在から相対的な "simple.woff" を読み込む  */
src: url(/fonts/simple.woff);  /*  絶対的な所在から "simple.woff" を読み込む  */
src: url(fonts/coll.otc#foo);  /*  コレクション "coll.otc" からフォント "foo" を読み込む  */
src: url(fonts/coll.woff2#foo);/*  WOFF 2 コレクション "coll.woff2" からフォント "foo" を読み込む  */
src: url(fonts.svg#simple);    /*  id に "simple" が付与された SVG フォントを読み込む  */

例えば、増分的な転送(incremental)はサポートされないときは、最適な処理能を得るため、woff2 で圧縮されたバージョンのフォントが給される。それから、クライアントが増分的な転送用に 範囲要請メソッド を利用してバイト範囲要請を遂行できるよう、生の未圧縮な OpenType フォントが供される。

@font-face {
  font-family: "MyIncrementallyLoadedWebFont";
  src: url("FallbackURLForBrowsersWhichDontSupportIncrementalLoading.woff2") format(woff2);
  src: url("MyIncrementallyLoadedWebFont.otf") format(opentype) tech(incremental);
}

可能なら WOFF 2 フォントを読み込んで、他の場合は可能なら WOFF 1 フォントを、他の場合は OpenType フォントを利用する例:

@font-face {
  font-family: bodytext;
  src: url(ideal-sans-serif.woff2) format(woff2),
       url(ideal-sans-serif.woff) format(woff),
       url(basic-sans-serif.ttf) format(opentype);
}

この例では、woff2 がサポートされない場合、未サポートな架空の形式 "zebra" は飛ばされ、opentype フォントがダウンロードされる:

src: url(ideal.woff2) format(woff2),url(unsupported.zeb) format("zebra"),
     url(basic.ttf) format(opentype);

ここでは、いずれかのコレクション内の個々のインスタンスが読み込まれるが、どのコレクションもサポートされない場合、代わりに個々のフォントをダウンロードする:

@font-face {
  font-family: 源ノ角ゴシック Code JP;
  src: url(SourceHanCodeJP.otc#Regular) format(collection),
       url(SourceHanCodeJP-Regular.ttf) format(opentype);
}

テスト
HTML:

ここに表示
HTML:

ここに表示
スクリプト:


スクリプト:



表示内容:
表示内容: