<-- Back

How to install a custom font family in a Mendix application?

Introduction

This article covers all the steps needed to install a custom font family in a Mendix application.

Environment

Studio Pro v9.24.0 and newer

Instructions/Procedure

The following steps outline how to import and install font files locally:

  1. Create a new module and mark it as a UI Resources module. For the purposes of this article, the module will be referred to as UIResourcesTest:

    image.png
  2. In your project directory, navigate to themesource\uiresourcestest\public and create a folder called fonts. In the fonts folder, place the font files of the custom font (SonnenText for the purposes of this article):

  3. Navigate to themesource\uiresourcestest\web and create a folder called base. In the base folder, create a typography.scss SASS file with the following content describing the font files from step 2 (in this example .otf files):

    /* 
    ========================================================================== 
    * Imports - Font imports 
    ========================================================================== 
    */ 
    
    //-- Patron (headlines and statements) 
    @font-face { 
        font-family: "SonnenText"; 
        src: url("fonts/SonnenText-Bold-2.otf") format("opentype"); 
        font-weight: bold; 
        font-style: normal; 
    } 
    
    @font-face { 
        font-family: "SonnenText"; 
        src: url("fonts/SonnenText-Light-2.otf") format("opentype"); 
        font-weight: light; 
        font-style: normal; 
    } 
    
    @font-face { 
        font-family: "SonnenText"; 
        src: url("fonts/SonnenText-Regular-2.otf") format("opentype"); 
        font-weight: normal; 
        font-style: normal; 
    }
  4. Navigate back to themesource\uiresourcestest\web, and import the newly created typography.scss file into the existing main.scss file:

    image (58).png
    @import '../../../theme/web/custom-variables'; 
    @import 'base/typography'; 
  5. Navigate to theme\web and in the existing custom-variables.scss file, edit $font-family-base to specify the newly created font family from the typography.scss file so that it includes the new custom font first, and thereafter the other fonts to be used as fallbacks.

    $font-family-base: "SonnenText", "Open Sans", sans-serif;
  6. Press F4 in Studio Pro to Synchronize App Directory.
  7. Deploy the application.

Outcome

Following the steps listed above should result in the new custom font family being shown in the application:

Internal information related

213701

Additional information

Have more questions? Submit a request

0 Comments

Article is closed for comments.

To provide feedback, please open a ticket here. Don't forget to include the article's URL along with the feedback you would like to provide.