"Customizing the website's font: A step-by-step guide to replacing the default Roboto font with a custom font

Despite my efforts to globally override the font, I am still encountering instances where the Roboto font is not being replaced, particularly on MUI select and autocomplete components.

import { createTheme } from '@material-ui/core/styles';

// A customized theme for this application
const theme = createTheme({
  typography: {
    fontFamily: [
      'DM Sans',
      'sans-serif',
    ].join(','),
  },
  components: {
    MuiCssBaseline: {
      styleOverrides: `
        @font-face {
          font-family: 'DM Sans', sans-serif;
          font-style: normal;
          font-display: swap;
          font-weight: 400;
          src: url(https://fonts.googleapis.com/css2?family=DM+Sans) format('woff2');
          unicodeRange: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF;
        }
      `,
    },
  },
});

export default theme;

Answer №1

If you're struggling with setting up a font in your MUI theme, check out this informative post that not only explains the process but also provides an example of how to set it in a specific component.

Don't forget to inspect the element that's not displaying the Roboto font properly to identify what might be causing the issue.

I hope this information proves to be helpful for you!

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

Can a piece of code be created that generates the XPath for a specific element?

I'm interested in finding out if there is a way to automatically generate an XPath by simply selecting an element, eliminating the need for manual updates when changes occur in HTML files on websites. I welcome any suggestions or alternatives that can ...

Removing the displayed image chips from the database using reactjs

How can I remove an image chip displayed from the database? Here is the code for displaying images from the database: {user.isImageUploaded != null ? <div > <p> {user.isImageUploaded.map(item => { const datatypeV ...

The primary text in the MUI ListItem exceeds the secondary action of the ListItem

I am currently using MUI (v5) List component. My list is quite simple, with each item having text on the left and a value on the right. The issue arises when the list's width shrinks as the window size decreases. The text on the left (<ListItemTe ...

Encountering an E401 error code following the execution of the 'npm install' command

I'm currently attempting to duplicate a ReactJs project using git clone. However, upon opening the project in VS CODE and running 'npm install,' I encountered an E401 error with the message below: npm ERR! code E401 npm ERR! Unable to authen ...

Tips for making a Bootstrap dropdown submenu appear as a 'dropup'

I'm using a Bootstrap dropdown menu with a submenu that should drop upwards while the rest of the menu drops down. How can I achieve this? Here is the code snippet: <div class="dropdown"> <a class="inputBarA dropdown-toggle" data-toggle= ...

Tips for converting a number into a percentage with two decimal places using FormatJs Message Syntax

With the react-intl library, I am encountering a message that looks like this: serviceFee: { en: 'Service fee: ({fee, number, percent})', ... }, Upon calling <FormatMessage id="serviceFee" values={{ fee: 0.0625 }} /> I anticipate th ...

What is the impact of a floated element on vertical spacing?

I have come across an article discussing the usage of CSS, but I am puzzled as to why image number four is not positioned below image number one. Instead, it appears below image number three. Can someone please explain this to me? Here is the HTML code sni ...

The problem with "em" in CSS: preventing it from scaling based on the font-size of a particular element

My website predominantly utilizes "em" for design over "px," which is meant to be more compatible with modern browsers. Most of the text is set at font-size:1em, where 1em equals 16px as a default without specific specification. However, there are sectio ...

Apply border-radius to Bar when using recharts

Having trouble with the BarChart Stacked component from Recharts. I'm trying to eliminate the empty space between these two bars. https://i.stack.imgur.com/uICnZ.png Attempting conditional rendering with the Cell component, but unfortunately no radi ...

What are some ways I can adjust line-height without changing the height of the cursor?

When working in a contenteditable div, I am utilizing line-height to create some spacing between lines. The following example illustrates the issue: <div style="padding: 50px; width: 90px; line-height: 2em;" contenteditable="true"> line height lin ...

When incorporating a Textarea element within styled components in ReactJS, it causes the text to be inputted backwards due to the cursor

Currently, I am utilizing the Textarea component from react-textarea-autosize along with using styled from styled components. In a class, I have created a function called renderForm which is responsible for rendering a form containing a StyledTextarea. How ...

Having trouble making elements in Tailwind CSS take up the entire page? Seems like they're getting stuck in smaller containers instead

I've been working on creating a layout for my webpage that is similar to the one found here: However, despite using Tailwind CSS, I'm having trouble with the flex styling and getting it to display correctly. import { ChevronRightIcon, HomeIc ...

Unable to eliminate border from image within label

The following code generates a border that appears to be approximately 1px thick and solid, colored grey around the image. Despite setting the border of the image to none, the border still remains. Here is the code snippet: <label> <img styl ...

Error: stripe.redirectToCheckout does not exist and cannot be executed

Can anyone help me with implementing Stripe checkout for a website? I've been struggling because the Stripe documentation is incomplete. Here's what I have so far: import React from 'react'; import { loadStripe } from '@stripe/stri ...

Setting the tab width in the Material UI App Bar

Exploring Material UI has been an exciting journey for me as a newcomer! However, I am facing a challenge in adjusting the width of each tab panel/label to ensure all three labels are visible at once. Currently, the last label, Upload, is extending beyond ...

Getting Started with Parsing JSON Objects in ReactJS

In my ReactJS project, I am trying to parse through a JSON list using the following model: public class ModelEmployee { public List<Employeelist> Employees { get; set; } public int count { get; set; } public int Pagenumber { get; set; } ...

Weaknesses found in the React Js library bundled with create-react-app

Each time I initiate a new react project using npx create-react-app <AppName>, the following vulnerabilities are detected: 96 vulnerabilities found - Packages audited: 1682 Severity: 65 Moderate | 30 High | 1 Critical Node Version: v14.18.1 Npm: 7.20 ...

Is there a way to instruct the code to select between two variables and align their values?

I have encountered a challenge while working on a unit test. The website I am testing is dynamic, causing the CSS Selector and xpath to frequently change. As a solution, I came up with the idea of using both CSS and xpath to retrieve the same text. Curren ...

Trouble with importing scss file in sass and bootstrap collaboration

I am using Sass with Bootstrap 4, and now I'm facing an issue in my Sass folder where I have an app.scss file that includes: @import _customVariables.scss @import node_modules/bootstrap/scss/functions @import node_modules/bootstrap/scss/mixins Howev ...

Issue with state not being properly updated in a separate component within React/Next.js framework

Having an issue I am in the process of creating a cart feature and have encountered an issue in my main _app.js file, essentially the index.js file for react where I am utilizing the useState hook. The problem arises when I pass a function to update a va ...