Getting started

Contents

Include the master CSS & JavaScript

Include the Material Lite CSS and JavaScript files in each HTML page in your project. We recommend that you use the files hosted on our CDN. You can also customize and download them to host them yourself, build them from our source code or install them in your npm/Bower project.

Just add the following <link> and <script> elements into your HTML pages (27kB gzipped):
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>

Choose color scheme

Color schemes used in Material Design are based on a primary and an accent colors which you may want to personalize. These colors are specified in the CSS file name by following this pattern: material.{primary}-{accent}.min.css (e.g. material.indigo-pink.min.css). Our CDN hosts a number of color combinations based on common Material Design colors. To discover and preview available color combinations use our Customize and Preview tool.

Download the minified CSS and Javascript now (27kB gzipped):

Refer to these files by adding a <link> and a <script> elements into your HTML pages and also include the Material Icon font:
<link rel="stylesheet" href="./material.min.css">
<script src="./material.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

Choose color scheme

Color schemes used in Material Design are based on a primary and an accent colors which you may want to personalize. Use the Customize and Preview tool to select and preview primary and accent colors combinations for your site. Then download your customized Material Design Lite CSS using the button and simply replace the `material.min.css` with the customized one.

Our source code is hosted on GitHub. You'll need to download the code and build it.

Run the following commands in a shell:
# Clone/copy the Material Design lite source code.
git clone https://github.com/google/material-design-lite.git
# Go into the newly created folder containing the source code.
cd material-design-lite
# Install necessary dependencies.
npm install && npm install -g gulp
# Build a production version of the components.
gulp

You'll find the Material Design Lite library's file in the dist folder. Copy them to your project.

Refer to these files by adding a <link> and a <script> element into your HTML pages and also include the Material Icon font:
<link rel="stylesheet" href="./material.min.css">
<script src="./material.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

Note:

Using this method you will not be able to customize the color scheme of the MDL elements. If you'd like to customize the color scheme prefer the CDN hosted or downloadable libraries. In this case use our Customize and Preview tool.

Simply install Material Design Lite files in your Bower enabled project using:

Run the following command in a shell:
bower install material-design-lite --save

This will install the Material Design Lite library files in your project's bower_components folder.

Refer to these files by adding a <link> and a <script> element into your HTML pages and also include the Material Icon font:
<link rel="stylesheet" href="/bower_components/material-design-lite/material.min.css">
<script src="/bower_components/material-design-lite/material.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

Note:

Using this method you will not be able to customize the color scheme of the MDL elements. If you'd like to customize the color scheme prefer the CDN hosted or downloadable libraries. In this case use our Customize and Preview tool.

Simply install Material Design Lite files in your npm enabled project using:

Run the following command in a shell:
npm install material-design-lite --save

This will install the Material Design Lite library files in your project's node_modules folder.

Refer to these files by adding a <link> and a <script> element into your HTML pages and also include the Material Icon font:
<link rel="stylesheet" href="/node_modules/material-design-lite/material.min.css">
<script src="/node_modules/material-design-lite/material.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

Note:

Using this method you will not be able to customize the color scheme of the MDL elements. If you'd like to customize the color scheme prefer the CDN hosted or downloadable libraries. In this case use our Customize and Preview tool.

That's it! You are now ready to add MDL components on your site.

Use the components

You'll find below a couple of examples of MDL Button elements: a Button with ripples and a FAB Button. Just copy & paste the corresponding source code in the <body> of an HTML page of your project and the elements will render as shown below.

Raised button
Colored FAB
<!-- Accent-colored raised button with ripple -->
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent">
  Button
</button>
<style></style>
<!-- Colored FAB button --> <button class="mdl-button mdl-js-button mdl-button--fab mdl-button--colored"> <i class="material-icons">add</i> </button>
<style></style>
<style> body { padding: 20px; background: #fafafa; position: relative; } </style>

MDL elements can be tweaked and configured by adding CSS classes. For example adding mdl-js-ripple-effect to an MDL Button will add a Ripple effect when the button is clicked and adding mdl-button--fab will change the style of the button to a FAB button.

There are many other elements available such as Card containers, Sliders, Tables, Menus... For the complete set of MDL elements and options have a look at the components page.

We also recommend that you check out our templates. These are ready to use website templates using MDL components. Feel free to have a look at them to get started quickly on your next project.

General rules and principles

In general, follow these basic steps to use an MDL component in your HTML page:

  1. Start with a standard HTML element, such as <button>, <div>, or <ul>, depending on the MDL component you want to use. This establishes the element in the page and readies it for MDL modification.
  2. Add one or more MDL-specific CSS classes to the element, such as mdl-button or mdl-tabs__panel, again depending on the component. The classes apply the MDL enhancements to the element and turn it into an MDL component.

Remember to include the meta viewport tag in your document so mobile devices will render correctly.

<meta name="viewport" content="width=device-width, initial-scale=1.0">

A note about HTML elements and MDL CSS classes

Material Design Lite uses namespaced BEM classes—which can apply to almost any HTML element—to construct components. For some components you can use almost any element. The examples in each component's documentation use elements that perform well as that component. If you must use elements other than those shown in the examples, we encourage you to experiment to find the best combination of HTML elements and MDL CSS classes for your application.

Use MDL on dynamic websites

Material Design Lite will automatically register and render all elements marked with MDL classes upon page load. However in the case where you are creating DOM elements dynamically you need to register new elements using the upgradeElement function. Here is how you can dynamically create the same raised button with ripples shown in the section above:

<div id="container"/>
<script>
  var button = document.createElement('button');
  var textNode = document.createTextNode('Click Me!');
  button.appendChild(textNode);
  button.className = 'mdl-button mdl-js-button mdl-js-ripple-effect';
  componentHandler.upgradeElement(button);
  document.getElementById('container').appendChild(button);
</script>

What are MDL's responsibilities?

Material Design Lite is built to provide a lightweight and basic set of Material Design components and templates for web sites. The project does not intend to provide structures to create all possible UX needs, but to provide a low-friction Material Design implementation you can build on. Even within Material Design itself, cards specifically, it is unfeasible to provide every combination in a seamless manner. When you find something not provided, such as dropdowns in the drawer, you may need to code your own component.

The team is committed to providing a great experience to developers while staying true to the promise of lite.

What's next?

Detailed instructions for using the components, including MDL classes and their effects, coding considerations, and configuration options, can be found in the components page. Example of sites using MDL elements together can be found in the templates page.

License

Copyright Google, 2015. Licensed under an Apache-2 license.

Download Kit