<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Harris Reynolds</title>
    <description>The latest articles on DEV Community by Harris Reynolds (@harrisreynolds).</description>
    <link>https://dev.to/harrisreynolds</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F719045%2Fdf9f7f56-3e08-4129-bd18-61d48eb2c597.jpeg</url>
      <title>DEV Community: Harris Reynolds</title>
      <link>https://dev.to/harrisreynolds</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/harrisreynolds"/>
    <language>en</language>
    <item>
      <title>Find and Save New Fonts with the Google Fonts Explorer</title>
      <dc:creator>Harris Reynolds</dc:creator>
      <pubDate>Tue, 16 May 2023 18:01:22 +0000</pubDate>
      <link>https://dev.to/harrisreynolds/find-and-save-new-fonts-with-the-google-fonts-explorer-j7g</link>
      <guid>https://dev.to/harrisreynolds/find-and-save-new-fonts-with-the-google-fonts-explorer-j7g</guid>
      <description>&lt;p&gt;Font selection is a fun part of building a website or application, but it isn't always easy to find new and interesting fonts with a platform like Google Fonts.&lt;/p&gt;

&lt;p&gt;There are &lt;strong&gt;one thousand, five hundred and twenty-one&lt;/strong&gt; fonts in their collection!&lt;/p&gt;

&lt;p&gt;So I decided to build a &lt;a href="https://www.webase.com/google-fonts-explorer"&gt;Google Fonts Explorer&lt;/a&gt; to make it easy to find new fonts that I like.&lt;/p&gt;

&lt;p&gt;Here's how I built it and what its key features are.&lt;/p&gt;

&lt;p&gt;A full list of all of the Google fonts is &lt;a href="https://developers.google.com/fonts/docs/developer_api"&gt;available via their api here&lt;/a&gt; as JSON.&lt;/p&gt;

&lt;p&gt;Load up the JSON in Javascript and render the available fonts in a list within a HTML page.&lt;/p&gt;

&lt;p&gt;Using a JS framework like Vue or React you can easily display the list of available fonts.&lt;/p&gt;

&lt;p&gt;Next let's write a handler that can load a font into the current page.&lt;/p&gt;

&lt;p&gt;Add a click handler to each element that is responsible for rendering the font family.&lt;/p&gt;

&lt;p&gt;Here's a couple Javascript functions that show how I did this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;injectFont(font) {
    let weights = this.availableWeights(font)
    let url = 'https://fonts.googleapis.com/css2?family=' + font.family + weights
    let link = document.createElement("link");
    link.href = url;
    link.rel = "stylesheet";
    document.getElementsByTagName("head")[0].appendChild(link);                
}

availableWeights(font) {
  let weights = font.variants.filter(variant =&amp;gt; variant.indexOf('italic') &amp;lt; 0).join(';')
    weights = weights.replace('regular', '400')
    return `:wght@${weights}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will make the font you click available to the current page by injecting the stylesheet link for the Google font into the head element of the page.&lt;/p&gt;

&lt;p&gt;Lastly you can dynamically change the font of any element on the page with a bit of code like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const displayElements = document.querySelectorAll(".display-element");
displayElements.forEach((displayElement) =&amp;gt; displayElement.style.fontFamily = selectedFont.family)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is just a high-level overview of how you can build a Google Fonts Explorer.  If you are interested you can just view the full source on the page I linked to above to see all the gritty details!&lt;/p&gt;

&lt;p&gt;The public version I linked to includes a few advanced features that make it super fast to explore fonts and save them.&lt;/p&gt;

&lt;p&gt;You can use the filters and the up and down arrow keys to narrow down your search and then quickly iterate over them.&lt;/p&gt;

&lt;p&gt;As you find fonts you like you can save your favorites (sign in required).&lt;/p&gt;

&lt;p&gt;I hope you enjoyed the article and that you find the &lt;a href="https://www.webase.com/google-fonts-explorer"&gt;Google Fonts Explorer&lt;/a&gt; useful.&lt;/p&gt;

&lt;p&gt;Feel free to hit me with questions or feedback!&lt;/p&gt;

</description>
      <category>design</category>
      <category>html</category>
      <category>css</category>
    </item>
  </channel>
</rss>
