title | layout | path |
---|---|---|
Material Components for the Web |
homepage |
/ |
{% contentfor benefits %}
-
Implement Material Design with pixel-perfect components, maintained by Google engineers and designers
-
Use components designed to work in any context, allowing seamless integration with libraries like React, AngularJS, and server-side rendering
-
Take advantage of components developed with minimal dependencies and tested for flexibility, accessibility, and internationalization
Get up and running with Material Components for web
-
{: .step-list-item } ### Install the library
Start by installing the library from npm:
npm install material-components-web
-
{: .step-list-item } ### Include the stylesheet
Include the MDC Web stylesheet in the head of your file
<html> <head> <title>Material Components for the web</title> <link rel="stylesheet" href="node_modules/material-components-web/dist/material-components-web.css"> </head>
-
{: .step-list-item } ### Add components
Add components to the body of your HTML
<body class="mdc-typography"> <h2 class="mdc-typography--display2">Hello, Material Components!</h2> <div class="mdc-text-field" data-mdc-auto-init="MDCTextField"> <input type="text" class="mdc-text-field__input" id="demo-input"> <label for="demo-input" class="mdc-floating-label">Tell us how you feel!</label> </div> </body>
-
{: .step-list-item } ### Add scripts and instantiate
Add the MDC Web scripts and call MDC Auto Init.
<script src="node_modules/material-components-web/dist/material-components-web.js"></script> <script>mdc.autoInit()</script>
A full example of the HTML could look like this:
<!DOCTYPE html> <html> <head> <title>Material Components for the web</title> <link rel="stylesheet" href="node_modules/material-components-web/dist/material-components-web.css"> </head> <body class="mdc-typography"> <h2 class="mdc-typography--display2">Hello, Material Components!</h2> <div class="mdc-text-field" data-mdc-auto-init="MDCTextField"> <input type="text" class="mdc-text-field__input" id="demo-input"> <label for="demo-input" class="mdc-floating-label">Tell us how you feel!</label> </div> <script src="node_modules/material-components-web/dist/material-components-web.js"></script> <script>mdc.autoInit()</script> </body> </html>
-
{: .step-list-item } ### What's next?
{: .step-list }