The font used in the production build of Next.js differs from the font used in the development build

It's evident from the images provided that the font used in my Production Build and Development Build for my Next.js webpage is different. Upon running npm run build and npm start to test the production build, the Montserrat Font disappears from the webpage.

Below is how I imported the font into my globals.scss file. Please let me know if there's an error in my approach:

@tailwind base;
@tailwind components;
@tailwind utilities;

@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;700&display=swap');

html,
body {
  padding: 0;
  margin: 0;
  font-family: 'Montserrat', sans-serif;
  background-color: hsl(265, 3%, 53%);
  color: black;
  &:before{
    content:'';
    content: "";
    width: 100%;
    height: 100vh;
  }
}

Production Build Screenshot:

https://i.sstatic.net/STIIE.png

Development Build Screenshot:

https://i.sstatic.net/i5g6l.png

Answer №1

Enhancing the font across your entire Next.js app for production can be achieved by utilizing a custom Document. For more information, you can refer to this helpful guide as well as this reference.

Here is an example code snippet from the _document.js file:

import Document, { Html, Head, Main, NextScript } from "next/document";

class MyDocument extends Document {
  render() {
    return (
      <Html lang="en">
        <Head>
          <link rel="preconnect" href="https://fonts.gstatic.com" />
          <link
            href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;700;900&display=swap"
            rel="stylesheet"
          />
        </Head>
        <body>
          <Main />
          <NextScript />
        </body>
      </Html>
    );
  }
}

export default MyDocument;

Make sure to include the necessary CSS styles in the globals.css file:

body {
  font-family: "Poppins", sans-serif;
  line-height: 1.5;
}

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

Bootstrap 4 experiences issues with modal dialogs

I am experiencing an issue with my code not working on Bootstrap 4. When I click on the 'overview' button, the page darkens but the dialog does not appear. This functionality worked fine with the old version of Bootstrap. Can someone please assis ...

Guide on implementing the addClass method for a :before pseudo-element when clicked

A custom feature has been developed that allows for a slideDown effect when the title is clicked, revealing a new section. Initially, the title displays a plus symbol to indicate that it can be expanded. However, upon clicking the title, the intention is t ...

Creating a button that seamlessly adapts to all browsers

I am encountering an issue with the positioning of a chat button on my website. Despite my efforts, the button does not remain in the desired location across different browsers and screen resolutions. The browser zoom also causes inconsistencies in the but ...

Leveraging selenium webdriver in python for extracting data from SVG text elements

I'm currently working with Selenium WebDriver (Firefox) to extract information about college courses from a website that features course reviews. Although I've managed to successfully log into the website and access the course info page, I'm ...

Tips for altering value by selecting radio buttons

Currently, I am in the process of developing a website using Adobe Dreamweaver with php. The site includes three buttons that serve as payment method options and act as continue buttons. My goal is to have the selected radio button (I agree button) add a s ...

Unable to adjust the top padding of the navbar to 0 pixels

Having recently started learning HTML and CSS, I am encountering an issue with the padding on my navbar. I am unable to get it to align with the top of the site as there is a persistent space between the navbar and the top. Below is my HTML code: <!do ...

Changing the array in child 2 based on the information provided by child 1

First child possesses an assortment of items Second child must send an item object to the first child for updating its array. What is the method to transmit this item object from the second child to the parent, and then pass it down to the first child. ...

Guide for accessing data in a reusable layout module within Next.js

Currently, I am trying to incorporate slugs into my Header component so that it can be utilized across all pages within the layout: const Layout = ({ children }) => { return ( <> <Header />//////////this one. {children} ...

Using GitHub Releases alongside Vercel: A Step-by-Step Guide

Currently, I am in the process of building an ecommerce platform using Next.js and I am considering deploying it on Vercel. One thing that caught my attention is Vercel's Deploy-Preview-Ship model (DPS), but I am uncertain if this aligns with what I h ...

The video background conceals the presence of the links placed behind

How can I ensure that my links show up in front of the video background rather than behind it? This is the code snippet I am currently working with: <body> <header class="v-header container"> <div class="fullscreen-video-wrap"> <vide ...

Tips for inserting a dropdown arrow below caret on Bootstrap 4

I'm currently utilizing the dropdown feature in Bootstrap 4. My goal is to include an upward arrow for the dropdown menu positioned in the top left corner. In Bootstrap 3, we could utilize caret markup on the button to easily add the arrow to the dr ...

Adding a logo to a website that utilizes CSS, HTML, JS, and Bootstrap

Hey there! I'm new to the world of Front-end development and I've been learning by watching videos and reading everything I can find on the Internet. Currently, I'm using HTML, CSS, and JS for my website. Can anyone help me figure out how to ...

Arranging three section elements side by side

I have encountered an issue where I have 3 consecutive section tags in a row, but when applying margin to them, the last section tag moves to the next line instead of staying on the same line. I attempted using the float:left and display:inline properties ...

How to effectively use jQuery to center images of varying widths horizontally within a div element

Presented below is the div in question: <div id="photos"> <div id="photos_cycle"> <img id="photo" src="{{ asset('bundles/tcheetenweb/images/photos/female_tennis_player.jpg') }}" /> <img id="photo" src="{{ asset(' ...

What steps can I take to stop the window/body from scrolling "through" a modal div?

Let me simplify my layout for you: <body> [... lots of content ...] <div id="modal-overlay"> </div> </body> The body has so much content that the whole page scrolls. The styling for #modal-overlay looks like this: #m ...

What is the best method to obtain the following id for an image?

Whenever I hover over the li with the number 3, I am getting the wrong number for the next id in the img tag. The first time, I get next id = 4 which is incorrect. But on the second hover, I get next id = 0 which is what I actually need. How can I correctl ...

Struggling to toggle the visibility of a table with a button - successfully hiding it, but unable to make it reappear?

I need a button that can toggle (show/hide) a table. Currently, my code hides the table successfully, but it fails to show the table again when I click the button. It seems like there is an issue with refreshing or redirecting after clicking the button for ...

Struggling to create a CSS dropdown menu where the dropdown items refuse to align to the left

I am currently working on creating a dropdown menu to reveal hidden elements on mobile devices such as smartphones. However, I am facing an issue where the child elements of the dropdown menu are appearing to the right of the parent element instead of the ...

Enable access to the child of Lages and apply CSS to disable it

My current code looks something like this: <label for="billing:postcode" class="required"><em>*</em>Zip/Postal Code</label> I am looking to hide the <em> element from displaying using CSS. How can I achieve this with the dis ...

The spin control buttons on the right of the input type=date are not properly aligned vertically

I've encountered an issue while trying to create a date picker using the code below in Chrome version 54. <input type="date"> Here is the CSS I'm using: input { height: 35px; line-height: 35px; box-sizing: border ...