ScandiPWA
Create Magento AppCreate ScandiPWA AppUser ManualGitHub
  • Why Scandi
  • πŸš€Quick-start Guide
  • πŸ—ΊοΈRoadmap
  • Introduction to the Stack
    • CMA, CSA, and ScandiPWA
    • Challenges
  • Setting up Scandi
    • Storefront Mode Setup
      • Proxying requests to server
    • Magento Mode Setup
    • Existing Magento 2 setup
    • Magento Commerce Cloud setup
    • Updating to new releases
      • Storefront mode upgrade
      • Magento mode upgrade
      • CMA upgrade
      • CSA upgrade
      • Custom ScandiPWA composer dependency update
      • Local ScandiPWA Composer Package Setup
    • Docker Setup [deprecated]
      • Legacy Docker setup
      • Migrating to CMA & CSA
  • Developing with Scandi
    • Override Mechanism
      • Overriding JavaScript
        • Overriding classes
        • Overriding non-classes
      • Overriding Styles
      • Overriding the HTML / PHP
      • Parent Themes
    • Extensions
      • Creating an extension
      • Installing an extension
      • Migrating from 3.x to 4.x
      • Publishing an extension
      • Extension Terminology
    • Working With Magento
      • Magento troubleshooting
      • Working with Magento modules
      • Working with GraphQL
      • GraphQL Security
      • Working with "granular cache"
    • Developer Tools
      • Debugging in VSCode
      • ScandiPWA CLI
      • Configuring ESLint
      • CSA Commands
    • Deploying Your App
      • Build & Deploy Android app
      • Build & Deploy iOS app
  • Structure
    • Directory Structure
    • Building Blocks
      • Components
        • Styling Components
      • Routes
      • Redux Stores
      • GraphQL Queries
      • Global Styles
      • The Util Directory
      • Type Checking
    • Application assets
    • Code Style
      • JavaScript Code Style
      • SCSS Code Style
  • Tutorials
    • Customizing Your Theme
      • Styling
        • Customizing the Global Styles
        • Adding a New Font
        • Overriding a Components Styles
        • Extending a Component's Styles
      • Customizing JavaScript
        • Customizing the Footer Copyright
        • Adding a New Page
        • Adding a Section in My Account
        • Adding a Tab on the Product Page
        • Creating a New Redux Store
    • Payment Method Integration
      • Setting Up for Development
      • Redirecting to the Payment Provider
      • Handling the Customer's Return
    • Creating a Custom Widget
      • Scandi CMS System Overview
      • Creating a Magento Widget
      • Implementing the Rendering
    • Video Tutorials
      • #1 Setting up and talking theory
      • #2 Templating in React
      • #3 Overriding a file
      • #4 Styling the application
      • #5 Patterns of ScandiPWA
    • Dark Mode Extension
    • Deploying Native Apps
    • Product 3D Model Extension
      • Part 1: Magento 3D Model Uploads
      • Part 2: GraphQL API
      • Part 3: Scandi Frontend
    • Social Share, Full Extension Development
      • STEP-1 and 2 Creating Magento 2 Module
      • STEP-3 Backend Configurations Settings
      • STEP-4 Simple GraphQl and Resolver
      • STEP-5 Creating Extension, Base Redux Store
      • STEP-6 Extension plugins
      • STEP-7 GraphQL types, Helpers
      • STEP-8 Query Field and FieldList
      • STEP-9 render Plugins and MSTP Plugin, Component creation
      • STEP-10 SocialShare Component Development
      • STEP-11 SocialShare for CategoryPage
      • TASK-1 Changing LinkedIn to Twitter
      • STEP-12 Comments for Admin Users
      • STEP-13 Final, bugfixes
    • Accessing Magento 2 Controllers
      • STEP-1 Creating Magento 2 Module
      • STEP-2 - Create Magento 2 Frontend Route and Basic Controller
      • STEP-3 Accessing Magento 2 Controller, Bypassing ScandiPWA frontend
      • STEP-4 Creating ScandiPWA Extension with additional dependencies
      • STEP-5 Creating Plugin and Axios request
  • About
    • Support
    • Release notes
    • Technical Information
    • Data Analytics
    • Contributing
      • Installation from Fork
      • Repository structure
      • Code contribution process
      • Submitting an Issue
      • Publishing ScandiPWA
Powered by GitBook
On this page

Was this helpful?

  1. Tutorials
  2. Customizing Your Theme
  3. Styling

Adding a New Font

Learn to add and use new assets in Scandi

PreviousCustomizing the Global StylesNextOverriding a Components Styles

Last updated 3 years ago

Was this helpful?

You can add fonts in the src directory. When you reference them with url in your style sheets, they will be resolved and bundled with your application. Let's go through an example.

You can find fonts in , , or .

In our case, it is best to into the woff format, which is optimized for the web. See .

Suppose you have decided to use the . Convert them into the Woff and Woff2 formats. Then, put them in the src/style/fonts directory. Any directory under src would work, but it makes sense to store them in their own directory along with styles. Verify that your fonts are where you expect:

$ ls src/style/fonts/
sourcesanspro-regular-webfont.woff  sourcesanspro-regular-webfont.woff2
staatliches-regular-webfont.woff    staatliches-regular-webfont.woff2

However, they are still not imported in our styles. To actually include them into the page, create a new file, namedsrc/style/base/_font.scss, for example. First, we will need to declare the font faces:

src/style/base/_font.scss
@font-face {
    font-family: 'Staatliches';
    src: url(/style/fonts/staatliches-regular-webfont.woff2) format('woff2'),
    url(/style/fonts/staatliches-regular-webfont.woff) format('woff');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'SourceSansPro';
    src: url(/style/fonts/sourcesanspro-regular-webfont.woff2) format('woff2'),
    url(/style/fonts/sourcesanspro-regular-webfont.woff) format('woff');
    font-weight: normal;
    font-style: normal;
}

For convenience, let's also define SCSS variables to refer to these fonts:

src/style/base/_font.scss
$font-staatliches: 'Staatliches', sans-serif;
$font-source-sans-pro: 'SourceSansPro', sans-serif;

Now, we have told the browser that these fonts exist and where to find them. However, they aren't actually being used anywhere. Let's use the Staatliches font for headings, and the Source Sans font for everything else:

src/style/base/_font.scss
body {
    font-family: $font-source-sans-pro;
}

h1, h2, h3, h4, h5, h6 {
    font-family: $font-staatliches;
}

One final change is needed - to actually include the _font.scss file as part of the styles. We can do so by importing it in src/style/main.scss (override the file if you don't already have it in your code). In the last lines of main.scss, add:

src/style/main.scss
@import './base/font';

Note: it is important that this import occurs after the import of base/_reset.scss, since, in the base theme, this is where the body font is set.

We can now refresh the page to see that the fonts have been updated:

Exercise: Try adding a new font and assigning it to some text! Be careful though - the more fonts you add, the less consistent the user interface looks. Besides, each additional font needs to be loaded into the browser.

Font squirrel
dafont.com
Everything Fonts
Google Fonts
convert your fonts
this article for more details
Staatliches and Source Sans Pro fonts
Result: fonts updated!