aboutsummaryrefslogtreecommitdiff
path: root/files/id/web/css/@font-face/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/id/web/css/@font-face/index.html')
-rw-r--r--files/id/web/css/@font-face/index.html199
1 files changed, 199 insertions, 0 deletions
diff --git a/files/id/web/css/@font-face/index.html b/files/id/web/css/@font-face/index.html
new file mode 100644
index 0000000000..940386b922
--- /dev/null
+++ b/files/id/web/css/@font-face/index.html
@@ -0,0 +1,199 @@
+---
+title: '@font-face'
+slug: Web/CSS/@font-face
+tags:
+ - '@font-face'
+ - At-rule
+ - CSS
+ - CSS Fonts
+ - Fonts
+ - NeedsTranslation
+ - Reference
+ - TopicStub
+ - typography
+translation_of: Web/CSS/@font-face
+---
+<div>{{CSSRef}}</div>
+
+<p><span class="seoSummary">The <strong><code>@font-face</code></strong> <a href="/en-US/docs/CSS">CSS</a> <a href="/en-US/docs/CSS/At-rule">at-rule</a> specifies a custom font with which to display text; the font can be loaded from either a remote server or a locally-installed font on the user's own computer.</span> If the <code>local()</code> function is provided, specifying a font name to look for on the user's computer, and the {{Glossary("user agent")}} finds a match, that local font is used. Otherwise, the font resource specified using the <code>url()</code> function is downloaded and used.</p>
+
+<p>By allowing authors to provide their own fonts, <code>@font-face</code> makes it possible to design content without being limited to the so-called "web-safe" fonts (that is, the fonts which are so common that they're considered to be universally available). The ability to specify the name of a locally-installed font to look for and use makes it possible to customize the font beyond the basics while making it possible to do so without relying on an Internet connection.</p>
+
+<p>It's common to use both <code>url()</code> and <code>local()</code> together, so that the user's installed copy of the font is used if available, falling back to downloading a copy of the font if it's not found on the user's device.</p>
+
+<p>The <code>@font-face</code> at-rule may be used not only at the top level of a CSS, but also inside any <a href="/en-US/docs/Web/CSS/At-rule#Conditional_group_rules">CSS conditional-group at-rule</a>.</p>
+
+<pre class="brush: css no-line-numbers">@font-face {
+ font-family: "Open Sans";
+ src: url("/fonts/OpenSans-Regular-webfont.woff2") format("woff2"),
+ url("/fonts/OpenSans-Regular-webfont.woff") format("woff");
+}</pre>
+
+<h2 id="Syntax">Syntax</h2>
+
+<h3 id="Descriptors">Descriptors</h3>
+
+<dl>
+ <dt>{{cssxref("@font-face/font-display", "font-display")}}</dt>
+ <dd>Determines how a font face is displayed based on whether and when it is downloaded and ready to use.</dd>
+ <dt>{{cssxref("@font-face/font-family", "font-family")}}</dt>
+ <dd>Specifies a name that will be used as the font face value for font properties.</dd>
+ <dt>{{cssxref("@font-face/font-stretch", "font-stretch")}}</dt>
+ <dd>A {{cssxref("font-stretch")}} value. Since Firefox 61 (and in other modern browsers) this also accepts two values to specify a range that is supported by a font-face, for example <code>font-stretch: 50% 200%;</code></dd>
+ <dt>{{cssxref("@font-face/font-style", "font-style")}}</dt>
+ <dd>A {{cssxref("font-style")}} value. Since Firefox 61 (and in other modern browsers) this also accepts two values to specify a range that is supported by a font-face, for example <code>font-style: oblique 20deg 50deg;</code></dd>
+ <dt>{{cssxref("@font-face/font-weight", "font-weight")}}</dt>
+ <dd>A {{cssxref("font-weight")}} value. Since Firefox 61 (and in other modern browsers) this also accepts two values to specify a range that is supported by a font-face, for example <code>font-weight: 100 400;</code></dd>
+ <dt>{{cssxref("@font-face/font-variant", "font-variant")}}</dt>
+ <dd>A {{cssxref("font-variant")}} value.</dd>
+ <dt>{{cssxref("font-feature-settings", "font-feature-settings")}}</dt>
+ <dd>Allows control over advanced typographic features in OpenType fonts.</dd>
+ <dt>{{cssxref("@font-face/font-variation-settings", "font-variation-settings")}}</dt>
+ <dd>Allows low-level control over OpenType or TrueType font variations, by specifying the four letter axis names of the features to vary, along with their variation values.</dd>
+ <dt>{{cssxref("@font-face/src", "src")}}</dt>
+ <dd>
+ <p>Specifies the resource containing the font data. This can be a URL to a remote font file location or the name of a font on the user's computer.</p>
+
+ <p>To provide the browser with a hint as to what format a font resource is — so it can select a suitable one — it is possible to include a format type inside a <code>format()</code> function:</p>
+
+ <pre class="brush: css">src: url(ideal-sans-serif.woff) <strong>format("woff")</strong>,
+ url(basic-sans-serif.ttf) <strong>format("truetype")</strong>;</pre>
+
+ <p>The available types are: <code>"woff"</code>, <code>"woff2"</code>, <code>"truetype"</code>, <code>"opentype"</code>, <code>"embedded-opentype"</code>, and <code>"svg"</code>.</p>
+ </dd>
+ <dt>{{cssxref("@font-face/unicode-range", "unicode-range")}}</dt>
+ <dd>The range of Unicode code points to be used from the font.</dd>
+</dl>
+
+<h3 id="Formal_syntax">Formal syntax</h3>
+
+<pre class="syntaxbox">{{csssyntax}}</pre>
+
+<h2 id="Examples">Examples</h2>
+
+<p>This example simply specifies a downloadable font to use, applying it to the entire body of the document:</p>
+
+<p><a href="https://mdn.mozillademos.org/files/7775/webfont-sample.html">View the live example</a></p>
+
+<pre class="brush: html">&lt;html&gt;
+&lt;head&gt;
+ &lt;title&gt;Web Font Sample&lt;/title&gt;
+ &lt;style type="text/css" media="screen, print"&gt;
+ @font-face {
+ font-family: "Bitstream Vera Serif Bold";
+ src: url("https://mdn.mozillademos.org/files/2468/VeraSeBd.ttf");
+ }
+
+ body { font-family: "Bitstream Vera Serif Bold", serif }
+ &lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+ This is Bitstream Vera Serif Bold.
+&lt;/body&gt;
+&lt;/html&gt;
+</pre>
+
+<p>In this example, the user's local copy of "Helvetica Neue Bold" is used; if the user does not have that font installed (two different names are tried), then the downloadable font named "MgOpenModernaBold.ttf" is used instead:</p>
+
+<pre class="brush: css">@font-face {
+ font-family: MyHelvetica;
+ src: local("Helvetica Neue Bold"),
+ local("HelveticaNeue-Bold"),
+ url(MgOpenModernaBold.ttf);
+ font-weight: bold;
+}
+</pre>
+
+<h2 id="Font_MIME_Types">Font MIME Types</h2>
+
+<table>
+ <thead>
+ <tr>
+ <th>Format</th>
+ <th>MIME type</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>TrueType</td>
+ <td><code>font/ttf</code></td>
+ </tr>
+ <tr>
+ <td>OpenType</td>
+ <td><code>font/otf</code></td>
+ </tr>
+ <tr>
+ <td>Web Open Font Format</td>
+ <td><code>font/woff</code></td>
+ </tr>
+ <tr>
+ <td>Web Open Font Format 2</td>
+ <td><code>font/woff2</code></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Notes">Notes</h2>
+
+<ul>
+ <li>Web fonts are subject to the same domain restriction (font files must be on the same domain as the page using them), unless <a href="/en-US/docs/HTTP_access_control">HTTP access controls</a> are used to relax this restriction.</li>
+ <li><code>@font-face</code> cannot be declared within a CSS selector. For example, the following will not work:
+ <pre class="brush: css; example-bad">.className {
+ @font-face {
+ font-family: MyHelvetica;
+ src: local("Helvetica Neue Bold"),
+ local("HelveticaNeue-Bold"),
+ url(MgOpenModernaBold.ttf);
+ font-weight: bold;
+ }
+}</pre>
+ </li>
+</ul>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('WOFF2.0', '', 'WOFF2 font format')}}</td>
+ <td>{{Spec2('WOFF2.0')}}</td>
+ <td>Font format specification with new compression algorithm</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('WOFF1.0', '', 'WOFF font format')}}</td>
+ <td>{{Spec2('WOFF1.0')}}</td>
+ <td>Font format specification</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('CSS3 Fonts', '#font-face-rule', '@font-face')}}</td>
+ <td>{{Spec2('CSS3 Fonts')}}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+
+
+<p>{{Compat("css.at-rules.font-face")}}</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li><a href="/en-US/docs/WOFF">About WOFF</a></li>
+ <li><a href="https://everythingfonts.com/font-face">Everythingfonts font-face generator</a></li>
+ <li><a class="external" href="http://www.fontsquirrel.com/fontface/generator">FontSquirrel @font-face generator</a></li>
+ <li><a class="external" href="http://hacks.mozilla.org/2009/06/beautiful-fonts-with-font-face/">Beautiful fonts with @font-face</a></li>
+ <li><a class="external" href="http://openfontlibrary.org/">Open Font Library</a></li>
+ <li><a class="external" href="http://caniuse.com/woff">When can I use WOFF?</a></li>
+ <li><a class="external" href="http://caniuse.com/svg-fonts">When can I use SVG Fonts?</a></li>
+ <li><a href="https://coolfont.org">Free Fancy Cool Fonts</a></li>
+</ul>