"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

"Incompatibility between Tailwind and NextJS causing avatars to disappear when certain props are applied to the render

Encountering issues with the avatar size - changing it to 28, 18, or 16 works fine. However, when adjusting the size to 24, 22, 20, and other values, the image disappears. Below are my screenshots and code snippets: Img Component: import Image from " ...

What techniques does Google use to craft mobile-friendly fixed backgrounds and parallax content within iframes?

Currently, I am working on a test that involves utilizing an intersectionobserver in conjunction with iframe postMessage to adjust the background image in a translate3d manner within the iframe. However, this method is causing significant jitter and potent ...

Ways to dynamically modify the CSS attributes of a webpage during the page load event

I'm looking to incorporate the background:rgba(226, 93, 141, 0.76) attribute into the body:after psuedo-element once my page has finished loading. Below is my HTML and CSS code: <style runat="server" id="myStyle" > body:after{ position:fix ...

Encountering a Typescript error when trying to pass a function as a prop that returns SX style

Imagine a scenario where a parent component needs to pass down a function to modify the styles of a reusable child component: const getStyleProps: StyleProps<Theme> = (theme: Theme) => ({ mt: 1, '.Custom-CSS-to-update': { padding ...

State in Next.js is still not prepared when the form is submitted

In my code, I have an onSubmit function that handles file uploads and creating records in a database. The issue I'm facing is that the record creation happens before the file upload process completes, resulting in incomplete data being stored. const ...

Ways to create two distinct "on click" actions for a single image to execute two distinct tasks

Clicking on an image will open a slider showing all images before filtering. Once filtered, only the selected images will be displayed in the slider. <div class="gallery row" id="gallery" style="margin:0;"> <!-- Grid column --> <div ...

Troubleshooting the issue: Unable to shift a div to the left in a Rails app using jQuery and CSS when a mouseover event occurs

Hey there, I'm working on a div that contains a map. My goal is to have the width of the div change from 80% to 50% when a user hovers over it. This will create space on the right side for an image to appear. I've been looking up examples of jqu ...

React: Importing functions from other files is not allowed

As someone coming from an Angular background, I recently started using React and everything was going smoothly until I encountered an error while checking if Firebase is initialized: TypeError: _assets_Services__Firebase__WEBPACK_IMPORTED_MODULE_11__.defau ...

Stopping jQuery fadeOut from setting the display property to 'hidden'

I am currently working on a project that involves creating a lightbox effect. I am using jQuery's fadeIn and fadeOut functions to display enlarged div elements. However, I have encountered an issue - when I use fadeOut on the enlarged div, the smaller ...

Element within an element should be centered

I've been attempting to center a block element, specifically the WordPress caption box with an image, and I'm encountering difficulties. Here is what I have tried: .imagecenter { margin-left: auto; margin-right: auto; display: block; } ...

Create an input box with a designated class

When I click the button in my HTML and JavaScript code below, I am able to dynamically add a text field and radio button. This functionality is working properly. However, I also want the newly generated text field to have the same font size and appearance ...

Display a separate component within a primary component upon clicking a button

Looking to display data from a placeholder module upon component click. As a beginner with React, my attempts have been unsuccessful so far. I have a component that lists some information for each element in the module as a list, and I would like to be ab ...

Whenever I attempt to import varied liveries, I consistently encounter the same errors

I experimented with webdriverio, puppeteer, playwright, and bowser but encountered the same issues when using React. All I did was $ yarn add webdriverio (or another) and then import { remote } from 'webdriverio'; or const playwright = requi ...

Tips for implementing a decorator in a TypeScript-dependent Node module with Create-React-App

I am working on a project using TypeScript and React, which has a dependency on another local TypeScript based project. Here are the configurations: tsconfig.json of the React project: "compilerOptions": { "target": "esnext& ...

The npm postinstall script will only execute if no packages are currently being installed

I made a mistake The reason behind why running npm install whatever results in the deletion of the node_modules/- folder is not what I initially thought. I mistakenly believed it executed the preinstall script but skipped the postinstall script, which was ...

Is it possible to have multiple ReactDOM.render calls in a single project

Currently, I am in the process of learning react and encountering an issue when trying to call multiple ReactDOM.render functions: Here is my code using React: class Header extends React.Component{ render(){ return( <div> <p&g ...

Adding additional elements to a div in a horizontal orientation

I am currently working on a project where I need to display bars and restaurants based on specific filter criteria. I have a container div called .resultsContainer where all the results will be displayed. While I can easily append more divs (.barContainer) ...

Is setTimeout used in Material-UI's Select component for closing? If yes, then what is the reason behind it?

Is there a timeout or other time function used by Material-UI's Select component for closing? I have been investigating the code implementation and debugging without success in finding an answer to this question. I'm facing an issue while writin ...

What's the best way to establish the namespace for styled components within a create-react-app environment?

As I work on my react app using create-react-app, I am determined to find a way to customize the generation of classes without needing to eject the webpack config. To achieve this, I have turned to using react-app-rewired along with react-app-rewire-styled ...

What is the best way to retrieve custom data attribute values from `MenuItem` within a `Select` component in material ui?

I am attempting to extract data attribute values from the MenuItem component in Material UI. <MenuItem value={one.supplier_Name} key={one.supplier_Name} data-id={one.supplier_ID} > {one.supplier_Name} </MenuItem> I want to acce ...