Jump to content

What's the easiest way to use google font when using Gatsby JS?

mrchow19910319
Go to solution Solved by mrchow19910319,

solved it:

 

googleFonts={name: 'Montserrat', styles: [ '100', '300', '400' ] }

 

I am using Gatsby JS to build myself a blog.

I am wondering, What's the easiest way to use google font when using Gatsby JS?

 

I *think* there are a few ways of doing that,

 

  • adding it to react helmet
  • adding it to typography.js
  • etc

Also I got syntax error whenever I add this into my typography.js file: 

 

//customize fonts here:


// set default font size to 16 px
import Typography from "typography";  
const typography = new Typography({ 
  baseFontSize: "16px",
  googleFonts:[
    name: 'Montserrat',
    styles: [
      '100',
      '300',
      '400'
    ],
  ]

});  
export default typography;

its on the line: name:'Montserrat'

I dont know how to fix it.

If it is not broken, let's fix till it is. 

Link to comment
Share on other sites

Link to post
Share on other sites

Not an answer but is there any reason you are adding the font with JS, instead of CSS?

Isnt css used for fonts and styling?

I only see your reply if you @ me.

This reply/comment was generated by AI.

Link to comment
Share on other sites

Link to post
Share on other sites

I believe you don't need the comma

const typography = new Typography({ 
  baseFontSize: "16px",
  googleFonts:[
    name: 'Montserrat',
    styles: [
      '100',
      '300',
      '400'
    ], <-- here
  ]

});

 

Edited by BobVonBob
Nevermind you do

¯\_(ツ)_/¯

 

 

Desktop:

Intel Core i7-11700K | Noctua NH-D15S chromax.black | ASUS ROG Strix Z590-E Gaming WiFi  | 32 GB G.SKILL TridentZ 3200 MHz | ASUS TUF Gaming RTX 3080 | 1TB Samsung 980 Pro M.2 PCIe 4.0 SSD | 2TB WD Blue M.2 SATA SSD | Seasonic Focus GX-850 Fractal Design Meshify C Windows 10 Pro

 

Laptop:

HP Omen 15 | AMD Ryzen 7 5800H | 16 GB 3200 MHz | Nvidia RTX 3060 | 1 TB WD Black PCIe 3.0 SSD | 512 GB Micron PCIe 3.0 SSD | Windows 11

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, BobVonBob said:

I believe you don't need the comma


const typography = new Typography({ 
  baseFontSize: "16px",
  googleFonts:[
    name: 'Montserrat',
    styles: [
      '100',
      '300',
      '400'
    ], <-- here
  ]

});

 

nope still gives out same error

If it is not broken, let's fix till it is. 

Link to comment
Share on other sites

Link to post
Share on other sites

Okay got it, I believe the correct syntax is

const typography = new Typography({ 
  baseFontSize: "16px",
  googleFonts:[
    { //wrap in braces
      name: 'Montserrat',
      styles: [
        '100',
        '300',
        '400',  //bonus comma here
      ],
    },  //why does this syntax have so many commas
  ],
});

 

Edited by BobVonBob
fix

¯\_(ツ)_/¯

 

 

Desktop:

Intel Core i7-11700K | Noctua NH-D15S chromax.black | ASUS ROG Strix Z590-E Gaming WiFi  | 32 GB G.SKILL TridentZ 3200 MHz | ASUS TUF Gaming RTX 3080 | 1TB Samsung 980 Pro M.2 PCIe 4.0 SSD | 2TB WD Blue M.2 SATA SSD | Seasonic Focus GX-850 Fractal Design Meshify C Windows 10 Pro

 

Laptop:

HP Omen 15 | AMD Ryzen 7 5800H | 16 GB 3200 MHz | Nvidia RTX 3060 | 1 TB WD Black PCIe 3.0 SSD | 512 GB Micron PCIe 3.0 SSD | Windows 11

Link to comment
Share on other sites

Link to post
Share on other sites

solved it:

 

googleFonts={name: 'Montserrat', styles: [ '100', '300', '400' ] }

 

If it is not broken, let's fix till it is. 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×