{"id":1961,"date":"2021-12-13T16:06:25","date_gmt":"2021-12-13T16:06:25","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/add-and-use-google-fonts-in-magento-2\/"},"modified":"2025-10-03T13:06:54","modified_gmt":"2025-10-03T07:36:54","slug":"add-and-use-google-fonts-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/add-and-use-google-fonts-in-magento-2\/","title":{"rendered":"How to Add &#038; Use Google Fonts in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento 2&nbsp;store owners may want to get creative with fonts once in a while!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Instead of paying for the fonts library, one can&nbsp;add &amp; use Google fonts in Magento 2&nbsp;store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, your business targets kids, or women, or professionals, you may want to choose the font of your website accordingly for each case.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/fonts.google.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Google fonts<\/a>&nbsp;are readily available and easy to use. Also, they are free of cost and the store owner can choose among thousands of fonts available that will be suitable for their customer base or type of business. Also&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/google-fonts-gdpr-compliant\/\">Google Fonts GDPR compliance<\/a>&nbsp;involves using Google Fonts in a way that adheres to the General Data Protection Regulation (GDPR) guidelines.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, if you are a Magento developer and need fonts other than the default ones to use in your&nbsp;<a href=\"https:\/\/meetanshi.com\/magento-2-extensions.html\" target=\"_blank\" rel=\"noreferrer noopener\">Magento extensions<\/a>&nbsp;or themes, you may use the below solution.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Add &amp; Use Google Fonts in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Put the following code at&nbsp;<em><strong><em><strong>Vendor\\Extension\\View\\frontend\\layout\\default_head_blocks.xml<\/strong><\/em><\/strong><\/em>&nbsp;file or&nbsp;<em><strong><em><strong>Vendor\\Your_Theme\\Magento_Theme\\layout\\default_head_blocks.xml<\/strong><\/em><\/strong><\/em><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n&lt;page xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd\">\n    &lt;head>\n        &lt;link rel=\"stylesheet\" type=\"text\/css\" src=\"https:\/\/fonts.googleapis.com\/css2?family=Open+Sans:ital,wght@0,300;0,400;0,600;0,700;0,800;1,300;1,400;1,600;1,700;1,800\" src_type=\"url\" \/>\n    &lt;\/head>\n&lt;\/page><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can import multiple google fonts by using:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n&lt;page xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd\">\n    &lt;head>\n        &lt;link rel=\"stylesheet\" type=\"text\/css\" src=\"https:\/\/fonts.googleapis.com\/css2?family=Open+Sans:ital,wght@0,300;0,400;0,600;0,700;0,800;1,300;1,400;1,600;1,700;1,800&amp;amp;family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&amp;amp;\" src_type=\"url\" \/>       \n    &lt;\/head>\n&lt;\/page><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">or you can use directly&nbsp;<strong>.phtml<\/strong>&nbsp;file as shown below:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;link rel=\"stylesheet\" href=\"https:\/\/fonts.googleapis.com\/css2?family=Open+Sans:ital,wght@0,300;0,400;0,600;0,700;0,800;1,300;1,400;1,600;1,700;1,800\" rel=\"stylesheet\" \/><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Import multiple google fonts in phtml file<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;link rel=\"stylesheet\" href=\"https:\/\/fonts.googleapis.com\/css2?family=Open+Sans:ital,wght@0,300;0,400;0,600;0,700;0,800;1,300;1,400;1,600;1,700;1,800&amp;amp;family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&amp;amp;\" rel=\"stylesheet\" \/><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once done, you can use the Google fonts like this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"css\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">font-family: 'Roboto'<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it. Let your creative juices flow freely while developing your Magento site, extensions, or themes when it comes to fonts!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Please share the post with the Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn the programmatic method to add &#038; use Google fonts in Magento 2 for better user interface.<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1961","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1961","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1961"}],"version-history":[{"count":8,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1961\/revisions"}],"predecessor-version":[{"id":23076,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1961\/revisions\/23076"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}