Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use a custom font? #3896

Closed
nmaves opened this issue Apr 7, 2016 · 8 comments
Closed

How to use a custom font? #3896

nmaves opened this issue Apr 7, 2016 · 8 comments
Labels
support: question Community support but can be turned into an improvement

Comments

@nmaves
Copy link

nmaves commented Apr 7, 2016

Why are we forced to use fonts bundled with material-ui?

Is there a way to remove or configure this?

@nathanmarks

This comment has been minimized.

@sandorvasas
Copy link

sandorvasas commented Mar 28, 2017

Actually, after 6 hours of searching online, digging in lib code and randomly guessing, the conclusion I arrived at: IT IS POSSIBLE! :D

  1. create /fonts directory in /public
  2. create /public/fonts/fonts.css, that defines the @font-faces:
@font-face {
  font-family: 'inglobal';
  font-weight: normal;
  font-style: normal;
  src: url('./inglobal.ttf');
}
  1. add <link rel="stylesheet" href="%PUBLIC_URL%/fonts/fonts.css"> to /public/index.html's head

  2. Hurray!

4/b. If, for any reason, it still doesn't work, change the fonts' extensions to .css (also at src: url('./OperatorMono.css') )


Alternatively, https://material-ui.com/customization/typography/#self-hosted-fonts

@muhammadawaisshaikh
Copy link

muhammadawaisshaikh commented Feb 27, 2020

  1. link google fonts in your index.html
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,500,700&display=swap" rel="stylesheet">
  1. Add in your body style
/* Styles */
body {
  margin: 0 auto;
  font-family: 'Montserrat';
}
  1. few changes in app.js
import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles';

const theme = createMuiTheme({
  typography: {
    fontFamily: [
      'Montserrat'
    ].join(','),
  },
})

@StreetProgrammer

This comment has been minimized.

@eaotnc

This comment has been minimized.

@anuragraina
Copy link

anuragraina commented Sep 7, 2020

Follow these 2 steps to change default font:

Here I'm changing default font to "Open Sans"

  1. Import Google Fonts in your index.html
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap" rel="stylesheet"/>
  1. Do these changes in index.js
import { ThemeProvider } from '@material-ui/styles';
import { CssBaseline } from '@material-ui/core';
import { createMuiTheme } from '@material-ui/core';

const theme = createMuiTheme({ typography: { fontFamily: [ 'Open Sans' ].join(','), }, })

ReactDOM.render(
		<ThemeProvider theme={theme}>
                        <CssBaseline />
			<App />
		</ThemeProvider>,
	document.getElementById('root')
);

@palak-temp

This comment has been minimized.

@cihanbas

This comment has been minimized.

@oliviertassinari oliviertassinari changed the title Change/use custom font How to use a custom font? Dec 18, 2020
@oliviertassinari oliviertassinari added the support: question Community support but can be turned into an improvement label Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

10 participants