src
CSS descriptor of the
@font-face
rule specifies the resource containing font data. It is required for the
@font-face
rule to be valid.
/* <url> values */
src: url(https://somewebsite.com/path/to/font.woff); /* Absolute URL */
src: url(path/to/font.woff); /* Relative URL */
src: url(path/to/font.woff) format("woff"); /* Explicit format */
src: url('path/to/font.woff'); /* Quoted URL */
src: url(path/to/svgfont.svg#example); /* Fragment identifying font */
/* <font-face-name> values */
src: local(font); /* Unquoted name */
src: local(some font); /* Name containing space */
src: local("font"); /* Quoted name */
/* Multiple items */
src: local(font), url(path/to/font.svg) format("svg"),
url(path/to/font.woff) format("woff"),
url(path/to/font.otf) format("opentype");
<url> [ format( <string># ) ]?
<url>
, followed by an optional hint using the
format()
function to describe the format of the font resource referenced by that URL. The format hint contains a comma-separated list of format strings that denote well-known font formats. If a user agent doesn't support the specified formats, it skips downloading the font resource. If no format hints are supplied, the font resource is always downloaded.
<font-face-name>
local()
function, which uniquely identifies a single font face within a larger family. The name can optionally be enclosed in quotes.
The value of this descriptor is a prioritized, comma-separated list of external references or locally-installed font face names. When a font is needed the 用户代理 iterates over the set of references listed using the first one it can successfully activate. Fonts containing invalid data or local font faces that are not found are ignored and the user agent loads the next font in the list.
As with other URLs in CSS, the URL may be relative, in which case it is resolved relative to the location of the style sheet containing the
@font-face
rule. In the case of SVG fonts, the URL points to an element within a document containing SVG font definitions. If the element reference is omitted, a reference to the first defined font is implied. Similarly, font container formats that can contain more than one font load only one of the fonts for a given
@font-face
rule. Fragment identifiers are used to indicate which font to load. If a container format lacks a defined fragment identifier scheme, a simple 1-based indexing scheme (e.g., "font-collection#1" for the first font, "font-collection#2" for the second font, etc.) is used.
| 相关 at-rule |
@font-face
|
|---|---|
| 初始值 |
n/a (required)
|
| 计算值 | 如指定 |
[ <url> [ format( <string># ) ]? | local( <family-name> ) ]#where
<family-name> = <string> | <custom-ident>+
@font-face {
font-family: examplefont;
src: local(Example Font),
url('examplefont.woff') format("woff"),
url('examplefont.otf') format("opentype");
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
CSS Fonts Module Level 3
The definition of 'src' in that specification. |
候选推荐 | 初始定义 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
src
|
Chrome 完整支持 4 | Edge 完整支持 12 | Firefox 完整支持 3.5 | IE 完整支持 6 | Opera 完整支持 10 | Safari 完整支持 3.1 | WebView Android 完整支持 2.2 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 10.1 | Safari iOS 完整支持 3.1 | Samsung Internet Android 完整支持 1.0 |
支持
format
关键词
|
Chrome 不支持 No | Edge 不支持 No | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 完整支持 4 | WebView Android 不支持 No | Chrome Android 不支持 No | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 完整支持 5 | Samsung Internet Android 不支持 No |
完整支持
不支持
font-display
font-family
font-stretch
font-style
font-weight
font-variant
font-feature-settings
font-variation-settings
unicode-range
font
font-family
font-feature-settings
font-kerning
font-language-override
font-optical-sizing
font-size
font-size-adjust
font-smooth
font-stretch
font-style
font-synthesis
font-variant
font-variant-alternates
font-variant-caps
font-variant-east-asian
font-variant-ligatures
font-variant-numeric
font-variant-position
font-variation-settings
font-weight
line-height
line-height-step