官术网_书友最值得收藏!

Adding custom fonts to AMP pages

One important aspect of web page design that we haven't looked at yet is the use of custom fonts. Not only is the choice of font important to the reading experience, but fonts can help differentiate a web page and give it its own identity. The fonts you choose for your web pages will be largely dictated by your personal preference and the theme of your website, so we won't make any font recommendations here. Rather, we'll demonstrate how you can get your preferred fonts to display, and leave the choice up to you.

There is already a range of web-safe fonts available on most systems. These include:

  • Arial/Helvetica
  • Courier/Courier New
  • Georgia
  • Times/Times New Roman
  • Trebuchet MS
  • Verdana

For many web pages, this will be enough to provide a decent reading experience, so you don't necessarily need to include any other fonts. Custom fonts are desirable in many cases, however, so let's see how to add them to AMP pages.

AMP doesn't permit the inclusion of external stylesheets in your markup, so the use of <link rel="stylesheet" ... > is generally banned, except for fonts. Custom fonts can be loaded in two ways:

  1. Using <link rel="stylesheet"...>:
<link  rel="stylesheet">

Note that in this approach you may only include fonts from the following whitelisted providers:

  1. Using @font-face in your <style amp-custom> CSS, for example:
<style amp-custom>
@font-face {
font-family: "Ubuntu";
src: url("http://example.com/fonts/ubuntu.woff")
format('woff');
}
body {
font-family: "Ubuntu", serif;
}
</style>

 

Note that fonts included with @font-face must include the URL scheme http or https.

Google has a very nice font picker at https://fonts.google.com/. You can use it to choose a font and it will give you the code you need to include in your page, ensuring that your page will still validate.

主站蜘蛛池模板: 鹿邑县| 长葛市| 彭阳县| 科尔| 梅州市| 天镇县| 纳雍县| 贵溪市| 壶关县| 荆门市| 林甸县| 陆良县| 封丘县| 丰台区| 安岳县| 辽宁省| 中西区| 泰宁县| 武功县| 岢岚县| 响水县| 温州市| 新昌县| 萝北县| 威海市| 宁国市| 聂拉木县| 青冈县| 前郭尔| 隆昌县| 辉县市| 罗山县| 沾化县| 游戏| 高尔夫| 荥经县| 南昌市| 霍林郭勒市| 凌云县| 山东省| 平阴县|