DEV Community

Cover image for Adding Custom fonts to Rails6 using webpacker
웃

Posted on • Edited on

1 1

Adding Custom fonts to Rails6 using webpacker

Adding custom fonts to you application stands out and makes a statement. In this article I would like to tell how to import custom fonts into your Rails 6 Application with Webpacker.

  1. Download the font from remote location.
  2. Create a fonts folder in the path app/javascript/ folder.
  3. Create a SASS file fonts.scss and specify location of your font, add import from external urls as well. - I prefer using seperate file for importing all my fonts
app/javascript/stylesheets/fonts/fonts.scss
  @import url('../fonts/harringt.ttf')
Enter fullscreen mode Exit fullscreen mode

Specify the font family in your application.css or specific views of a controller.

app/javascript/stylesheets/pages.css
.page-titles {
  font-family: 'Harrington', cursive;
}
Enter fullscreen mode Exit fullscreen mode

Finally, add CSS class to to sections you want to display in particular font or whole body.

app/views/pages/index.html.erb
<!-- pages/index.html.erb -->

<h1 class="page-titles">Custom Font</h1>
Enter fullscreen mode Exit fullscreen mode

Thats it! You have embedded custom fonts into your Rails application.

Thanks to Font Meme for Harrington font.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay