Created: 2012-03-24 03:45
Updated: 2018-09-13 19:49
License: mit


Build Status Coverage Status

Provides a helper for using Google Webfonts with the Ruby programming language.


Add this line to your application's Gemfile:

gem 'google-webfonts'

And then execute:

$ bundle

Or install it yourself as:

$ gem install google-webfonts


include Google::Webfonts::Helper

google_webfonts_link_tag font_name: [weights]


Basic usage:

google_webfonts_link_tag droid_sans: [400, 700], yanone_kaffeesatz: [300, 400]

The weights are optional, and do not have to be in an Array if you are only including one. For example:

# Generate a tag for Droid+Sans without specifying the font weight.
google_webfonts_link_tag :droid_sans

# Generate a tag for Droid+Sans with 400 weight.
google_webfonts_link_tag :droid_sans => 400

# Generate a tag for Droid+Sans with 400 and 700 weights.
google_webfonts_link_tag :droid_sans => [400, 700]

In certain cases it will be necessary to use Strings instead of Symbols for the font names. The helper method titleizes the symbols when converting it to a Google Webfonts compatible name. This does not work for every font name. For example:

# If a Symbol was provided here, the "T" would be lower-case, which would 
# result in an invalid link.
google_webfonts_link_tag 'PT Sans'

Using in Rails

Require the gem like this in your Gemfile when using with Rails:

gem 'google-webfonts', require: 'google/webfonts/rails'

The google_webfonts_link_tag helper method will automatically be available to your views. If you need to use it outside of the views, include this module:

include Google::Webfonts::Helper

Using in Sinatra

Here is a simple "Hello World" example for using Google::Webfonts in a Sinatra app:

# app.rb
require 'rubygems'
require 'sinatra'

# This must be required after requiring sinatra.
require 'google/webfonts/sinatra'

get '/' do
  erb :index

# views/index.erb
    <%= google_webfonts_link_tag "Droid Sans" %>
    <p style="font-family: 'Droid+Sans', sans-serif;">
      Hello World!


After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.


Bug reports and pull requests are welcome on GitHub at

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more