Aturan font-face

Aturan @font-face memungkinkan untuk menentukan font kustom yang sumbernya disimpan dalam sebuah file. Font ini kemudian dapat dihubungkan menggunakan properti font-family.

Sintaks

css@font-face {
  nama font;
  sumber untuk mencari font;
}

Contoh

Mari kita cari font di komputer lokal kita:

html<body>
  This is Montserrat SemiBold.
</body>
css@font-face {
  font-family: "Montserrat SemiBold";
  src: local("Montserrat SemiBold");
}
  
body {
  font-family: "Montserrat SemiBold";
}

#elem {
  animation: anim 3s infinite;
  border: 1px solid black;
  width: 50px;
  height: 50px;
}

Результат:

Contoh

Dan sekarang mari tentukan alamat server jarak jauh untuk mencari font:

html<body>
  This is Bitstream Vera Serif Bold.
</body>
css@font-face {
  font-family: "Bitstream Vera Serif Bold";
  src: url("https://mdn.github.io/css-examples/web-fonts/VeraSeBd.ttf");
}
  
body {
  font-family: "Bitstream Vera Serif Bold", serif;
}

#elem {
  animation: anim 3s infinite;
  border: 1px solid black;
  width: 50px;
  height: 50px;
}

Результат: