An obstacle with Google fonts in NextJs - Only a single font is appearing

In my NextJs application, I've added a Google Fonts link to the HEAD section of the _app.js file. This link includes two different fonts.

https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;700&family=Poppins:wght@400;700&display=swap

However, when I try to specify these font families in the sass files of my modules, they don't seem to take effect. The webpage continues to display the default browser fonts. How can I solve this issue?

Answer №1

Get the font files by downloading them. There are multiple variations available, so choose the ones you want and then paste them into the "public/fonts" folder.

Afterward, in your main.scss file (or a partial), include it like this:

@font-face {
  font-family: "PressStart2P";
  src: url("/fonts/PressStart2P-Regular.ttf");
  font-weight: normal;
  font-style: italic;
}

Now, you can utilize this font family in your scss code as shown below:

font-family: "PressStart2P";

Answer №2

To get the font family, I recommend downloading them and then using a tool like webfonttools.com to ensure they are compatible with all browsers. Be sure to check the boxes for:

  • TTF
  • EOT
  • WOFF
  • WOFF2

After downloading, you will receive all the fonts along with a @font-face stylesheet that automatically manages the font face declarations. All you need to do is adjust your file paths accordingly.

@font-face {
  font-family: 'Goodtype';
  src: url('../../assets/fonts/Goodtype-Regular.eot');
  src: url('../../assets/fonts/Goodtype-Regular.eot?#iefix')
      format('embedded-opentype'),
    url('../../assets/fonts/Goodtype-Regular.woff2') format('woff2'),
    url('../../assets/fonts/Goodtype-Regular.woff') format('woff'),
    url('../../assets/fonts/Goodtype-Regular.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}
 font-family: "Goodtype", sans-serif; // make sure to include fallback system fonts

Answer №3

To make the necessary changes, simply update the index.js file by deleting any imports or style references related to the font "Inter".

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating boxes with equal heights in HTML and CSS

I have created this menu using a combination of html and css. The layout consists of 3 boxes, each with different content. My goal is to ensure that all boxes are the same height within the design. However, due to specific responsive requirements, I cannot ...

React ensures that the page is not rerendered until after data has been fetched

I am dealing with the following code snippet. This is my React hook: const [isLoading, setIsLoading] = React.useState(true); useEffect(() => { setIsLoading(() => true); // I expect the page to rerender and display loading now. const select ...

Formatting text to automatically continue onto the next line without requiring scrolling through long blocks of

I have a unique Angular project with a terminal interface that functions properly, maintaining a vertical scroll and automatically scrolling when new commands are entered. However, I am struggling to get the text within the horizontal divs to wrap to the ...

React Material UI: utilize the useResizeContainer hook - The main container element of the data grid is currently lacking a specified width

I want to display a table with all columns having the exact summed up width (maybe plus 10px) in a centered parent div. However, I am encountering an error: MUI: useResizeContainer - The parent DOM element of the data grid has an empty width. Please make ...

Endlessly tapping through each tab with no direction

I am attempting to click on all unopened tabs (elements) randomly across this page. While the code below usually does the trick, it sometimes doesn't click on all elements. I suspect that there might be an issue with how it loads indexes or some othe ...

Tips for creating a filter in React JS using checkboxes

In my current situation, I have a constant that will eventually be replaced with an API. For now, it resembles the future API in the following way: const foo = { {'id':1, 'price':200, 'type':1,}, {'id':2, &apo ...

Can a C# application's design be enhanced using CSS?

While I excel at creating computer-based applications in C#, I've found that designing webpages in ASP.net can be a bit challenging. However, the power of CSS in creating stylish buttons and forms is really appealing to me. I recently searched on Goo ...

Customize drawerLabel in React Native based on user's current location

I am facing an issue with my react-native application where I need to dynamically render a menu item based on the user's location. However, since the function that fetches the user location is asynchronous, I am encountering an undefined error. My que ...

Parent div not properly adjusting its height

I am currently working on developing a fluid layout, however I have encountered a minor issue with the height of the container. The outer <div> (highlighted in yellow, ip_A-1) is not adjusting its height according to its child elements. You can view ...

Error encountered in the face api.js source map while executing a React application to identify and track faces through a webcam

I have been attempting to develop a facial recognition application using face-api.js in react js for one of my clients. Despite trying various solutions, I consistently encounter the same error. Here is the code snippet from App.js: insert your modified c ...

Android mobile browser lacks visibility of certain elements

please provide a brief description of the image The issue I am facing is consistent across all mobile browsers, with the exception of Firefox. It also manifests in Windows Chrome devtools mode and when the device toolbar is activated. I came across a sim ...

Add a custom filter to the active route for a stylish look

I am trying to dynamically change the color of elements in my navbar by creating a filter in my typescript code. I have a string with values like 'greyscale(73%) saturate(1400%)'. How can I apply this string to the fa-icon's filter property ...

Tips for hiding the text cursor when using the React Select library's Select component

I need help with removing the blinking text cursor that appears when the Select is focused. Can someone offer guidance on how to achieve this? https://i.sstatic.net/K6fgY.png Below is the code snippet for my select component: <Select options={s ...

Extracting request data from nextjs middleware to pass to page component

After successfully implementing a middleware function in NextJS, I am able to access the geo object and ip string. The geo object contains fields such as country, city, latitude, longitude, and region. Now, I need to integrate this data into my home page c ...

What is causing the restriction in accessing the .map variable outside of the Return function?

I'm currently working on a project that involves rendering dummy shop items using a card component. I have an onClick function called AddToCart, but I'm facing an issue where I can't access the data.price variable from the shopData.map funct ...

Is there a way to set the background of the first sibling element to blue, but change it when another sibling element is hovered over?

I have a list of names: <div>Timothy Gruns</div> <div>Lawrence Fishly</div> <div>Jackson Crolya</div> What I want is for the background color to change to blue when any name is hovered over. However, if no names are be ...

Navigating with Buttons using React Router

Header: I need help figuring out how to properly redirect to a new page when clicking on a Material UI button using the onClick method. Specifically, I am unsure of what to include in my handleClickSignIn function. Here is a snippet of code from my Header ...

Is it possible to alter the color of a selected CheckBox within Material-ui components?

http://www.material-ui.com/#/components/checkbox I have been attempting to modify the style with a color attribute, but haven't had any success so far. I am aware of the checkedIcon property that requires an 'element', however, I am unsure ...

Choose a HTML element <a> containing a hyperlink reference and a nested child element <li>

Does anyone know of a way in javascript/css to select the (n) <li> in my code, while also specifying that the <li> must have a parent with the current <a> tag containing a specific href link? <a href="www.link.com">CATEGORY NAME& ...

The html input box's ability to handle overflow situations

Currently, I am working on creating a form that allows users to update data. <dl> <dt>Medical Needs:</dt> <dd class="med_needs" style="height:60px;overflow:auto"> <input type = "text" id="med_needs"name ="med_nee ...