{"id":137704,"date":"2015-02-22T08:00:50","date_gmt":"2015-02-22T13:00:50","guid":{"rendered":"http:\/\/premium.wpmudev.org\/blog\/?p=137704"},"modified":"2022-03-02T04:07:32","modified_gmt":"2022-03-02T04:07:32","slug":"custom-fonts-css","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/custom-fonts-css\/","title":{"rendered":"Adding Custom Fonts to WordPress with @Font-Face and CSS3"},"content":{"rendered":"<p>Whether you&#8217;re creating a new WordPress theme or simply customizing one, custom fonts can help freshen your theme&#8217;s style.<\/p>\n<p>While browsers have built-in default fonts, which you can call in your <em>style.css<\/em> file, using the same fonts everyone else uses can seem a bit dull.<\/p>\n<p>Luckily, adding your own choice of fonts is relatively easy using the CSS3 <code>@font-face<\/code> rule. All that&#8217;s required is uploading a font to your server, then adding it to your theme with a few small snippets of CSS.<\/p>\n<p>Let&#8217;s look at how to do it for your WordPress theme.<\/p>\n<ul>\n<li><a href=\"#find\">Finding a Font<\/a><\/li>\n<li><a href=\"#upload\">Uploading Your Font<\/a><\/li>\n<li><a href=\"#add\">Adding Your Font to Your Theme<\/a><\/li>\n<li><a href=\"#conclusion\">Conclusion<\/a><\/li>\n<\/ul>\n<h2 id=\"find\">Finding a Font<\/h2>\n<p>There are many places to find great web fonts for free such as <a href=\"http:\/\/www.fontsquirrel.com\/\" rel=\"noopener\" target=\"_blank\">FontSquirrel<\/a> or <a href=\"https:\/\/fonts.adobe.com\/\" rel=\"noopener\" target=\"_blank\">Adobe Fonts<\/a>. Just make sure the font you choose has a license suitable to your needs.<\/p>\n<p>Not all free fonts can be used for commercial purposes, but you can buy premium fonts for commercial use from many places such as <a href=\"https:\/\/typekit.com\/\" rel=\"noopener\" target=\"_blank\">Typekit<\/a>.<\/p>\n<p>There are also two main kinds of fonts: Serif and sans-serif. Serif fonts have curls over the edges while sans-serif fonts do not.<\/p>\n<p>This might help you remember the difference between the two font types.<\/p>\n<p>The amusing image below might help you remember the difference between the two types.<\/p>\n<div class=\"td\">\n<figure class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-490x490\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2015\/02\/shot-serif.png\" alt=\"A letter &quot;S&quot; in a serif font with a hole at the part of the top end that is curled over the edge. The caption reads, &quot;I shot the serif.&quot;\" width=\"490\" height=\"312\" \/><figcaption class=\"wp-caption-text\">This joke is a long shot, but hopefully, it works.<\/figcaption><\/figure>\n<\/div>\n<p>Once you have chosen your new font, you need to download its file. Keep in mind that there are different kinds of font files and they aren&#8217;t all compatible across most major browsers.<\/p>\n<p>Here&#8217;s a quick summary of different types of fonts and their file extensions:<\/p>\n<ul>\n<li><strong>TrueType Font (TTF)<\/strong> \u2013 Compatible with Internet Explorer version 9.0 and above, Chrome starting at 4.0, Firefox at 3.5, Safari since 3.1, and Opera beginning with 10.0<\/li>\n<li><strong>OpenType Font (OTF)<\/strong> \u2013 Has the same browser compatibility as the TrueType Font<\/li>\n<li><strong>Web Open Font Format (WOFF)<\/strong> \u2013 Supported by Internet Explorer version 9.0 and above, Chrome starting at 5.0, Firefox at 3.6, Safari since 5.1, and Opera beginning with 11.1<\/li>\n<li><strong>Web Open Font Format 2.0 (WOFF2)<\/strong> \u2013 Supported only by Chrome since version 36.0, Firefox starting at 35.0, and Opera with 26.0<\/li>\n<li><strong>Embedded OpenType Font (EOT)<\/strong> \u2013 Exclusively available for Internet Explorer version 6.0 and above.<\/li>\n<\/ul>\n<p>The Web Open Font Format has become the standard since the fonts are compressed to consume less of your bandwidth and contain extra metadata. Unfortunately, they&#8217;re not always available to download.<\/p>\n<p>If you&#8217;re having trouble finding this kind of file, TrueType and OpenType fonts are more readily available for download and are still great choices.<\/p>\n<h2 id=\"upload\">Uploading Your Font<\/h2>\n<p>Once you&#8217;ve found the font you wish to use and followed your source&#8217;s instructions for downloading the file, it&#8217;s time to upload it to your server. Before you do, it&#8217;s a good idea to backup your entire site before making any changes.<\/p>\n<p>For details on creating a full backup, check out a couple of our other posts: <a href=\"https:\/\/wpmudev.com\/blog\/backup-with-snapshot\/\" target=\"_blank\" rel=\"noopener\">How to Backup Your WordPress Website (and Multisite) Using Snapshot<\/a> and<a href=\"https:\/\/wpmudev.com\/blog\/premium-freemium-wordpress-backup-plugins\/\" target=\"_blank\" rel=\"noopener\"> 7 Top Premium and Freemium WordPress Backup Plugins Reviewed<\/a>.<\/p>\n<p>It&#8217;s best to add it to the folder of your theme, which can be found under <strong>wp-content &gt; themes &gt; your-theme<\/strong>. You could optionally create a &#8220;Fonts&#8221; folder to house your file to keep things organized, especially if you plan on adding more than one font.<\/p>\n<p>Unzip the packaged file and upload the contents to your theme folder.<\/p>\n<p>In cPanel, click the <strong>File Manager<\/strong> button under <strong>Files<\/strong> on the main page. If a pop-up opens, select your site&#8217;s location followed by the <strong>Go<\/strong> button. Navigate to your theme folder and click the <strong>Upload<\/strong> button at the top of the page.<\/p>\n<figure id=\"attachment_137720\" class=\"wp-caption aligncenter\" data-caption=\"true\"><img loading=\"lazy\" decoding=\"async\" class=\"size-ratio-large wp-image-137720\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2015\/02\/upload-file-cPanel-700x295.png\" alt=\"A screenshot of the &quot;Upload Files&quot; page in cPanel. The upload file path is highlighted.\" width=\"700\" height=\"295\" \/><figcaption class=\"wp-caption-text\">You should be able to keep the file permissions to 644 and not run into any issues. If you receive a permission error, try deleting the files and uploading them again with different permissions.<\/figcaption><\/figure>\n<p>Click the <strong>Choose file<\/strong> button on the <strong>Upload Files<\/strong> page and choose the font files from your computer. Once selected and opened, the files will upload automatically without clicking another button on this page.<\/p>\n<p>No matter where you place your font file, you need to remember its file path. It will be listed on this page in bold after the words <strong>Select files to upload to<\/strong>.<\/p>\n<h2 id=\"add\">Adding Your Font to Your Theme<\/h2>\n<p>To allow your uploaded font to actually appear in your theme, you need to call it in your <em>style.css<\/em> file, which you can find under <strong>wp-content &gt; themes &gt; your-theme<\/strong>.<\/p>\n<p>It&#8217;s ideal to create a child theme first so your changes aren&#8217;t lost when your theme rolls out with updates.<\/p>\n<p>If you&#8217;re creating a theme from scratch, this isn&#8217;t usually a problem, but if you&#8217;re editing a pre-existing theme, you can check out a couple of our other posts, <a href=\"https:\/\/wpmudev.com\/blog\/how-to-create-wordpress-child-theme\/\" target=\"_blank\" rel=\"noopener\">How to Create a WordPress Child Theme<\/a> and <a href=\"https:\/\/wpmudev.com\/blog\/easy-child-themes\/\" target=\"_blank\" rel=\"noopener\">How to Automagically Create Child Themes in WordPress<\/a>, for details on how to make a child theme.<\/p>\n<p>In cPanel, select the file, then click the <strong>Edit<\/strong> button at the top of the page. If you haven&#8217;t previously disabled pop-ups, one will appear. If this is the case, click <strong>Go<\/strong> at the bottom.<\/p>\n<p>Copy and paste the following code into the file, ideally, somewhere where fonts are referenced. Make sure there is a line break in between each block of CSS and the code you enter.<\/p>\n<p><span style=\"font-weight: 400;\"><div class=\"gist\" data-gist=\"e54c3ea4af351aece6a33faaf255df8d\" data-gist-file=\"style\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/e54c3ea4af351aece6a33faaf255df8d.js?file=style\">Loading gist e54c3ea4af351aece6a33faaf255df8d<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div><\/span><\/p>\n<p>Don&#8217;t forget to replace the font name with the one you uploaded and update the code to reflect the correct file path.<\/p>\n<p>Add the same CSS code additional times to define bold, italicized, header text and the like, keeping sure you update the file name and path to reflect the purpose of the font.<\/p>\n<p>Finally, define where your font will be used with some more CSS, such as in the example below:<\/p>\n<p><span style=\"font-weight: 400;\"><div class=\"gist\" data-gist=\"747a2cae250560a9818cd93d571c7c1b\" data-gist-file=\"gistfile 1\"><a class=\"loading\" href=\"https:\/\/gist.github.com\/747a2cae250560a9818cd93d571c7c1b.js?file=gistfile+1\">Loading gist 747a2cae250560a9818cd93d571c7c1b<\/a><div class=\"gist-consent-notice\" style=\"display:none\"><p>Please <a href=\"javascript:Cookiebot.renew()\">update your cookie preferences<\/a> to enable preference cookies to view this gist.<\/p><\/div><\/div><\/span><\/p>\n<p>In this example, all paragraph text will use the new (fictitious) font. Once you update this code to your own specifications and save the file, your new font will be viewable on your site.<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>With these instructions, you should be able to add new fonts to your theme without error. Still, there are many plugins that can help you add fonts without any coding if you would prefer an easier solution.<\/p>\n<p>In fact, we already listed the best ones in our post <a href=\"https:\/\/wpmudev.com\/blog\/top-wordpress-custom-fonts-plugins-reviewed\/\" target=\"_blank\">Top WordPress Custom Fonts Plugins Reviewed<\/a>. If you would like a handy guide to choosing the right font, we have a post for that, too: <a href=\"https:\/\/wpmudev.com\/blog\/what-you-know-about-wordpress-typography-is-wrong\/\" target=\"_blank\">Most of What You \u201cKnow\u201d About WordPress Typography is Wrong<\/a>.<\/p>\n<p>For more information on using fonts in WordPress, check out the Codex: <a href=\"http:\/\/codex.wordpress.org\/Playing_With_Fonts\" rel=\"noopener\" target=\"_blank\">Playing with Fonts<\/a>. If you run into troubles adding fonts, <a href=\"https:\/\/wpmudev.com\/forums\/forum\/support#question\" target=\"_blank\" rel=\"noopener\">open a support ticket<\/a> and our support heroes can answer your question lickety-split.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Whether you&#8217;re creating a new WordPress theme or simply customizing one, custom fonts can help freshen your theme&#8217;s style. Luckily, adding your own choice of fonts is relatively easy using CSS.<\/p>\n","protected":false},"author":811449,"featured_media":155208,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[557],"tags":[973],"tutorials_categories":[],"class_list":["post-137704","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","tag-fonts"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/137704","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/811449"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=137704"}],"version-history":[{"count":20,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/137704\/revisions"}],"predecessor-version":[{"id":222655,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/137704\/revisions\/222655"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/155208"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=137704"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=137704"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=137704"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=137704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}