Material-ui: change default font family

Created on 22 Jan 2018  路  15Comments  路  Source: mui-org/material-ui

how to change default font family for all components ?!!

support

Most helpful comment

@aminkhademian We have a documentation example for this: https://material-ui.com/customization/typography/

This changes the typography of all the Material-UI components.

const theme = createMuiTheme({
  typography: {
    // Use the system font.
    fontFamily:
      '-apple-system,system-ui,BlinkMacSystemFont,' +
      '"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif',
  },
})

If you want to also impact the typography outside of Material-UI, at the document level, you can use the CssBaseline component.

All 15 comments

@aminkhademian We have a documentation example for this: https://material-ui.com/customization/typography/

This changes the typography of all the Material-UI components.

const theme = createMuiTheme({
  typography: {
    // Use the system font.
    fontFamily:
      '-apple-system,system-ui,BlinkMacSystemFont,' +
      '"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif',
  },
})

If you want to also impact the typography outside of Material-UI, at the document level, you can use the CssBaseline component.

馃憢 Thanks for using Material-UI!

We use the issue tracker exclusively for bug reports and feature requests, however,
this issue appears to be a support request or question. Please ask on StackOverflow where the
community will do their best to help. There is a "material-ui" tag that you can use to tag your
question.

If you would like to link from here to your question on SO, it will help others find it.
If your issues is confirmed as a bug, you are welcome to reopen the issue using the issue template.

@oliviertassinari this doesn't set a global font type to all text elements within a <MuiThemeProvider>. You have to wrap all texts within a <Typography> HOC, which is quite repetitive when you only want to inherit styles.

The solution is to resort to add classes with className or inline styles on parent components: https://material-ui.com/customization/overrides

@AntonioRedondo I don't understand your point. We have no <typography> Higher order component. Would you mind providing more detail?

https://material-ui.com/api/typography (call it simply component)

@AntonioRedondo I don't understand. What's preventing you from setting a global font? Material-UI tries to promote isolation with this Typography component.

I think what the original poster is asking is about some functionality similar to styled-components createGlobalStyle() with which from the styling library you can set global styles without using conventional classes and CSS.

@AntonioRedondo It's already available:

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

export default withStyles({
  '@global': {
    body: {
      fontFamily: 'Arial',
    },
  },
})(() => null);

This looks 馃啋. I cannot see it on the Material-UI website. Is it documented anywhere?

@oliviertassinari in what file can this be used? I can't seem to find any context in de documentation on the website either.

@jaycc008 ?

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

export default withStyles({
  '@global': {
    body: {
      fontFamily: 'Arial',
    },
  },
})(() => null);

This above code, how do I implement this in any file? I am trying to change the default font from Roboto to Noto Sans, but I don't understand where I can add this code to make Noto Sans the default font.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

damianobarbati picture damianobarbati  路  55Comments

kybarg picture kybarg  路  164Comments

garygrubb picture garygrubb  路  57Comments

nathanmarks picture nathanmarks  路  100Comments

HZooly picture HZooly  路  63Comments