Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use google fonts in a typescript react-app with JSS?

How do I include Google fonts so I can use them in my JSS?

const styles = ({palette, typography}: Theme) => 
  createStyles({
    time: {
      flexBasis: '10%',
      flexShrink: 0,
      fontSize: typography.pxToRem(20)
    },
    guestname: {
      flexBasis: '20%',
      flexShrink: 0,
      fontSize: typography.pxToRem(20),
    }
})
like image 510
crownlessking Avatar asked Oct 31 '25 07:10

crownlessking


1 Answers

Go on fonts.google.com, "select the font(s)" you need. When you are finished, click the @import tab and copy the @import code only:

@import url('https://fonts.googleapis.com/css?family=Montserrat&display=swap');

paste it in your CSS file, e.g. index.css then save.

In your JSS, to use the imported font, do:

const styles = ({palette, typography}: Theme) => 
  createStyles({
    time: {
      flexBasis: '10%',
      flexShrink: 0,
      fontFamily: "'Montserrat', sans-serif", // <-- FONT IS USED HERE
      fontSize: typography.pxToRem(20)
    },
    guestname: {
      flexBasis: '20%',
      flexShrink: 0,
      fontSize: typography.pxToRem(20),
    }
})
like image 196
crownlessking Avatar answered Nov 01 '25 20:11

crownlessking



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!