Installation - Material UI


本站和网页 https://mui.com/material-ui/getting-started/installation/ 的作者无关,不对其内容负责。快照谨为网络故障时之索引,不代表被搜索网站的即时页面。

Installation - Material UISkip to contentMUI CoreMaterial UIv5.14.18Getting startedOverviewInstallationUsageExample projectsTemplatesLearnDesign resourcesFAQsSupported componentsSupported platformsSupportComponentsComponent APICustomizationHow-to guidesExperimental APIsDiscover moreMigrationTemplates
InstallationInstall Material UI, the world's most popular React UI framework.
Default installationRun one of the following commands to add Material UI to your project:
npmyarnpnpmnpm install @mui/material @emotion/react @emotion/styledWith styled-componentsMaterial UI uses Emotion as its default styling engine.
If you want to use styled-components instead, run one of the following commands:
npmyarnpnpmnpm install @mui/material @mui/styled-engine-sc styled-componentsNext, follow the styled-components how-to guide to properly configure your bundler to support @mui/styled-engine-sc.
As of late 2021, styled-components is not compatible with server-rendered Material UI projects.
This is because babel-plugin-styled-components isn't able to work with the styled() utility inside @mui packages.
See this GitHub issue for more details.
We strongly recommend using Emotion for SSR projects.
Peer dependencies
Please note that react and react-dom are peer dependencies too:
"peerDependencies": {
"react": "^17.0.0 || ^18.0.0",
"react-dom": "^17.0.0 || ^18.0.0"
},
(or $keyC)
Roboto fontMaterial UI uses the Roboto font by default.
Add it to your project via Fontsource, or with the Google Fonts CDN.
npmyarnpnpmnpm install @fontsource/robotoThen you can import it in your entry point like this:
import '@fontsource/roboto/300.css';
import '@fontsource/roboto/400.css';
import '@fontsource/roboto/500.css';
import '@fontsource/roboto/700.css';
(or $keyC)
Fontsource can be configured to load specific subsets, weights and styles. Material UI's default typography configuration relies only on the 300, 400, 500, and 700 font weights.
Google Web FontsTo install Roboto through the Google Web Fonts CDN, add the following code inside your project's tag:
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;600;700&display=swap"
/>
(or $keyC)
IconsTo use the font Icon component or the prebuilt SVG Material Icons (such as those found in the icon demos), you must first install the Material Icons font.
You can do so with npm, or with the Google Web Fonts CDN.
npmyarnpnpmnpm install @mui/icons-materialGoogle Web FontsTo install the Material Icons font in your project using the Google Web Fonts CDN, add the following code snippet inside your project's <head /> tag:
To use the font Icon component, you must first add the Material Icons font.
Here are some instructions
on how to do so.
For instance, via Google Web Fonts:
<link
rel="stylesheet"
href="https://fonts.googleapis.com/icon?family=Material+Icons"
/>
(or $keyC)
CDNYou can start using Material UI right away with minimal front-end infrastructure by installing it via CDN, which is a great option for rapid prototyping.
Follow this CDN example to get started.
We do not recommend using this approach in production.
It requires the client to download the entire library—regardless of which components are actually used—which negatively impacts performance and bandwidth utilization.
Two Universal Module Definition (UMD) files are provided:
one for development: https://unpkg.com/@mui/material@latest/umd/material-ui.development.js
one for production: https://unpkg.com/@mui/material@latest/umd/material-ui.production.min.js
The UMD links use the latest tag to point to the latest version of the library.
This pointer is unstable and subject to change as we release new versions.
You should consider pointing to a specific version, such as v5.0.0.
Edit this pageWas this page helpful?OverviewUsage•Blog •Store MUI stands in solidarity with Ukraine.ContentsDefault installationWith styled-componentsPeer dependenciesRoboto fontGoogle Web FontsIconsGoogle Web FontsCDNDiamond sponsorsBecome a Diamond sponsorOne spot left!