How can I change the Bootstrap default font family using font from Google?
Swiftly switch to a Google Font from Bootstrap's default by plugging the font's link into your HTML and overriding Bootstrap's font in CSS:
Update 'Oswald'
with your choice of Google Font. Be sure to flex the power of !important
to bully Bootstrap rules into submission.
Moreover, if you plan to use various font weights, specify them in the URL parameters of the <link>
or @import
statement.
Deep dive
Refined look with Sass
Sass is a tool that brings some order to the sometimes chaotic world of CSS. It allows overwriting Bootstrap's variables in a neat way:
For seamless Sass customization, reference _variables.scss
. Use a compiler like gulp-sass
to sew together a well-tailored, optimized stylesheet.
CSS Closet Organization
Organization, my friend, is key. Maintain your styling in a separate custom.css
or custom.scss
file:
Link the _custom_compiled.css
in your HTML header, right after the Bootstrap CSS.
Twisting knobs with CSS Variables in Bootstrap 5
Bootstrap 5 brought a new toy - CSS variables for easier theming. Here's how you set Oswald as the fashion statement:
Bootstrap's official documentation is your guide to mastering CSS variables.
Import medicine and optimization tips
<link> vs @import
When it comes to pulling Google Fonts off the rack, the <link>
tag beats @import
at the performance game - owing to parallel loading:
However, @import
carries the day in case your CSS or Sass files deeply desire a single roof:
Swift font delivery
Whilst defining font families and weights, employ font-display strategies, and only call for necessary font weights. You don't want an overweight font slowing down your site now, would you?
Was this article helpful?