- COMPONENTS
- Material Design Lite (MDL) is a library of components for web developers based on Google's Material Design Philosophy: "A visual language for our users that synthesizes the classic principles of good design with the innovation and possibility of technology and science." Understanding the goals and principles of Material Design is critical to the proper use of the Material Design Lite components. If you have not yet read the Material Design Introduction you should do so before attempting to use the components.
Badges
Small status descriptors for UI elements.
<!-- Number badge on icon --> <div class="material-icons mdl-badge mdl-badge--overlap" data-badge="1">account_box</div>
<style></style><!-- Icon badge on icon --> <div class="material-icons mdl-badge mdl-badge--overlap" data-badge="♥">account_box</div>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
<!-- Number badge --> <span class="mdl-badge" data-badge="4">Inbox</span>
<style></style><!-- Icon badge --> <span class="mdl-badge" data-badge="♥">Mood</span>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
Introduction
The Material Design Lite (MDL) badge component is an onscreen notification element. A badge consists of a small circle, typically containing a number or other characters, that appears in proximity to another object. A badge can be both a notifier that there are additional items associated with an object and an indicator of how many items there are.
You can use a badge to unobtrusively draw the user's attention to items they might not otherwise notice, or to emphasize that items may need their attention. For example:
- A "New messages" notification might be followed by a badge containing the number of unread messages.
- A "You have unpurchased items in your shopping cart" reminder might include a badge showing the number of items in the cart.
- A "Join the discussion!" button might have an accompanying badge indicating the number of users currently participating in the discussion.
A badge is almost always positioned near a link so that the user has a convenient way to access the additional information indicated by the badge. However, depending on the intent, the badge itself may or may not be part of the link.
Badges are a new feature in user interfaces, and provide users with a visual clue to help them discover additional relevant content. Their design and use is therefore an important factor in the overall user experience.
To include an MDL badge component:
1. Code an <a>
(anchor/link) or a <span>
element. Include any desired attributes and content.
<a href="#">This link has a badge.</a>
2. Add one or more MDL classes, separated by spaces, to the element using the class
attribute.
<a href="#" class="mdl-badge">This link has a badge.</a>
3. Add a data-badge
attribute and quoted string value for the badge.
<a href="#" class="mdl-badge" data-badge="5">This link has a badge.</a>
The badge component is ready for use.
Note: Because of the badge component's small size, the
data-badge
value should typically contain one to three characters. More than three characters will not cause an error, but some characters may fall outside the badge and thus be difficult or impossible to see. The value of thedata-badge
attribute is centered in the badge.
Examples
A badge inside a link.
<a href="#" class="mdl-badge" data-badge="7">This link contains a badge.</a>
A badge near, but not included in, a link.
<a href="#">This link is followed by a badge.</a>
<span class="mdl-badge" data-badge="12"></span>
A badge inside a link with too many characters to fit inside the badge.
<a href="#" class="mdl-badge" data-badge="123456789">
This badge has too many characters.</a>
A badge inside a link with no badge background color.
<a href="#" class="mdl-badge mdl-badge--no-background" data-badge="123">
This badge has no background color.</a>
Configuration options
The MDL CSS classes apply various predefined visual enhancements to the badge. The table below lists the available classes and their effects.
MDL class | Effect | Remarks |
---|---|---|
mdl-badge |
Defines badge as an MDL component | Required on span or link |
mdl-badge--no-background |
Applies open-circle effect to badge | Optional |
mdl-badge--overlap |
Make the badge overlap with its container | Optional |
data-badge="value" |
Assigns string value to badge | Not a class, but a separate attribute; required on span or link |
Cards
Self-contained pieces of paper with data.
Welcome
<!-- Wide card with share menu button --> <style> .demo-card-wide.mdl-card { width: 512px; } .demo-card-wide > .mdl-card__title { color: #fff; height: 176px; background: url('../assets/demos/welcome_card.jpg') center / cover; } .demo-card-wide > .mdl-card__menu { color: #fff; } </style> <div class="demo-card-wide mdl-card mdl-shadow--2dp"> <div class="mdl-card__title"> <h2 class="mdl-card__title-text">Welcome</h2> </div> <div class="mdl-card__supporting-text"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris sagittis pellentesque lacus eleifend lacinia... </div> <div class="mdl-card__actions mdl-card--border"> <a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect"> Get Started </a> </div> <div class="mdl-card__menu"> <button class="mdl-button mdl-button--icon mdl-js-button mdl-js-ripple-effect"> <i class="material-icons">share</i> </button> </div> </div>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
<!-- Square card --> <style> .demo-card-square.mdl-card { width: 320px; height: 320px; } .demo-card-square > .mdl-card__title { color: #fff; background: url('../assets/demos/dog.png') bottom right 15% no-repeat #46B6AC; } </style> <div class="demo-card-square mdl-card mdl-shadow--2dp"> <div class="mdl-card__title mdl-card--expand"> <h2 class="mdl-card__title-text">Update</h2> </div> <div class="mdl-card__supporting-text"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenan convallis. </div> <div class="mdl-card__actions mdl-card--border"> <a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect"> View Updates </a> </div> </div>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
<!-- Image card --> <style> .demo-card-image.mdl-card { width: 256px; height: 256px; background: url('../assets/demos/image_card.jpg') center / cover; } .demo-card-image > .mdl-card__actions { height: 52px; padding: 16px; background: rgba(0, 0, 0, 0.2); } .demo-card-image__filename { color: #fff; font-size: 14px; font-weight: 500; } </style> <div class="demo-card-image mdl-card mdl-shadow--2dp"> <div class="mdl-card__title mdl-card--expand"></div> <div class="mdl-card__actions"> <span class="demo-card-image__filename">Image.jpg</span> </div> </div>
<style></style><!-- Event card --> <style> .demo-card-event.mdl-card { width: 256px; height: 256px; background: #3E4EB8; } .demo-card-event > .mdl-card__actions { border-color: rgba(255, 255, 255, 0.2); } .demo-card-event > .mdl-card__title { align-items: flex-start; } .demo-card-event > .mdl-card__title > h4 { margin-top: 0; } .demo-card-event > .mdl-card__actions { display: flex; box-sizing:border-box; align-items: center; } .demo-card-event > .mdl-card__actions > .material-icons { padding-right: 10px; } .demo-card-event > .mdl-card__title, .demo-card-event > .mdl-card__actions, .demo-card-event > .mdl-card__actions > .mdl-button { color: #fff; } </style> <div class="demo-card-event mdl-card mdl-shadow--2dp"> <div class="mdl-card__title mdl-card--expand"> <h4> Featured event:<br> May 24, 2016<br> 7-11pm </h4> </div> <div class="mdl-card__actions mdl-card--border"> <a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect"> Add to Calendar </a> <div class="mdl-layout-spacer"></div> <i class="material-icons">event</i> </div> </div>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
Introduction
The Material Design Lite (MDL) card component is a user interface element representing a virtual piece of paper that contains related data — such as a photo, some text, and a link — that are all about a single subject.
Cards are a convenient means of coherently displaying related content that is composed of different types of objects. They are also well-suited for presenting similar objects whose size or supported actions can vary considerably, like photos with captions of variable length. Cards have a constant width and a variable height, depending on their content.
Cards are a fairly new feature in user interfaces, and allow users an access point to more complex and detailed information. Their design and use is an important factor in the overall user experience. See the card component's Material Design specifications page for details.
To include an MDL card component:
1. Code a <div>
element; this is the "outer" container, intended to hold all of the card's content.
<div>
</div>
2. Inside the div, code one or more "inner" divs, one for each desired content block. A card containing a title, an image, some text, and an action bar would contain four "inner" divs, all siblings.
<div>
<div>
...
</div>
<div>
...
</div>
<div>
...
</div>
<div>
...
</div>
</div>
3. Add one or more MDL classes, separated by spaces, to the "outer" div and the "inner" divs (depending on their intended use) using the class
attribute.
<div class="mdl-card">
<div class="mdl-card__title">
...
</div>
<div class="mdl-card__media">
...
</div>
<div class="mdl-card__supporting-text">
...
</div>
<div class="mdl-card__actions">
...
</div>
</div>
4. Add content to each "inner" div, again depending on its intended use, using standard HTML elements and, optionally, additional MDL classes.
<div class="mdl-card">
<div class="mdl-card__title">
<h2 class="mdl-card__title-text">title Text Goes Here</h2>
</div>
<div class="mdl-card__media">
<img src="photo.jpg" width="220" height="140" border="0" alt="" style="padding:20px;">
</div>
<div class="mdl-card__supporting-text">
This text might describe the photo and provide further information, such as where and
when it was taken.
</div>
<div class="mdl-card__actions">
<a href="(URL or function)">Related Action</a>
</div>
</div>
The card component is ready for use.
Examples
A card (no shadow) with a title, image, text, and action.
<div class="mdl-card">
<div class="mdl-card__title">
<h2 class="mdl-card__title-text">Auckland Sky Tower<br>Auckland, New Zealand</h2>
</div>
<div class="mdl-card__media">
<img src="skytower.jpg" width="173" height="157" border="0" alt=""
style="padding:10px;">
</div>
<div class="mdl-card__supporting-text">
The Sky Tower is an observation and telecommunications tower located in Auckland,
New Zealand. It is 328 metres (1,076 ft) tall, making it the tallest man-made structure
in the Southern Hemisphere.
</div>
<div class="mdl-card__actions">
<a href="http://en.wikipedia.org/wiki/Sky_Tower_%28Auckland%29">Wikipedia entry</a>
</div>
</div>
Card (level-3 shadow) with an image, caption, and text:
<div class="mdl-card mdl-shadow--4dp">
<div class="mdl-card__media"><img src="skytower.jpg" width="173" height="157" border="0"
alt="" style="padding:10px;">
</div>
<div class="mdl-card__supporting-text">
Auckland Sky Tower, taken March 24th, 2014
</div>
<div class="mdl-card__supporting-text">
The Sky Tower is an observation and telecommunications tower located in Auckland,
New Zealand. It is 328 metres (1,076 ft) tall, making it the tallest man-made structure
in the Southern Hemisphere.
</div>
</div>
Configuration options
The MDL CSS classes apply various predefined visual and behavioral enhancements to the card. The table below lists the available classes and their effects.
MDL class | Effect | Remarks |
---|---|---|
mdl-card |
Defines div element as an MDL card container | Required on "outer" div |
mdl-card--border |
Adds a border to the card section that it's applied to | Used on the "inner" divs |
mdl-shadow--2dp through mdl-shadow--16dp |
Assigns variable shadow depths (2, 3, 4, 6, 8, or 16) to card | Optional, goes on "outer" div; if omitted, no shadow is present |
mdl-card__title |
Defines div as a card title container | Required on "inner" title div |
mdl-card__title-text |
Assigns appropriate text characteristics to card title | Required on head tag (H1 - H6) inside title div |
mdl-card__subtitle-text |
Assigns text characteristics to a card subtitle | Optional. Should be a child of the title element. |
mdl-card__media |
Defines div as a card media container | Required on "inner" media div |
mdl-card__supporting-text |
Defines div as a card body text container and assigns appropriate text characteristics to body text | Required on "inner" body text div; text goes directly inside the div with no intervening containers |
mdl-card__actions |
Defines div as a card actions container and assigns appropriate text characteristics to actions text | Required on "inner" actions div; content goes directly inside the div with no intervening containers |
mdl-card__menu |
Defines element as top right menu button | Optional. Should be a child of the mdl-card element. |
Chips
Represents complex entities in small blocks.
<!-- Basic Chip --> <span class="mdl-chip"> <span class="mdl-chip__text">Basic Chip</span> </span>
<style></style><!-- Deletable Chip --> <span class="mdl-chip mdl-chip--deletable"> <span class="mdl-chip__text">Deletable Chip</span> <button type="button" class="mdl-chip__action"><i class="material-icons">cancel</i></button> </span>
<style></style><!-- Button Chip --> <button type="button" class="mdl-chip"> <span class="mdl-chip__text">Button Chip</span> </button>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
<!-- Contact Chip --> <span class="mdl-chip mdl-chip--contact"> <span class="mdl-chip__contact mdl-color--teal mdl-color-text--white">A</span> <span class="mdl-chip__text">Contact Chip</span> </span>
<style></style><!-- Deletable Contact Chip --> <span class="mdl-chip mdl-chip--contact mdl-chip--deletable"> <img class="mdl-chip__contact" src="/templates/dashboard/images/user.jpg"></img> <span class="mdl-chip__text">Deletable Contact Chip</span> <a href="#" class="mdl-chip__action"><i class="material-icons">cancel</i></a> </span>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
Introduction
The Material Design Lite (MDL) chip component is a small, interactive element. Chips are commonly used for contacts, text, rules, icons, and photos.
TO INCLUDE AN MDL CHIP COMPONENT:
1. Create a container element for the chip; typically <span>
and <div>
are used, but any container element should work equally well. If you need interactivity, use a <button>
, or add the tabindex
attribute to your container.
<span>
</span>
2. Add in the text wrapper and the MDL classes.
<span class="mdl-chip">
<span class="mdl-chip__text">Chip Text</span>
</span>
3. For deletable chips, add in the delete icon. This can be an <a>
, <button>
or non-interactive tags like <span>
.
<span class="mdl-chip">
<span class="mdl-chip__text">Chip Text</span>
<a href="#" class="mdl-chip__action"><i class="material-icons">cancel</i></a>
</span>
4. Contact chips need to have the mdl-chip--contact
class added to the container, along with another container for the contact icon. The icon container for photos is typically an <img>
tag, but other types of content can be used with a little extra supporting css.
<span class="mdl-chip">
<span class="mdl-chip__contact mdl-color--teal mdl-color-text--white">A</span>
<span class="mdl-chip__text">Chip Text</span>
<a href="#" class="mdl-chip__action"><i class="material-icons">cancel</i></a>
</span>
Examples
A button based contact chip whose contact image is a <span>
with a background-image
.
<style>
.demo-chip .mdl-chip__contact {
background-image: url("./path/to/image");
background-size: cover;
}
</style>
<button class="mdl-chip demo-chip">
<span class="mdl-chip__contact"> </span>
<span class="mdl-chip__text">Chip Text</span>
<a href="#" class="mdl-chip__action"><i class="material-icons">cancel</i></a>
</button>
CSS Classes
MDL Class | Effect | Remarks |
---|---|---|
mdl-chip |
Defines element as an MDL chip container | Required on "outer" container |
mdl-chip--contact |
Defines an MDL chip as a contact style chip | Optional, goes on "outer" container |
mdl-chip__text |
Defines element as the chip's text | Required on "inner" text container |
mdl-chip__action |
Defines element as the chip's action | Required on "inner" action container, if present |
mdl-chip__contact |
Defines element as the chip's contact container | Required on "inner" contact container, if the mdl-chip--contact class is present on "outer" container |
Dialogs
Modal windows for dedicated user input.
Introduction
The Material Design Lite (MDL) dialog component allows for verification of user actions, simple data input, and alerts to provide extra information to users.
Basic Usage
To use the dialog component, you must be using a browser that supports the dialog element. Only Chrome and Opera have native support at the time of writing. For other browsers you will need to include the dialog polyfill or create your own.
Once you have dialog support create a dialog element.
The element when using the polyfill must be a child of the body
element.
Within that container, add a content element with the class mdl-dialog__content
.
Add you content, then create an action container with the class mdl-dialog__actions
.
Finally for the markup, add your buttons within this container for triggering dialog functions.
Keep in mind, the order is automatically reversed for actions. Material Design requires that the primary (confirmation) action be displayed last. So, the first action you create will appear last on the action bar. This allows for more natural coding and tab ordering while following the specification.
Remember to add the event handlers for your action items. After your dialog markup is created, add the event listeners to the page to trigger the dialog to show.
For example:
var button = document.querySelector('button');
var dialog = document.querySelector('dialog');
button.addEventListener('click', function() {
dialog.showModal();
/* Or dialog.show(); to show the dialog without a backdrop. */
});
Examples
Simple Dialog
See this example live in codepen.
<body>
<button id="show-dialog" type="button" class="mdl-button">Show Dialog</button>
<dialog class="mdl-dialog">
<h4 class="mdl-dialog__title">Allow data collection?</h4>
<div class="mdl-dialog__content">
<p>
Allowing us to collect data will let us get you the information you want faster.
</p>
</div>
<div class="mdl-dialog__actions">
<button type="button" class="mdl-button">Agree</button>
<button type="button" class="mdl-button close">Disagree</button>
</div>
</dialog>
<script>
var dialog = document.querySelector('dialog');
var showDialogButton = document.querySelector('#show-dialog');
if (! dialog.showModal) {
dialogPolyfill.registerDialog(dialog);
}
showDialogButton.addEventListener('click', function() {
dialog.showModal();
});
dialog.querySelector('.close').addEventListener('click', function() {
dialog.close();
});
</script>
</body>
Dialog with full width actions
See this example live in codepen.
<body>
<button type="button" class="mdl-button show-modal">Show Modal</button>
<dialog class="mdl-dialog">
<div class="mdl-dialog__content">
<p>
Allow this site to collect usage data to improve your experience?
</p>
</div>
<div class="mdl-dialog__actions mdl-dialog__actions--full-width">
<button type="button" class="mdl-button">Agree</button>
<button type="button" class="mdl-button close">Disagree</button>
</div>
</dialog>
<script>
var dialog = document.querySelector('dialog');
var showModalButton = document.querySelector('.show-modal');
if (! dialog.showModal) {
dialogPolyfill.registerDialog(dialog);
}
showModalButton.addEventListener('click', function() {
dialog.showModal();
});
dialog.querySelector('.close').addEventListener('click', function() {
dialog.close();
});
</script>
</body>
CSS Classes
Blocks
MDL Class | Effect | Remarks |
---|---|---|
mdl-dialog |
Defines the container of the dialog component. | Required on dialog container. |
Elements
MDL Class | Effect | Remarks |
---|---|---|
mdl-dialog__title |
Defines the title container in the dialog. | Optional on title container. |
mdl-dialog__content |
Defines the content container of the dialog. | Required on content container. |
mdl-dialog__actions |
Defines the actions container in the dialog. | Required on action container. |
Modifiers
MDL Class | Effect | Remarks |
---|---|---|
mdl-dialog__actions--full-width |
Modifies the actions to each take the full width of the container. This makes each take their own line. | Optional on action container. |
Layout
Building blocks for constructing a page layout.
Navigation layouts
<!-- Uses a transparent header that draws on top of the layout's background --> <style> .demo-layout-transparent { background: url('../assets/demos/transparent.jpg') center / cover; } .demo-layout-transparent .mdl-layout__header, .demo-layout-transparent .mdl-layout__drawer-button { /* This background is dark, so we set text to white. Use 87% black instead if your background is light. */ color: white; } </style> <div class="demo-layout-transparent mdl-layout mdl-js-layout"> <header class="mdl-layout__header mdl-layout__header--transparent"> <div class="mdl-layout__header-row"> <!-- Title --> <span class="mdl-layout-title">Title</span> <!-- Add spacer, to align navigation to the right --> <div class="mdl-layout-spacer"></div> <!-- Navigation --> <nav class="mdl-navigation"> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> </nav> </div> </header> <div class="mdl-layout__drawer"> <span class="mdl-layout-title">Title</span> <nav class="mdl-navigation"> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> </nav> </div> <main class="mdl-layout__content"> </main> </div>
<style></style>
<!-- No header, and the drawer stays open on larger screens (fixed drawer). --> <div class="mdl-layout mdl-js-layout mdl-layout--fixed-drawer"> <div class="mdl-layout__drawer"> <span class="mdl-layout-title">Title</span> <nav class="mdl-navigation"> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> </nav> </div> <main class="mdl-layout__content"> <div class="page-content"><!-- Your content goes here --></div> </main> </div>
<style></style>
<!-- Always shows a header, even in smaller screens. --> <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header"> <header class="mdl-layout__header"> <div class="mdl-layout__header-row"> <!-- Title --> <span class="mdl-layout-title">Title</span> <!-- Add spacer, to align navigation to the right --> <div class="mdl-layout-spacer"></div> <!-- Navigation. We hide it in small screens. --> <nav class="mdl-navigation mdl-layout--large-screen-only"> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> </nav> </div> </header> <div class="mdl-layout__drawer"> <span class="mdl-layout-title">Title</span> <nav class="mdl-navigation"> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> </nav> </div> <main class="mdl-layout__content"> <div class="page-content"><!-- Your content goes here --></div> </main> </div>
<style></style>
<!-- The drawer is always open in large screens. The header is always shown, even in small screens. --> <div class="mdl-layout mdl-js-layout mdl-layout--fixed-drawer mdl-layout--fixed-header"> <header class="mdl-layout__header"> <div class="mdl-layout__header-row"> <div class="mdl-layout-spacer"></div> <div class="mdl-textfield mdl-js-textfield mdl-textfield--expandable mdl-textfield--floating-label mdl-textfield--align-right"> <label class="mdl-button mdl-js-button mdl-button--icon" for="fixed-header-drawer-exp"> <i class="material-icons">search</i> </label> <div class="mdl-textfield__expandable-holder"> <input class="mdl-textfield__input" type="text" name="sample" id="fixed-header-drawer-exp"> </div> </div> </div> </header> <div class="mdl-layout__drawer"> <span class="mdl-layout-title">Title</span> <nav class="mdl-navigation"> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> </nav> </div> <main class="mdl-layout__content"> <div class="page-content"><!-- Your content goes here --></div> </main> </div>
<style></style>
<!-- Uses a header that scrolls with the text, rather than staying locked at the top --> <div class="mdl-layout mdl-js-layout"> <header class="mdl-layout__header mdl-layout__header--scroll"> <div class="mdl-layout__header-row"> <!-- Title --> <span class="mdl-layout-title">Title</span> <!-- Add spacer, to align navigation to the right --> <div class="mdl-layout-spacer"></div> <!-- Navigation --> <nav class="mdl-navigation"> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> </nav> </div> </header> <div class="mdl-layout__drawer"> <span class="mdl-layout-title">Title</span> <nav class="mdl-navigation"> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> </nav> </div> <main class="mdl-layout__content"> <div class="page-content"><!-- Your content goes here --></div> </main> </div>
<style></style>
<!-- Uses a header that contracts as the page scrolls down. --> <style> .demo-layout-waterfall .mdl-layout__header-row .mdl-navigation__link:last-of-type { padding-right: 0; } </style> <div class="demo-layout-waterfall mdl-layout mdl-js-layout"> <header class="mdl-layout__header mdl-layout__header--waterfall"> <!-- Top row, always visible --> <div class="mdl-layout__header-row"> <!-- Title --> <span class="mdl-layout-title">Title</span> <div class="mdl-layout-spacer"></div> <div class="mdl-textfield mdl-js-textfield mdl-textfield--expandable mdl-textfield--floating-label mdl-textfield--align-right"> <label class="mdl-button mdl-js-button mdl-button--icon" for="waterfall-exp"> <i class="material-icons">search</i> </label> <div class="mdl-textfield__expandable-holder"> <input class="mdl-textfield__input" type="text" name="sample" id="waterfall-exp"> </div> </div> </div> <!-- Bottom row, not visible on scroll --> <div class="mdl-layout__header-row"> <div class="mdl-layout-spacer"></div> <!-- Navigation --> <nav class="mdl-navigation"> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> </nav> </div> </header> <div class="mdl-layout__drawer"> <span class="mdl-layout-title">Title</span> <nav class="mdl-navigation"> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> <a class="mdl-navigation__link" href="">Link</a> </nav> </div> <main class="mdl-layout__content"> <div class="page-content"><!-- Your content goes here --></div> </main> </div>
<style></style>
<!-- Simple header with scrollable tabs. --> <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header"> <header class="mdl-layout__header"> <div class="mdl-layout__header-row"> <!-- Title --> <span class="mdl-layout-title">Title</span> </div> <!-- Tabs --> <div class="mdl-layout__tab-bar mdl-js-ripple-effect"> <a href="#scroll-tab-1" class="mdl-layout__tab is-active">Tab 1</a> <a href="#scroll-tab-2" class="mdl-layout__tab">Tab 2</a> <a href="#scroll-tab-3" class="mdl-layout__tab">Tab 3</a> <a href="#scroll-tab-4" class="mdl-layout__tab">Tab 4</a> <a href="#scroll-tab-5" class="mdl-layout__tab">Tab 5</a> <a href="#scroll-tab-6" class="mdl-layout__tab">Tab 6</a> </div> </header> <div class="mdl-layout__drawer"> <span class="mdl-layout-title">Title</span> </div> <main class="mdl-layout__content"> <section class="mdl-layout__tab-panel is-active" id="scroll-tab-1"> <div class="page-content"><!-- Your content goes here --></div> </section> <section class="mdl-layout__tab-panel" id="scroll-tab-2"> <div class="page-content"><!-- Your content goes here --></div> </section> <section class="mdl-layout__tab-panel" id="scroll-tab-3"> <div class="page-content"><!-- Your content goes here --></div> </section> <section class="mdl-layout__tab-panel" id="scroll-tab-4"> <div class="page-content"><!-- Your content goes here --></div> </section> <section class="mdl-layout__tab-panel" id="scroll-tab-5"> <div class="page-content"><!-- Your content goes here --></div> </section> <section class="mdl-layout__tab-panel" id="scroll-tab-6"> <div class="page-content"><!-- Your content goes here --></div> </section> </main> </div>
<style></style>
<!-- Simple header with fixed tabs. --> <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--fixed-tabs"> <header class="mdl-layout__header"> <div class="mdl-layout__header-row"> <!-- Title --> <span class="mdl-layout-title">Title</span> </div> <!-- Tabs --> <div class="mdl-layout__tab-bar mdl-js-ripple-effect"> <a href="#fixed-tab-1" class="mdl-layout__tab is-active">Tab 1</a> <a href="#fixed-tab-2" class="mdl-layout__tab">Tab 2</a> <a href="#fixed-tab-3" class="mdl-layout__tab">Tab 3</a> </div> </header> <div class="mdl-layout__drawer"> <span class="mdl-layout-title">Title</span> </div> <main class="mdl-layout__content"> <section class="mdl-layout__tab-panel is-active" id="fixed-tab-1"> <div class="page-content"><!-- Your content goes here --></div> </section> <section class="mdl-layout__tab-panel" id="fixed-tab-2"> <div class="page-content"><!-- Your content goes here --></div> </section> <section class="mdl-layout__tab-panel" id="fixed-tab-3"> <div class="page-content"><!-- Your content goes here --></div> </section> </main> </div>
<style></style>
Introduction
The Material Design Lite (MDL) layout component is a comprehensive approach to page layout that uses MDL development tenets, allows for efficient use of MDL components, and automatically adapts to different browsers, screen sizes, and devices.
Appropriate and accessible layout is a critical feature of all user interfaces, regardless of a site's content or function. Page design and presentation is therefore an important factor in the overall user experience. See the layout component's Material Design specifications page for details.
Use of MDL layout principles simplifies the creation of scalable pages by providing reusable components and encourages consistency across environments by establishing recognizable visual elements, adhering to logical structural grids, and maintaining appropriate spacing across multiple platforms and screen sizes. MDL layout is extremely powerful and dynamic, allowing for great consistency in outward appearance and behavior while maintaining development flexibility and ease of use.
To include a basic MDL layout component:
1. Code a <div>
element. This is the "outer" div that holds the entire layout.
<div>
</div>
Note: The layout cannot be applied directly on the
<body>
element. Always create a nested<div>
element.
2. Add MDL classes as indicated, separated by spaces, to the div using the class
attribute.
<div class="mdl-layout mdl-js-layout">
</div>
3. Inside the div, code a <header>
element. This holds the header row with navigation links that is displayed on large screens, and the menu icon that opens the navigation drawer for smaller screens. Add the MDL class to the header using the class
attribute.
<div class="mdl-layout mdl-js-layout">
<header class="mdl-layout__header">
</header>
</div>
4. Inside the header, add a <div>
to produce the menu icon, and include the MDL class as indicated. The div has no content of its own.
<div class="mdl-layout mdl-js-layout">
<header class="mdl-layout__header">
<div class="mdl-layout-icon"></div>
</header>
</div>
5. Still inside the header, add another <div>
to hold the header row's content, and include the MDL class as indicated.
<div class="mdl-layout mdl-js-layout">
<header class="mdl-layout__header">
<div class="mdl-layout-icon"></div>
<div class="mdl-layout__header-row">
</div>
</header>
</div>
6. Inside the header row div, add a span containing the layout title, and include the MDL class as indicated.
<div class="mdl-layout mdl-js-layout">
<header class="mdl-layout__header">
<div class="mdl-layout-icon"></div>
<div class="mdl-layout__header-row">
<span class="mdl-layout__title">Simple Layout</span>
</div>
</header>
</div>
7. Following the span, add a <div>
to align the header's navigation links to the right, and include the MDL class as indicated.
<div class="mdl-layout mdl-js-layout">
<header class="mdl-layout__header">
<div class="mdl-layout-icon"></div>
<div class="mdl-layout__header-row">
<span class="mdl-layout__title">Simple Layout</span>
<div class="mdl-layout-spacer"></div>
</div>
</header>
</div>
8. Following the spacer div, add a <nav>
element to contain the header's navigation links, and include the MDL class as indicated. Inside the nav, add one anchor <a>
element for each header link, and include the MDL class as indicated. This completes the layout's header.
<div class="mdl-layout mdl-js-layout">
<header class="mdl-layout__header">
<div class="mdl-layout-icon"></div>
<div class="mdl-layout__header-row">
<span class="mdl-layout__title">Simple Layout</span>
<div class="mdl-layout-spacer"></div>
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="#">Nav link 1</a>
<a class="mdl-navigation__link" href="#">Nav link 2</a>
<a class="mdl-navigation__link" href="#">Nav link 3</a>
</nav>
</div>
</header>
</div>
9. Following the header, add a <div>
element to hold the slide-out drawer's content, and add the MDL class as indicated. The drawer appears automatically on smaller screens, and may be opened with the menu icon on any screen size.
<div class="mdl-layout mdl-js-layout">
<header class="mdl-layout__header">
<div class="mdl-layout-icon"></div>
<div class="mdl-layout__header-row">
<span class="mdl-layout__title">Simple Layout</span>
<div class="mdl-layout-spacer"></div>
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="#">Nav link 1</a>
<a class="mdl-navigation__link" href="#">Nav link 2</a>
<a class="mdl-navigation__link" href="#">Nav link 3</a>
</nav>
</div>
</header>
<div class="mdl-layout__drawer">
</div>
</div>
10. Inside the drawer div, add a span containing the layout title (this should match the title in step 5), and include the MDL class as indicated.
<div class="mdl-layout mdl-js-layout">
<header class="mdl-layout__header">
<div class="mdl-layout-icon"></div>
<div class="mdl-layout__header-row">
<span class="mdl-layout__title">Simple Layout</span>
<div class="mdl-layout-spacer"></div>
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="#">Nav link 1</a>
<a class="mdl-navigation__link" href="#">Nav link 2</a>
<a class="mdl-navigation__link" href="#">Nav link 3</a>
</nav>
</div>
</header>
<div class="mdl-layout__drawer">
<span class="mdl-layout__title">Simple Layout</span>
</div>
</div>
11. Following the span, add a <nav>
element to contain the drawer's navigation links, and one anchor <a>
element for each drawer link (these should match the links in step 7), and include the MDL classes as indicated. This completes the layout's drawer.
<div class="mdl-layout mdl-js-layout">
<header class="mdl-layout__header">
<div class="mdl-layout-icon"></div>
<div class="mdl-layout__header-row">
<span class="mdl-layout__title">Simple Layout</span>
<div class="mdl-layout-spacer"></div>
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="#">Nav link 1</a>
<a class="mdl-navigation__link" href="#">Nav link 2</a>
<a class="mdl-navigation__link" href="#">Nav link 3</a>
</nav>
</div>
</header>
<div class="mdl-layout__drawer">
<span class="mdl-layout__title">Simple Layout</span>
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="#">Nav link 1</a>
<a class="mdl-navigation__link" href="#">Nav link 2</a>
<a class="mdl-navigation__link" href="#">Nav link 3</a>
</nav>
</div>
</div>
12. Finally, following the drawer div, add a <main>
element to hold the layout's primary content, and include the MDL class as indicated. Inside that element, add your desired content.
<div class="mdl-layout mdl-js-layout">
<header class="mdl-layout__header">
<div class="mdl-layout-icon"></div>
<div class="mdl-layout__header-row">
<span class="mdl-layout__title">Simple Layout</span>
<div class="mdl-layout-spacer"></div>
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="#">Nav link 1</a>
<a class="mdl-navigation__link" href="#">Nav link 2</a>
<a class="mdl-navigation__link" href="#">Nav link 3</a>
</nav>
</div>
</header>
<div class="mdl-layout__drawer">
<span class="mdl-layout__title">Simple Layout</span>
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="#">Nav link 1</a>
<a class="mdl-navigation__link" href="#">Nav link 2</a>
<a class="mdl-navigation__link" href="#">Nav link 3</a>
</nav>
</div>
<main class="mdl-layout__content">
<p>Content</p>
<p>Goes</p>
<p>Here</p>
</main>
</div>
The layout component is ready for use.
Examples
A layout with a fixed header for larger screens and a collapsible drawer for smaller screens.
<div class="mdl-layout mdl-js-layout">
<header class="mdl-layout__header">
<div class="mdl-layout-icon"></div>
<div class="mdl-layout__header-row">
<span class="mdl-layout__title">Material Design Lite</span>
<div class="mdl-layout-spacer"></div>
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="#">Hello</a>
<a class="mdl-navigation__link" href="#">World.</a>
<a class="mdl-navigation__link" href="#">How</a>
<a class="mdl-navigation__link" href="#">Are</a>
<a class="mdl-navigation__link" href="#">You?</a>
</nav>
</div>
</header>
<div class="mdl-layout__drawer">
<span class="mdl-layout__title">Material Design Lite</span>
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="#">Hello</a>
<a class="mdl-navigation__link" href="#">World.</a>
<a class="mdl-navigation__link" href="#">How</a>
<a class="mdl-navigation__link" href="#">Are</a>
<a class="mdl-navigation__link" href="#">You?</a>
</nav>
</div>
<main class="mdl-layout__content">
<div>Content</div>
</main>
</div>
The same layout with a non-fixed header that scrolls with the content.
<div class="mdl-layout mdl-js-layout">
<header class="mdl-layout__header mdl-layout__header--scroll">
<img class="mdl-layout-icon"></img>
<div class="mdl-layout__header-row">
<span class="mdl-layout__title">Material Design Lite</span>
<div class="mdl-layout-spacer"></div>
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="#">Hello</a>
<a class="mdl-navigation__link" href="#">World.</a>
<a class="mdl-navigation__link" href="#">How</a>
<a class="mdl-navigation__link" href="#">Are</a>
<a class="mdl-navigation__link" href="#">You?</a>
</nav>
</div>
</header>
<div class="mdl-layout__drawer">
<span class="mdl-layout__title">Material Design Lite</span>
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="#">Hello</a>
<a class="mdl-navigation__link" href="#">World.</a>
<a class="mdl-navigation__link" href="#">How</a>
<a class="mdl-navigation__link" href="#">Are</a>
<a class="mdl-navigation__link" href="#">You?</a>
</nav>
</div>
<main class="mdl-layout__content">
<div>Content</div>
</main>
</div>
A layout with a fixed drawer that serves as sidebar navigation on larger screens. The drawer collapses and the menu icon is displayed on smaller screens.
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-drawer">
<header class="mdl-layout__header">
<div class="mdl-layout__header-row">
<span class="mdl-layout__title">Fixed drawer layout demo</span>
</div>
</header>
<div class="mdl-layout__drawer">
<span class="mdl-layout__title">Material Design Lite</span>
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="#">Hello</a>
<a class="mdl-navigation__link" href="#">World.</a>
<a class="mdl-navigation__link" href="#">How</a>
<a class="mdl-navigation__link" href="#">Are</a>
<a class="mdl-navigation__link" href="#">You?</a>
</nav>
</div>
<main class="mdl-layout__content">
<div>Content</div>
</main>
</div>
A layout with a fixed drawer but no header.
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-drawer">
<div class="mdl-layout__drawer">
<span class="mdl-layout__title">Material Design Lite</span>
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="#">Hello</a>
<a class="mdl-navigation__link" href="#">World.</a>
<a class="mdl-navigation__link" href="#">How</a>
<a class="mdl-navigation__link" href="#">Are</a>
<a class="mdl-navigation__link" href="#">You?</a>
</nav>
</div>
<main class="mdl-layout__content">
<div>Content</div>
</main>
</div>
Configuration options
The MDL CSS classes apply various predefined visual and behavioral enhancements to the layout. The table below lists the available classes and their effects.
MDL class | Effect | Remarks |
---|---|---|
mdl-layout |
Defines container as an MDL component | Required on outer div element |
mdl-js-layout |
Assigns basic MDL behavior to layout | Required on outer div element |
mdl-layout__header |
Defines container as an MDL component | Required on header element |
mdl-layout-icon |
Used for adding an application icon. Gets concealed by menu icon if both are visible. | Goes on optional icon element |
mdl-layout__header-row |
Defines container as MDL header row | Required on header content div |
mdl-layout__title |
Defines layout title text | Required on layout title span |
mdl-layout-spacer |
Used to align elements inside a header or drawer, by growing to fill remaining space. Commonly used for aligning elements to the right. | Goes on optional div following layout title |
mdl-navigation |
Defines container as MDL navigation group | Required on nav element |
mdl-navigation__link |
Defines anchor as MDL navigation link | Required on header and/or drawer anchor elements |
mdl-layout__drawer |
Defines container as MDL layout drawer | Required on drawer div element |
mdl-layout__content |
Defines container as MDL layout content | Required on main element |
mdl-layout__header--scroll |
Makes the header scroll with the content | Optional; goes on header element |
mdl-layout--fixed-drawer |
Makes the drawer always visible and open in larger screens | Optional; goes on outer div element (not drawer div element) |
mdl-layout--fixed-header |
Makes the header always visible, even in small screens | Optional; goes on outer div element |
mdl-layout--no-drawer-button |
Does not display a drawer button | Optional; goes on mdl-layout element |
mdl-layout--no-desktop-drawer-button |
Does not display a drawer button in desktop mode | Optional; goes on mdl-layout element |
mdl-layout--large-screen-only |
Hides an element on smaller screens | Optional; goes on any descendant of mdl-layout |
mdl-layout--small-screen-only |
Hides an element on larger screens | Optional; goes on any descendant of mdl-layout |
mdl-layout__header--waterfall |
Allows a "waterfall" effect with multiple header lines | Optional; goes on header element |
mdl-layout__header--waterfall-hide-top |
Hides the top rather than the bottom rows on a waterfall header | Optional; goes on header element. Requires mdl-layout__header--waterfall |
mdl-layout__header--transparent |
Makes header transparent (draws on top of layout background) | Optional; goes on header element |
mdl-layout__header--seamed |
Uses a header without a shadow | Optional; goes on header element |
mdl-layout__tab-bar |
Defines container as an MDL tab bar | Required on div element inside header (tabbed layout) |
mdl-layout__tab |
Defines anchor as MDL tab link | Required on tab bar anchor elements |
is-active |
Defines tab as default active tab | Optional; goes on tab bar anchor element and associated tab section element |
mdl-layout__tab-panel |
Defines container as tab content panel | Required on tab section elements |
mdl-layout__tab-manual-switch |
Disables tab switching when clicking on tab separators. Useful for disabling default behavior and setting up your own event listeners. | Optional; goes on tab bar element |
mdl-layout--fixed-tabs |
Uses fixed tabs instead of the default scrollable tabs | Optional; goes on outer div element (not div inside header) |
Grid
<div class="mdl-grid"> <div class="mdl-cell mdl-cell--1-col">1</div> <div class="mdl-cell mdl-cell--1-col">1</div> <div class="mdl-cell mdl-cell--1-col">1</div> <div class="mdl-cell mdl-cell--1-col">1</div> <div class="mdl-cell mdl-cell--1-col">1</div> <div class="mdl-cell mdl-cell--1-col">1</div> <div class="mdl-cell mdl-cell--1-col">1</div> <div class="mdl-cell mdl-cell--1-col">1</div> <div class="mdl-cell mdl-cell--1-col">1</div> <div class="mdl-cell mdl-cell--1-col">1</div> <div class="mdl-cell mdl-cell--1-col">1</div> <div class="mdl-cell mdl-cell--1-col">1</div> </div> <div class="mdl-grid"> <div class="mdl-cell mdl-cell--4-col">4</div> <div class="mdl-cell mdl-cell--4-col">4</div> <div class="mdl-cell mdl-cell--4-col">4</div> </div> <div class="mdl-grid"> <div class="mdl-cell mdl-cell--6-col">6</div> <div class="mdl-cell mdl-cell--4-col">4</div> <div class="mdl-cell mdl-cell--2-col">2</div> </div> <div class="mdl-grid"> <div class="mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet">6 (8 tablet)</div> <div class="mdl-cell mdl-cell--4-col mdl-cell--6-col-tablet">4 (6 tablet)</div> <div class="mdl-cell mdl-cell--2-col mdl-cell--4-col-phone">2 (4 phone)</div> </div>
<style>.mdl-cell { box-sizing: border-box; background-color: #BDBDBD; height: 200px; padding-left: 8px; padding-top: 4px; color: white; } .mdl-grid:first-of-type .mdl-cell { height: 50px; } </style>
Introduction
The Material Design Lite (MDL) grid component is a simplified method for laying out content for multiple screen sizes. It reduces the usual coding burden required to correctly display blocks of content in a variety of display conditions.
The MDL grid is defined and enclosed by a container element. A grid has 12 columns in the desktop screen size, 8 in the tablet size, and 4 in the phone size, each size having predefined margins and gutters. Cells are laid out sequentially in a row, in the order they are defined, with some exceptions:
- If a cell doesn't fit in the row in one of the screen sizes, it flows into the following line.
- If a cell has a specified column size equal to or larger than the number of columns for the current screen size, it takes up the entirety of its row.
You can set a maximum grid width, after which the grid stays centered with padding on either side, by setting its max-width
CSS property.
Grids are a fairly new and non-standardized feature in most user interfaces, and provide users with a way to view content in an organized manner that might otherwise be difficult to understand or retain. Their design and use is an important factor in the overall user experience.
To include an MDL grid component:
1. Code a <div>
element; this is the "outer" container, intended to hold all of the grid's cells. Style the div as desired (colors, font size, etc.).
<div>
</div>
2. Add the mdl-grid
MDL class to the div using the class
attribute.
<div class="mdl-grid">
</div>
3. For each cell, code one "inner" div, including the text to be displayed.
<div class="mdl-grid">
<div>Content</div>
<div>goes</div>
<div>here</div>
</div>
4. Add the mdl-cell
class and an mdl-cell--COLUMN-col
class, where COLUMN specifies the column size for the cell, to the "inner" divs using the class
attribute.
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--4-col">Content</div>
<div class="mdl-cell mdl-cell--4-col">goes</div>
<div class="mdl-cell mdl-cell--4-col">here</div>
</div>
5. Optionally add an mdl-cell--COLUMN-col-DEVICE
class, where COLUMN specifies the column size for the cell on a specific device, and DEVICE specifies the device type.
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--4-col mdl-cell--8-col-tablet">Content</div>
<div class="mdl-cell mdl-cell--4-col mdl-cell--8-col-tablet">goes</div>
<div class="mdl-cell mdl-cell--4-col mdl-cell--8-col-tablet">here</div>
</div>
The grid component is ready for use.
Examples
A grid with five cells of column size 1.
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--1-col">CS 1</div>
<div class="mdl-cell mdl-cell--1-col">CS 1</div>
<div class="mdl-cell mdl-cell--1-col">CS 1</div>
<div class="mdl-cell mdl-cell--1-col">CS 1</div>
<div class="mdl-cell mdl-cell--1-col">CS 1</div>
</div>
A grid with three cells, one of column size 6, one of column size 4, and one of column size 2.
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--6-col">CS 6</div>
<div class="mdl-cell mdl-cell--4-col">CS 4</div>
<div class="mdl-cell mdl-cell--2-col">CS 2</div>
</div>
A grid with three cells of column size 6 that will display as column size 8 on a tablet device.
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet">CS 6 (8 on tablet)</div>
<div class="mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet">CS 6 (8 on tablet)</div>
<div class="mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet">CS 6 (8 on tablet)</div>
</div>
A grid with four cells of column size 2 that will display as column size 4 on a phone device.
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--2-col mdl-cell--4-col-phone">CS 2 (4 on phone)</div>
<div class="mdl-cell mdl-cell--2-col mdl-cell--4-col-phone">CS 2 (4 on phone)</div>
<div class="mdl-cell mdl-cell--2-col mdl-cell--4-col-phone">CS 2 (4 on phone)</div>
<div class="mdl-cell mdl-cell--2-col mdl-cell--4-col-phone">CS 2 (4 on phone)</div>
</div>
Configuration options
The MDL CSS classes apply various predefined visual enhancements and behavioral effects to the grid. The table below lists the available classes and their effects.
MDL class | Effect | Remarks |
---|---|---|
mdl-grid |
Defines a container as an MDL grid component | Required on "outer" div element |
mdl-cell |
Defines a container as an MDL cell | Required on "inner" div elements |
mdl-grid--no-spacing |
Modifies the grid cells to have no margin between them. | Optional on grid container. |
mdl-cell--N-col |
Sets the column size for the cell to N | N is 1-12 inclusive, defaults to 4; optional on "inner" div elements |
mdl-cell--N-col-desktop |
Sets the column size for the cell to N in desktop mode only | N is 1-12 inclusive; optional on "inner" div elements |
mdl-cell--N-col-tablet |
Sets the column size for the cell to N in tablet mode only | N is 1-8 inclusive; optional on "inner" div elements |
mdl-cell--N-col-phone |
Sets the column size for the cell to N in phone mode only | N is 1-4 inclusive; optional on "inner" div elements |
mdl-cell--N-offset |
Adds N columns of whitespace before the cell | N is 1-11 inclusive; optional on "inner" div elements |
mdl-cell--N-offset-desktop |
Adds N columns of whitespace before the cell in desktop mode | N is 1-11 inclusive; optional on "inner" div elements |
mdl-cell--N-offset-tablet |
Adds N columns of whitespace before the cell in tablet mode | N is 1-7 inclusive; optional on "inner" div elements |
mdl-cell--N-offset-phone |
Adds N columns of whitespace before the cell in phone mode | N is 1-3 inclusive; optional on "inner" div elements |
mdl-cell--order-N |
Reorders cell to position N | N is 1-12 inclusive; optional on "inner" div elements |
mdl-cell--order-N-desktop |
Reorders cell to position N when in desktop mode | N is 1-12 inclusive; optional on "inner" div elements |
mdl-cell--order-N-tablet |
Reorders cell to position N when in tablet mode | N is 1-12 inclusive; optional on "inner" div elements |
mdl-cell--order-N-phone |
Reorders cell to position N when in phone mode | N is 1-12 inclusive; optional on "inner" div elements |
mdl-cell--hide-desktop |
Hides the cell when in desktop mode | Optional on "inner" div elements |
mdl-cell--hide-tablet |
Hides the cell when in tablet mode | Optional on "inner" div elements |
mdl-cell--hide-phone |
Hides the cell when in phone mode | Optional on "inner" div elements |
mdl-cell--stretch |
Stretches the cell vertically to fill the parent | Default; optional on "inner" div elements |
mdl-cell--top |
Aligns the cell to the top of the parent | Optional on "inner" div elements |
mdl-cell--middle |
Aligns the cell to the middle of the parent | Optional on "inner" div elements |
mdl-cell--bottom |
Aligns the cell to the bottom of the parent | Optional on "inner" div elements |
Tabs
- Eddard
- Catelyn
- Robb
- Sansa
- Brandon
- Arya
- Rickon
- Tywin
- Cersei
- Jamie
- Tyrion
- Viserys
- Daenerys
<div class="mdl-tabs mdl-js-tabs mdl-js-ripple-effect"> <div class="mdl-tabs__tab-bar"> <a href="#starks-panel" class="mdl-tabs__tab is-active">Starks</a> <a href="#lannisters-panel" class="mdl-tabs__tab">Lannisters</a> <a href="#targaryens-panel" class="mdl-tabs__tab">Targaryens</a> </div> <div class="mdl-tabs__panel is-active" id="starks-panel"> <ul> <li>Eddard</li> <li>Catelyn</li> <li>Robb</li> <li>Sansa</li> <li>Brandon</li> <li>Arya</li> <li>Rickon</li> </ul> </div> <div class="mdl-tabs__panel" id="lannisters-panel"> <ul> <li>Tywin</li> <li>Cersei</li> <li>Jamie</li> <li>Tyrion</li> </ul> </div> <div class="mdl-tabs__panel" id="targaryens-panel"> <ul> <li>Viserys</li> <li>Daenerys</li> </ul> </div> </div>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
Introduction
The Material Design Lite (MDL) tab component is a user interface element that allows different content blocks to share the same screen space in a mutually exclusive manner. Tabs are always presented in sets of two or more, and they make it easy to explore and switch among different views or functional aspects of an app, or to browse categorized data sets individually. Tabs serve as "headings" for their respective content; the active tab — the one whose content is currently displayed — is always visually distinguished from the others so the user knows which heading the current content belongs to.
Tabs are an established but non-standardized feature in user interfaces, and allow users to view different, but often related, blocks of content (often called panels). Tabs save screen real estate and provide intuitive and logical access to data while reducing navigation and associated user confusion. Their design and use is an important factor in the overall user experience. See the tab component's Material Design specifications page for details.
To include a set of MDL tab components:
1. Code a <div>
element; this is the "outer" div, intended to contain all of the tabs and their content.
<div>
</div>
2. Inside the "outer" div, code one "inner" div for the tabs themselves, and one for each tab's content, all siblings. That is, for three content tabs, you would code four "inner" divs.
<div>
<div>
...
</div>
<div>
...
</div>
<div>
...
</div>
<div>
...
</div>
</div>
3. Inside the first "inner" div (the tabs), code one anchor <a>
(link) tag for each tab. Include href
attributes with values to match the tabs' id
attribute values, and some brief link text. On the remaining "inner" divs (the content), code id
attributes whose values match the links' href
s.
<div>
<div>
<a href="#tab1">Tab One</a>
<a href="#tab2">Tab Two</a>
<a href="#tab3">Tab Three</a>
</div>
<div id="tab1">
...
</div>
<div id="tab2">
...
</div>
<div id="tab3">
...
</div>
</div>
4. Inside the remaining "inner" divs, code the content you intend to display in each panel; use standard HTML tags to structure the content as desired.
<div>
<div>
<a href="#tab1">Tab One</a>
<a href="#tab2">Tab Two</a>
<a href="#tab3">Tab Three</a>
</div>
<div id="tab1">
<p>First tab's content.</p>
</div>
<div id="tab2">
<p>Second tab's content.</p>
</div>
<div id="tab3">
<p>Third tab's content.</p>
</div>
</div>
5. Add one or more MDL classes, separated by spaces, to the "outer" and "inner" divs using the class
attribute; be sure to include the is-active
class on the tab you want to be displayed by default.
<div class="mdl-tabs mdl-js-tabs">
<div class="mdl-tabs__tab-bar">
<a href="#tab1" class="mdl-tabs__tab">Tab One</a>
<a href="#tab2" class="mdl-tabs__tab">Tab Two</a>
<a href="#tab3" class="mdl-tabs__tab">Tab Three</a>
</div>
<div class="mdl-tabs__panel is-active" id="tab1">
<p>First tab's content.</p>
</div>
<div class="mdl-tabs__panel" id="tab2">
<p>Second tab's content.</p>
</div>
<div class="mdl-tabs__panel" id="tab3">
<p>Third tab's content.</p>
</div>
</div>
The tab components are ready for use.
Example
Three tabs, with ripple effect on tab links.
<div class="mdl-tabs mdl-js-tabs mdl-js-ripple-effect">
<div class="mdl-tabs__tab-bar">
<a href="#about-panel" class="mdl-tabs__tab is-active">About the Beatles</a>
<a href="#members-panel" class="mdl-tabs__tab">Members</a>
<a href="#albums-panel" class="mdl-tabs__tab">Discography</a>
</div>
<div class="mdl-tabs__panel is-active" id="about-panel">
<p><b>The Beatles</b> were a four-piece musical group from Liverpool, England.
Formed in 1960, their career spanned just over a decade, yet they are widely
regarded as the most influential band in history.</p>
<p>Their songs are among the best-loved music of all time. It is said that every
minute of every day, a radio station somewhere is playing a Beatles song.</p>
</div>
<div class="mdl-tabs__panel" id="members-panel">
<p>The Beatles' members were:</p>
<ul>
<li>John Lennon (1940-1980)</li>
<li>Paul McCartney (1942-)</li>
<li>George Harrison (1943-2001)</li>
<li>Ringo Starr (1940-)</li>
</ul>
</div>
<div class="mdl-tabs__panel" id="albums-panel">
<p>The Beatles' original UK LPs, in order of release:</p>
<ol>
<li>Please Please Me (1963)</li>
<li>With the Beatles (1963)</li>
<li>A Hard Day's Night (1964)</li>
<li>Beatles for Sale (1964)</li>
<li>Help! (1965)</li>
<li>Rubber Soul (1965)</li>
<li>Revolver (1966)</li>
<li>Sgt. Pepper's Lonely Hearts Club Band (1967)</li>
<li>The Beatles ("The White Album", 1968)</li>
<li>Yellow Submarine (1969)</li>
<li>Abbey Road (1969)</li>
<li>Let It Be (1970)</li>
</ol>
</div>
</div>
Configuration options
The MDL CSS classes apply various predefined visual and behavioral enhancements to the tabs. The table below lists the available classes and their effects.
MDL class | Effect | Remarks |
---|---|---|
mdl-tabs |
Defines a tabs container as an MDL component | Required on "outer" div element |
mdl-js-tabs |
Assigns basic MDL behavior to tabs container | Required on "outer" div element |
mdl-js-ripple-effect |
Applies ripple click effect to tab links | Optional; goes on "outer" div element |
mdl-tabs__tab-bar |
Defines a container as an MDL tabs link bar | Required on first "inner" div element |
mdl-tabs__tab |
Defines an anchor (link) as an MDL tab activator | Required on all links in first "inner" div element |
is-active |
Defines a tab as the default display tab | Required on one (and only one) of the "inner" div (tab) elements |
mdl-tabs__panel |
Defines a container as tab content | Required on each of the "inner" div (tab) elements |
Footer
<footer class="mdl-mega-footer"> <div class="mdl-mega-footer__middle-section"> <div class="mdl-mega-footer__drop-down-section"> <input class="mdl-mega-footer__heading-checkbox" type="checkbox" checked> <h1 class="mdl-mega-footer__heading">Features</h1> <ul class="mdl-mega-footer__link-list"> <li><a href="#">About</a></li> <li><a href="#">Terms</a></li> <li><a href="#">Partners</a></li> <li><a href="#">Updates</a></li> </ul> </div> <div class="mdl-mega-footer__drop-down-section"> <input class="mdl-mega-footer__heading-checkbox" type="checkbox" checked> <h1 class="mdl-mega-footer__heading">Details</h1> <ul class="mdl-mega-footer__link-list"> <li><a href="#">Specs</a></li> <li><a href="#">Tools</a></li> <li><a href="#">Resources</a></li> </ul> </div> <div class="mdl-mega-footer__drop-down-section"> <input class="mdl-mega-footer__heading-checkbox" type="checkbox" checked> <h1 class="mdl-mega-footer__heading">Technology</h1> <ul class="mdl-mega-footer__link-list"> <li><a href="#">How it works</a></li> <li><a href="#">Patterns</a></li> <li><a href="#">Usage</a></li> <li><a href="#">Products</a></li> <li><a href="#">Contracts</a></li> </ul> </div> <div class="mdl-mega-footer__drop-down-section"> <input class="mdl-mega-footer__heading-checkbox" type="checkbox" checked> <h1 class="mdl-mega-footer__heading">FAQ</h1> <ul class="mdl-mega-footer__link-list"> <li><a href="#">Questions</a></li> <li><a href="#">Answers</a></li> <li><a href="#">Contact us</a></li> </ul> </div> </div> <div class="mdl-mega-footer__bottom-section"> <div class="mdl-logo">Title</div> <ul class="mdl-mega-footer__link-list"> <li><a href="#">Help</a></li> <li><a href="#">Privacy & Terms</a></li> </ul> </div> </footer>
<style></style>
<footer class="mdl-mini-footer"> <div class="mdl-mini-footer__left-section"> <div class="mdl-logo">Title</div> <ul class="mdl-mini-footer__link-list"> <li><a href="#">Help</a></li> <li><a href="#">Privacy & Terms</a></li> </ul> </div> </footer>
<style></style>
Introduction
The Material Design Lite (MDL) footer component is a comprehensive container intended to present a substantial amount of related content in a visually attractive and logically intuitive area. Although it is called "footer", it may be placed at any appropriate location on a device screen, either before or after other content.
An MDL footer component takes two basic forms: mega-footer and mini-footer. As the names imply, mega-footers contain more (and more complex) content than mini-footers. A mega-footer presents multiple sections of content separated by horizontal rules, while a mini-footer presents a single section of content. Both footer forms have their own internal structures, including required and optional elements, and typically include both informational and clickable content, such as links.
Footers, as represented by this component, are a fairly new feature in user interfaces, and allow users to view discrete blocks of content in a coherent and consistently organized way. Their design and use is an important factor in the overall user experience.
To include an MDL mega-footer component:
1a. Code a <footer>
element. Inside the footer, include one <div>
element for each content section, typically three: top, middle, and bottom.
<footer>
<div>
...
</div>
<div>
...
</div>
<div>
...
</div>
</footer>
1b. Add the appropriate MDL classes to the footer and divs using the class
attribute.
<footer class="mdl-mega-footer">
<div class="mdl-mega-footer__top-section">
...
</div>
<div class="mdl-mega-footer__middle-section">
...
</div>
<div class="mdl-mega-footer__bottom-section">
...
</div>
</footer>
2a. Inside the top section div, code two sibling "inner" divs for the left and right content sections.
<footer class="mdl-mega-footer">
<div class="mdl-mega-footer__top-section">
<div>
...
</div>
<div>
...
</div>
</div>
<div class="mdl-mega-footer__middle-section">
...
</div>
<div class="mdl-mega-footer__bottom-section">
...
</div>
</footer>
2b. Add the appropriate MDL classes to the two "inner" left and right divs using the class
attribute.
<footer class="mdl-mega-footer">
<div class="mdl-mega-footer__top-section">
<div class="mdl-mega-footer__left-section">
...
</div>
<div class="mdl-mega-footer__right-section">
...
</div>
</div>
<div class="mdl-mega-footer__middle-section">
...
</div>
<div class="mdl-mega-footer__bottom-section">
...
</div>
</footer>
3a. Inside the middle section div, code one or more sibling "inner" divs for the drop-down content sections. That is, for two drop-down sections, you would code two divs.
<footer class="mdl-mega-footer">
<div class="mdl-mega-footer__top-section">
<div class="mdl-mega-footer__left-section">
...
</div>
<div class="mdl-mega-footer__right-section">
...
</div>
</div>
<div class="mdl-mega-footer__middle-section">
<div>
...
</div>
<div>
...
</div>
</div>
<div class="mdl-mega-footer__bottom-section">
...
</div>
</footer>
3b. Add the appropriate MDL classes to the two "inner" drop-down divs using the class
attribute.
<footer class="mdl-mega-footer">
<div class="mdl-mega-footer__top-section">
<div class="mdl-mega-footer__left-section">
...
</div>
<div class="mdl-mega-footer__right-section">
...
</div>
</div>
<div class="mdl-mega-footer__middle-section">
<div class="mdl-mega-footer__drop-down-section">
...
</div>
<div class="mdl-mega-footer__drop-down-section">
...
</div>
</div>
<div class="mdl-mega-footer__bottom-section">
...
</div>
</footer>
4a. Inside the bottom section div, code an "inner" div for the section heading and a sibling unordered list for the bottom section links.
<footer class="mdl-mega-footer">
<div class="mdl-mega-footer__top-section">
<div class="mdl-mega-footer__left-section">
...
</div>
<div class="mdl-mega-footer__right-section">
...
</div>
</div>
<div class="mdl-mega-footer__middle-section">
<div class="mdl-mega-footer__drop-down-section">
...
</div>
<div class="mdl-mega-footer__drop-down-section">
...
</div>
</div>
<div class="mdl-mega-footer__bottom-section">
<div>
...
</div>
<ul>
...
</ul>
</div>
</footer>
4b. Add the appropriate MDL classes to the "inner" div heading and list using the class
attribute.
<footer class="mdl-mega-footer">
<div class="mdl-mega-footer__top-section">
<div class="mdl-mega-footer__left-section">
...
</div>
<div class="mdl-mega-footer__right-section">
...
</div>
</div>
<div class="mdl-mega-footer__middle-section">
<div class="mdl-mega-footer__drop-down-section">
...
</div>
<div class="mdl-mega-footer__drop-down-section">
...
</div>
</div>
<div class="mdl-mega-footer__bottom-section">
<div class="mdl-logo">
</div>
<ul class="mdl-mega-footer__link-list">
...
</ul>
</div>
</footer>
5. Add content to the top (left and right), middle (drop-downs), and bottom (text and links) sections of the footer; include any appropriate MDL classes using the class
attribute.
<footer class="mdl-mega-footer">
<div class="mdl-mega-footer__top-section">
<div class="mdl-mega-footer__left-section">
<button class="mdl-mega-footer__social-btn"></button>
<button class="mdl-mega-footer__social-btn"></button>
<button class="mdl-mega-footer__social-btn"></button>
</div>
<div class="mdl-mega-footer__right-section">
<a href="">Link 1</a>
<a href="">Link 2</a>
<a href="">Link 3</a>
</div>
</div>
<div class="mdl-mega-footer__middle-section">
<div class="mdl-mega-footer__drop-down-section">
<h1 class="mdl-mega-footer__heading">Drop-down 1 Heading</h1>
<ul class="mdl-mega-footer__link-list">
<li><a href="">Link A</a></li>
<li><a href="">Link B</a></li>
<li><a href="">Link C</a></li>
<li><a href="">Link D</a></li>
</ul>
</div>
<div class="mdl-mega-footer__drop-down-section">
<h1 class="mdl-mega-footer__heading">Drop-down 2 Heading</h1>
<ul class="mdl-mega-footer__link-list">
<li><a href="">Link A</a></li>
<li><a href="">Link B</a></li>
<li><a href="">Link C</a></li>
</ul>
</div>
</div>
<div class="mdl-mega-footer__bottom-section">
<div class="mdl-logo">
Mega-Footer Bottom Section Heading
</div>
<ul class="mdl-mega-footer__link-list">
<li><a href="">Link A</a></li>
<li><a href="">Link B</a></li>
</ul>
</div>
</footer>
The mega-footer component is ready for use.
Examples
A mega-footer component with three sections and two drop-down sections in the middle section.
<footer class="mdl-mega-footer">
<div class="mdl-mega-footer__top-section">
<div class="mdl-mega-footer__left-section">
<button class="mdl-mega-footer__social-btn"></button>
<button class="mdl-mega-footer__social-btn"></button>
<button class="mdl-mega-footer__social-btn"></button>
</div>
<div class="mdl-mega-footer__right-section">
<a href="#">Introduction</a>
<a href="#">App Status Dashboard</a>
<a href="#">Terms of Service</a>
</div>
</div>
<div class="mdl-mega-footer__middle-section">
<div class="mdl-mega-footer__drop-down-section">
<h1 class="mdl-mega-footer__heading">Learning and Support</h1>
<ul class="mdl-mega-footer__link-list">
<li><a href="#">Resource Center</a></li>
<li><a href="#">Help Center</a></li>
<li><a href="#">Community</a></li>
<li><a href="#">Learn with Google</a></li>
<li><a href="#">Small Business Community</a></li>
<li><a href="#">Think Insights</a></li>
</ul>
</div>
<div class="mdl-mega-footer__drop-down-section">
<h1 class="mdl-mega-footer__heading">Just for Developers</h1>
<ul class="mdl-mega-footer__link-list">
<li><a href="#">Google Developers</a></li>
<li><a href="#">AdWords API</a></li>
<li><a href="#">AdWords Scipts</a></li>
<li><a href="#">AdWords Remarketing Tag</a></li>
</ul>
</div>
</div>
<div class="mdl-mega-footer__bottom-section">
<div class="mdl-logo">
More Information
</div>
<ul class="mdl-mega-footer__link-list">
<li><a href="#">Help</a></li>
<li><a href="#">Privacy and Terms</a></li>
</ul>
</div>
</footer>
To include an MDL mini-footer component:
1a. Code a <footer>
element. Inside the footer, code two <div>
elements, one for the left section and one for the right section.
<footer>
<div>
...
</div>
<div>
...
</div>
</footer>
1b. Add the appropriate MDL classes to the footer and divs using the class
attribute.
<footer class="mdl-mini-footer">
<div class="mdl-mini-footer__left-section">
...
</div>
<div class="mdl-mini-footer__right-section">
...
</div>
</footer>
2a. Inside the left section div, code an "inner" div for the section heading and a sibling unordered list for the left section links.
<footer class="mdl-mini-footer">
<div class="mdl-mini-footer__left-section">
<div>
...
</div>
<ul>
...
</ul>
</div>
<div class="mdl-mini-footer__right-section">
...
</div>
</footer>
2b. Add the appropriate MDL classes to the "inner" div and list using the class
attribute.
<footer class="mdl-mini-footer">
<div class="mdl-mini-footer__left-section">
<div class="mdl-logo">
...
</div>
<ul class="mdl-mini-footer__link-list">
...
</ul>
</div>
<div class="mdl-mini-footer__right-section">
...
</div>
</footer>
3. Add content to the left (text and links) and right (text or decoration) sections of the footer; include any appropriate MDL classes using the class
attribute.
<footer class="mdl-mini-footer">
<div class="mdl-mini-footer__left-section">
<div class="mdl-logo">
Mini-footer Heading
</div>
<ul class="mdl-mini-footer__link-list">
<li><a href="">Link 1</a></li>
<li><a href="">Link 2</a></li>
<li><a href="">Link 3</a></li>
</ul>
</div>
<div class="mdl-mini-footer__right-section">
<button class="mdl-mini-footer__social-btn"></button>
<button class="mdl-mini-footer__social-btn"></button>
<button class="mdl-mini-footer__social-btn"></button>
</div>
</footer>
The mini-footer component is ready for use.
Examples
A mini-footer with left and right sections.
<footer class="mdl-mini-footer">
<div class="mdl-mini-footer__left-section">
<div class="mdl-logo">
More Information
</div>
<ul class="mdl-mini-footer__link-list">
<li><a href="#">Help</a></li>
<li><a href="#">Privacy and Terms</a></li>
<li><a href="#">User Agreement</a></li>
</ul>
</div>
<div class="mdl-mini-footer__right-section">
<button class="mdl-mini-footer__social-btn"></button>
<button class="mdl-mini-footer__social-btn"></button>
<button class="mdl-mini-footer__social-btn"></button>
</div>
</footer>
Configuration options
The MDL CSS classes apply various predefined visual enhancements to the footer. The table below lists the available classes and their effects.
MDL class | Effect | Remarks |
---|---|---|
mdl-mega-footer |
Defines container as an MDL mega-footer component | Required on footer element |
mdl-mega-footer__top-section |
Defines container as a footer top section | Required on top section "outer" div element |
mdl-mega-footer__left-section |
Defines container as a left section | Required on left section "inner" div element |
mdl-mega-footer__social-btn |
Defines a decorative square within mega-footer | Required on button element (if used) |
mdl-mega-footer__right-section |
Defines container as a right section | Required on right section "inner" div element |
mdl-mega-footer__middle-section |
Defines container as a footer middle section | Required on middle section "outer" div element |
mdl-mega-footer__drop-down-section |
Defines container as a drop-down (vertical) content area | Required on drop-down "inner" div elements |
mdl-mega-footer__heading |
Defines a heading as a mega-footer heading | Required on h1 element inside drop-down section |
mdl-mega-footer__link-list |
Defines an unordered list as a drop-down (vertical) list | Required on ul element inside drop-down section |
mdl-mega-footer__bottom-section |
Defines container as a footer bottom section | Required on bottom section "outer" div element |
mdl-logo |
Defines a container as a styled section heading | Required on "inner" div element in mega-footer bottom-section or mini-footer left-section |
mdl-mini-footer |
Defines container as an MDL mini-footer component | Required on footer element |
mdl-mini-footer__left-section |
Defines container as a left section | Required on left section "inner" div element |
mdl-mini-footer__link-list |
Defines an unordered list as an inline (horizontal) list | Required on ul element sibling to "mdl-logo" div element |
mdl-mini-footer__right-section |
Defines container as a right section | Required on right section "inner" div element |
mdl-mini-footer__social-btn |
Defines a decorative square within mini-footer | Required on button element (if used) |
Lists
Customizable scrollable lists.
- Bryan Cranston
- Aaron Paul
- Bob Odenkirk
<!-- Simple list --> <style> .demo-list-item { width: 300px; } </style> <ul class="demo-list-item mdl-list"> <li class="mdl-list__item"> <span class="mdl-list__item-primary-content"> Bryan Cranston </span> </li> <li class="mdl-list__item"> <span class="mdl-list__item-primary-content"> Aaron Paul </span> </li> <li class="mdl-list__item"> <span class="mdl-list__item-primary-content"> Bob Odenkirk </span> </li> </ul>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
<!-- Icon List --> <style> .demo-list-icon { width: 300px; } </style> <ul class="demo-list-icon mdl-list"> <li class="mdl-list__item"> <span class="mdl-list__item-primary-content"> <i class="material-icons mdl-list__item-icon">person</i> Bryan Cranston </span> </li> <li class="mdl-list__item"> <span class="mdl-list__item-primary-content"> <i class="material-icons mdl-list__item-icon">person</i> Aaron Paul </span> </li> <li class="mdl-list__item"> <span class="mdl-list__item-primary-content"> <i class="material-icons mdl-list__item-icon">person</i> Bob Odenkirk </span> </li> </ul>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
<!-- List items with avatar and action --> <style> .demo-list-action { width: 300px; } </style> <div class="demo-list-action mdl-list"> <div class="mdl-list__item"> <span class="mdl-list__item-primary-content"> <i class="material-icons mdl-list__item-avatar">person</i> <span>Bryan Cranston</span> </span> <a class="mdl-list__item-secondary-action" href="#"><i class="material-icons">star</i></a> </div> <div class="mdl-list__item"> <span class="mdl-list__item-primary-content"> <i class="material-icons mdl-list__item-avatar">person</i> <span>Aaron Paul</span> </span> <a class="mdl-list__item-secondary-action" href="#"><i class="material-icons">star</i></a> </div> <div class="mdl-list__item"> <span class="mdl-list__item-primary-content"> <i class="material-icons mdl-list__item-avatar">person</i> <span>Bob Odenkirk</span> </span> <span class="mdl-list__item-secondary-content"> <a class="mdl-list__item-secondary-action" href="#"><i class="material-icons">star</i></a> </span> </div> </div>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
- person Bryan Cranston
- person Aaron Paul
- person Bob Odenkirk
<!-- List with avatar and controls --> <style> .demo-list-control { width: 300px; } .demo-list-radio { display: inline; } </style> <ul class="demo-list-control mdl-list"> <li class="mdl-list__item"> <span class="mdl-list__item-primary-content"> <i class="material-icons mdl-list__item-avatar">person</i> Bryan Cranston </span> <span class="mdl-list__item-secondary-action"> <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="list-checkbox-1"> <input type="checkbox" id="list-checkbox-1" class="mdl-checkbox__input" checked /> </label> </span> </li> <li class="mdl-list__item"> <span class="mdl-list__item-primary-content"> <i class="material-icons mdl-list__item-avatar">person</i> Aaron Paul </span> <span class="mdl-list__item-secondary-action"> <label class="demo-list-radio mdl-radio mdl-js-radio mdl-js-ripple-effect" for="list-option-1"> <input type="radio" id="list-option-1" class="mdl-radio__button" name="options" value="1" checked /> </label> </span> </li> <li class="mdl-list__item"> <span class="mdl-list__item-primary-content"> <i class="material-icons mdl-list__item-avatar">person</i> Bob Odenkirk </span> <span class="mdl-list__item-secondary-action"> <label class="mdl-switch mdl-js-switch mdl-js-ripple-effect" for="list-switch-1"> <input type="checkbox" id="list-switch-1" class="mdl-switch__input" checked /> </label> </span> </li> </ul>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
<!-- Two Line List with secondary info and action --> <style> .demo-list-two { width: 300px; } </style> <ul class="demo-list-two mdl-list"> <li class="mdl-list__item mdl-list__item--two-line"> <span class="mdl-list__item-primary-content"> <i class="material-icons mdl-list__item-avatar">person</i> <span>Bryan Cranston</span> <span class="mdl-list__item-sub-title">62 Episodes</span> </span> <span class="mdl-list__item-secondary-content"> <span class="mdl-list__item-secondary-info">Actor</span> <a class="mdl-list__item-secondary-action" href="#"><i class="material-icons">star</i></a> </span> </li> <li class="mdl-list__item mdl-list__item--two-line"> <span class="mdl-list__item-primary-content"> <i class="material-icons mdl-list__item-avatar">person</i> <span>Aaron Paul</span> <span class="mdl-list__item-sub-title">62 Episodes</span> </span> <span class="mdl-list__item-secondary-content"> <a class="mdl-list__item-secondary-action" href="#"><i class="material-icons">star</i></a> </span> </li> <li class="mdl-list__item mdl-list__item--two-line"> <span class="mdl-list__item-primary-content"> <i class="material-icons mdl-list__item-avatar">person</i> <span>Bob Odenkirk</span> <span class="mdl-list__item-sub-title">62 Episodes</span> </span> <span class="mdl-list__item-secondary-content"> <a class="mdl-list__item-secondary-action" href="#"><i class="material-icons">star</i></a> </span> </li> </ul>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
- person Bryan Cranston Bryan Cranston played the role of Walter in Breaking Bad. He is also known for playing Hal in Malcom in the Middle. star
- person Aaron Paul Aaron Paul played the role of Jesse in Breaking Bad. He also featured in the "Need For Speed" Movie. star
- person Bob Odenkirk Bob Odinkrik played the role of Saul in Breaking Bad. Due to public fondness for the character, Bob stars in his own show now, called "Better Call Saul". star
<!-- Three Line List with secondary info and action --> <style> .demo-list-three { width: 650px; } </style> <ul class="demo-list-three mdl-list"> <li class="mdl-list__item mdl-list__item--three-line"> <span class="mdl-list__item-primary-content"> <i class="material-icons mdl-list__item-avatar">person</i> <span>Bryan Cranston</span> <span class="mdl-list__item-text-body"> Bryan Cranston played the role of Walter in Breaking Bad. He is also known for playing Hal in Malcom in the Middle. </span> </span> <span class="mdl-list__item-secondary-content"> <a class="mdl-list__item-secondary-action" href="#"><i class="material-icons">star</i></a> </span> </li> <li class="mdl-list__item mdl-list__item--three-line"> <span class="mdl-list__item-primary-content"> <i class="material-icons mdl-list__item-avatar">person</i> <span>Aaron Paul</span> <span class="mdl-list__item-text-body"> Aaron Paul played the role of Jesse in Breaking Bad. He also featured in the "Need For Speed" Movie. </span> </span> <span class="mdl-list__item-secondary-content"> <a class="mdl-list__item-secondary-action" href="#"><i class="material-icons">star</i></a> </span> </li> <li class="mdl-list__item mdl-list__item--three-line"> <span class="mdl-list__item-primary-content"> <i class="material-icons mdl-list__item-avatar">person</i> <span>Bob Odenkirk</span> <span class="mdl-list__item-text-body"> Bob Odinkrik played the role of Saul in Breaking Bad. Due to public fondness for the character, Bob stars in his own show now, called "Better Call Saul". </span> </span> <span class="mdl-list__item-secondary-content"> <a class="mdl-list__item-secondary-action" href="#"><i class="material-icons">star</i></a> </span> </li> </ul>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
Introduction
Lists present multiple line items vertically as a single continuous element. Refer the Material Design Spec to know more about the content options.
To include the MDL list component:
Create a List with basic items.
1. Code a <ul>
element with the class mdl-list
; this is the "outer" container, intended to hold all of the list's content.
<ul class='mdl-list'>
</ul>
2. Code as many <li>
elements as required with the class mdl-list__item
; this is intended to hold all of the item's content.
<ul class='mdl-list'>
<li class="mdl-list__item"></li>
<li class="mdl-list__item"></li>
<li class="mdl-list__item"></li>
</ul>
3. Add your content as the children of the <li>
, with the appropriate content type modification class for example .
<ul class='mdl-list'>
<li class="mdl-list__item">
<span class="mdl-list__item-primary-content"></span>
</li>
<li class="mdl-list__item">
<span class="mdl-list__item-primary-content"></span>
</li>
<li class="mdl-list__item">
<span class="mdl-list__item-primary-content"></span>
</li>
</ul>
Configuration options
The MDL CSS classes apply various predefined visual enhancements to the list. The table below lists the available classes and their effects.
MDL Class | Effect | Remark |
---|---|---|
.mdl-list | Defines list as an MDL component | - |
.mdl-list__item | Defines the List's Items | required |
.mdl-list__item--two-line | Defines the List's Items as Two Line | Optional Two Line List Variant |
.mdl-list__item--three-line | Defines the List's Items as a Three Line | Optional Three Line List Variant |
.mdl-list__item-primary-content | Defines the primary content sub-division | - |
.mdl-list__item-avatar | Defines the avatar sub-division | - |
.mdl-list__item-icon | Defines the icon sub-division | - |
.mdl-list__item-secondary-content | Defines the secondary content sub-division | requires .mdl-list__item--two-line or .mdl-list__item--three-line |
.mdl-list__item-secondary-info | Defines the information sub-division | requires .mdl-list__item--two-line or .mdl-list__item--three-line |
.mdl-list__item-secondary-action | Defines the Action sub-division | requires .mdl-list__item--two-line or .mdl-list__item--three-line |
.mdl-list__item-text-body | Defines the Text Body sub-division | requires .mdl-list__item--three-line |
Loading
Indicate loading and progress states.
Progress bar
<!-- Simple MDL Progress Bar --> <div id="p1" class="mdl-progress mdl-js-progress"></div> <script> document.querySelector('#p1').addEventListener('mdl-componentupgraded', function() { this.MaterialProgress.setProgress(44); }); </script>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
<!-- MDL Progress Bar with Indeterminate Progress --> <div id="p2" class="mdl-progress mdl-js-progress mdl-progress__indeterminate"></div>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
<!-- MDL Progress Bar with Buffering --> <div id="p3" class="mdl-progress mdl-js-progress"></div> <script> document.querySelector('#p3').addEventListener('mdl-componentupgraded', function() { this.MaterialProgress.setProgress(33); this.MaterialProgress.setBuffer(87); }); </script>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
Introduction
The Material Design Lite (MDL) progress component is a visual indicator of background activity in a web page or application. A progress indicator consists of a (typically) horizontal bar containing some animation that conveys a sense of motion. While some progress devices indicate an approximate or specific percentage of completion, the MDL progress component simply communicates the fact that an activity is ongoing and is not yet complete.
Progress indicators are an established but non-standardized feature in user interfaces, and provide users with a visual clue to an application's status. Their design and use is therefore an important factor in the overall user experience. See the progress component's Material Design specifications page for details.
To include an MDL progress component:
1. Code a <div>
element. Include any desired attributes and values, such as an id or width — typically done using external CSS rather than the inline style
attribute as shown here.
<div id="prog1" style="width:250px"></div>
2. Add one or more MDL classes, separated by spaces, to the div using the class
attribute.
<div id="prog1" style="width:250px" class="mdl-js-progress"></div>
The progress component is ready for use.
Examples
A static (non-animated) progress indicator.
<div id="progstatic" style="width:250px" class="mdl-js-progress"></div>
An active (animated) progress indicator.
<div id="progactive" style="width:200px" class="mdl-js-progress
mdl-progress--indeterminate"></div>
Configuration options
The MDL CSS classes apply various predefined visual and behavioral enhancements to the progress indicator. The table below lists the available classes and their effects.
MDL class | Effect | Remarks |
---|---|---|
mdl-js-progress |
Assigns basic MDL behavior to progress indicator | Required |
mdl-progress--indeterminate |
Applies animation effect | Optional |
Note:
mdl-progress__intermediate
does exist within the codebase. It is deprecated since the name is not in BEM alignment. It will be removed in 2.0.
Spinner
<!-- MDL Spinner Component --> <div class="mdl-spinner mdl-js-spinner is-active"></div>
<style></style><!-- MDL Spinner Component with Single Color --> <div class="mdl-spinner mdl-spinner--single-color mdl-js-spinner is-active"></div>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
Introduction
The Material Design Lite (MDL) spinner component is an enhanced replacement for the classic "wait cursor" (which varies significantly among hardware and software versions) and indicates that there is an ongoing process, the results of which are not yet available. A spinner consists of an open circle that changes colors as it animates in a clockwise direction, and clearly communicates that a process has been started but not completed.
A spinner performs no action itself, either by its display nor when the user clicks or touches it, and does not indicate a process's specific progress or degree of completion. The MDL spinner component provides various types of spinners, and allows you to add display effects.
Spinners are a fairly new feature of most user interfaces, and provide users with a consistent visual cue about ongoing activity, regardless of hardware device, operating system, or browser environment. Their design and use is an important factor in the overall user experience.
To include an MDL spinner component:
1. Code an element, such as a <div>
, <p>
, or <span>
, to contain the spinner; the element should have no content of its own.
<div></div>
2. Add one or more MDL classes, separated by spaces, to the container using the class
attribute.
<div class="mdl-spinner mdl-js-spinner is-active"></div>
The spinner component is ready for use.
Examples
A default spinner in a div.
<div class="mdl-spinner mdl-js-spinner is-active"></div>
A single-color spinner in a paragraph.
<p class="mdl-spinner mdl-js-spinner mdl-spinner--single-color is-active"></p>
Configuration options
The MDL CSS classes apply various predefined visual enhancements to the spinner. The table below lists the available classes and their effects.
MDL class | Effect | Remarks |
---|---|---|
mdl-spinner |
Defines the container as an MDL spinner component | Required |
mdl-js-spinner |
Assigns basic MDL behavior to spinner | Required |
is-active |
Makes the spinner visible and animated | Optional |
mdl-spinner--single-color |
Uses a single (primary palette) color instead of changing colors | Optional |
Note: There is no specific disabled version of a spinner; the presence or absence of the
is-active
class determines whether the spinner is visible. For example, this spinner is inactive and invisible:<div class="mdl-spinner mdl-js-spinner"></div>
This attribute may be added or removed programmatically via scripting.
Sliders
Selecting a value out of a range.
<!-- Default Slider --> <input class="mdl-slider mdl-js-slider" type="range" min="0" max="100" value="0" tabindex="0">
<style></style><!-- Slider with Starting Value --> <input class="mdl-slider mdl-js-slider" type="range" min="0" max="100" value="25" tabindex="0">
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
Introduction
The Material Design Lite (MDL) slider component is an enhanced version of the new HTML5 <input type="range">
element. A slider consists of a horizontal line upon which sits a small, movable disc (the thumb) and, typically, text that clearly communicates a value that will be set when the user moves it.
Sliders are a fairly new feature in user interfaces, and allow users to choose a value from a predetermined range by moving the thumb through the range (lower values to the left, higher values to the right). Their design and use is an important factor in the overall user experience. See the slider component's Material Design specifications page for details.
The enhanced slider component may be initially or programmatically disabled.
To include an MDL slider component:
1. Code a <p>
paragraph element and style it as desired. Include a CSS width
property (directly or via a CSS class), which determines the slider's size.
<p style="width:300px">
...
</p>
2. Inside the paragraph container, code an <input>
element and give it a type
attribute whose value is "range"
. Also give it an id
attribute to make it available for scripting, and min
and max
attributes whose values specify the slider's range. Give it a value
attribute whose value sets the initial thumb position (optional; if omitted, defaults to 50% of the maximum), and a step
attribute whose value specifies the increment by which the thumb moves (also optional; if omitted, defaults to 1). Finally, give it an event handler to be executed when the user changes the slider's value.
<p style="width:300px">
<input type="range" id="s1" min="0" max="10" value="4" step="2">
</p>
3. Add one or more MDL classes, separated by spaces, to the slider using the class
attribute.
<p style="width:300px">
<input class="mdl-slider mdl-js-slider" type="range" id="s1" min="0" max="10" value="4" step="2">
</p>
The slider component is ready for use.
Example
A slider that controls volume.
<p style="width:300px">
<input class="mdl-slider mdl-js-slider" type="range" id="s1" min="0" max="10" value="4" step="2">
</p>
Configuration options
The MDL CSS classes apply various predefined visual and behavioral enhancements to the slider. The table below lists the available classes and their effects.
MDL class | Effect | Remarks |
---|---|---|
mdl-slider |
Defines input element as an MDL component | Required |
mdl-js-slider |
Assigns basic MDL behavior to input element | Required |
Note: A disabled version of the slider is provided, and is invoked with the standard HTML boolean attribute
disabled
.<input class="mdl-slider mdl-js-slider" type="range" id="s1" min="0" max="10" value="4" step="2" disabled>
This attribute may be added or removed programmatically via scripting.Note: Although the value attribute is used to set a slider's initial value, it should not be used to modify the value programmatically; instead, use the MDL
change()
method. For example, assuming that slider1 is a slider object and newvalue is a variable containing the desired value, do not useslider1.value = newvalue
; instead, useslider1.MaterialSlider.change(newvalue)
.
License
Copyright Google, 2015. Licensed under an Apache-2 license.
Snackbar
Transient popup notifications.
<button id="demo-show-snackbar" class="mdl-button mdl-js-button mdl-button--raised" type="button">Show Snackbar</button> <div id="demo-snackbar-example" class="mdl-js-snackbar mdl-snackbar"> <div class="mdl-snackbar__text"></div> <button class="mdl-snackbar__action" type="button"></button> </div> <script> (function() { 'use strict'; var snackbarContainer = document.querySelector('#demo-snackbar-example'); var showSnackbarButton = document.querySelector('#demo-show-snackbar'); var handler = function(event) { showSnackbarButton.style.backgroundColor = ''; }; showSnackbarButton.addEventListener('click', function() { 'use strict'; showSnackbarButton.style.backgroundColor = '#' + Math.floor(Math.random() * 0xFFFFFF).toString(16); var data = { message: 'Button color changed.', timeout: 2000, actionHandler: handler, actionText: 'Undo' }; snackbarContainer.MaterialSnackbar.showSnackbar(data); }); }()); </script>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
<button id="demo-show-toast" class="mdl-button mdl-js-button mdl-button--raised" type="button">Show Toast</button> <div id="demo-toast-example" class="mdl-js-snackbar mdl-snackbar"> <div class="mdl-snackbar__text"></div> <button class="mdl-snackbar__action" type="button"></button> </div> <script> (function() { 'use strict'; window['counter'] = 0; var snackbarContainer = document.querySelector('#demo-toast-example'); var showToastButton = document.querySelector('#demo-show-toast'); showToastButton.addEventListener('click', function() { 'use strict'; var data = {message: 'Example Message # ' + ++counter}; snackbarContainer.MaterialSnackbar.showSnackbar(data); }); }()); </script>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
Introduction
The Material Design Lite (MDL) snackbar component is a container used to notify a user of an operation's status. It displays at the bottom of the screen. A snackbar may contain an action button to execute a command for the user. Actions should undo the committed action or retry it if it failed for example. Actions should not be to close the snackbar. By not providing an action, the snackbar becomes a toast component.
Basic Usage:
Start a snackbar with a container div element.
On that container define the mdl-js-snackbar
and mdl-snackbar
classes.
It is also beneficial to add the aria live and atomic values to this container.
Within the container create a container element for the message.
This element should have the class mdl-snackbar__text
.
Leave this element empty!
Text is added when the snackbar is called to be shown.
Second in the container, add a button element.
This element should have the class mdl-snackbar__action
.
It is recommended to set the type to button to make sure no forms get submitted by accident.
Leave the text content empty here as well!
Do not directly apply any event handlers.
You now have complete markup for the snackbar to function.
All that is left is within your JavaScript to call the showSnackbar
method on the snackbar container.
This takes a plain object to configure the snackbar content appropriately.
You may call it multiple consecutive times and messages will stack.
Examples
All snackbars should be shown through the same element.
Markup:
<div aria-live="assertive" aria-atomic="true" aria-relevant="text" class="mdl-snackbar mdl-js-snackbar">
<div class="mdl-snackbar__text"></div>
<button type="button" class="mdl-snackbar__action"></button>
</div>
Note: In this example there are a few aria attributes for accessibility. Please modify these as-needed for your site.
Snackbar
var notification = document.querySelector('.mdl-js-snackbar');
var data = {
message: 'Message Sent',
actionHandler: function(event) {},
actionText: 'Undo',
timeout: 10000
};
notification.MaterialSnackbar.showSnackbar(data);
Toast
var notification = document.querySelector('.mdl-js-snackbar');
notification.MaterialSnackbar.showSnackbar(
{
message: 'Image Uploaded'
}
);
CSS Classes
Blocks
MDL Class | Effect | Remarks |
---|---|---|
mdl-snackbar |
Defines the container of the snackbar component. | Required on snackbar container |
Elements
MDL Class | Effect | Remarks |
---|---|---|
mdl-snackbar__text |
Defines the element containing the text of the snackbar. | Required |
mdl-snackbar__action |
Defines the element that triggers the action of a snackbar. | Required |
Modifiers
MDL Class | Effect | Remarks |
---|---|---|
mdl-snackbar--active |
Marks the snackbar as active which causes it to display. | Required when active. Controlled in JavaScript |
Data Object
The Snackbar components showSnackbar
method takes an object for snackbar data.
The table below shows the properties and their usage.
Property | Effect | Remarks | Type |
---|---|---|---|
message | The text message to display. | Required | String |
timeout | The amount of time in milliseconds to show the snackbar. | Optional (default 2750) | Integer |
actionHandler | The function to execute when the action is clicked. | Optional | Function |
actionText | The text to display for the action button. | Required if actionHandler is set | String. |
Toggles
Choose between states.
Checkbox
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="checkbox-1"> <input type="checkbox" id="checkbox-1" class="mdl-checkbox__input" checked> <span class="mdl-checkbox__label">Checkbox</span> </label>
<style></style><label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="checkbox-2"> <input type="checkbox" id="checkbox-2" class="mdl-checkbox__input"> <span class="mdl-checkbox__label">Checkbox</span> </label>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
Introduction
The Material Design Lite (MDL) checkbox component is an enhanced version of the standard HTML <input type="checkbox">
element. A checkbox consists of a small square and, typically, text that clearly communicates a binary condition that will be set or unset when the user clicks or touches it. Checkboxes typically, but not necessarily, appear in groups, and can be selected and deselected individually. The MDL checkbox component allows you to add display and click effects.
Checkboxes are a common feature of most user interfaces, regardless of a site's content or function. Their design and use is therefore an important factor in the overall user experience. See the checkbox component's Material Design specifications page for details.
The enhanced checkbox component has a more vivid visual look than a standard checkbox, and may be initially or programmatically disabled.
To include an MDL checkbox component:
1. Code a <label>
element and give it a for
attribute whose value is the unique id of the checkbox it will contain. The for
attribute is optional when the <input>
element is contained inside the <label>
element, but is recommended for clarity.
<label for="chkbox1">
...
</label>
2. Inside the label, code an <input>
element and give it a type
attribute whose value is "checkbox"
. Also give it an id
attribute whose value matches the label's for
attribute value.
<label for="chkbox1">
<input type="checkbox" id="chkbox1">
</label>
3. Also inside the label, after the checkbox, code a <span>
element containing the checkbox's text caption.
<label for="chkbox1">
<input type="checkbox" id="chkbox1">
<span>Enable AutoSave</span>
</label>
4. Add one or more MDL classes, separated by spaces, to the label, checkbox, and caption using the class
attribute.
<label for="chkbox1" class="mdl-checkbox mdl-js-checkbox">
<input type="checkbox" id="chkbox1" class="mdl-checkbox__input">
<span class="mdl-checkbox__label">Enable AutoSave</span>
</label>
The checkbox component is ready for use.
Example
A checkbox with a ripple click effect.
<label for="chkbox1" class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect">
<input type="checkbox" id="chkbox1" class="mdl-checkbox__input">
<span class="mdl-checkbox__label">Enable AutoSave</span>
</label>
Configuration options
The MDL CSS classes apply various predefined visual and behavioral enhancements to the checkbox. The table below lists the available classes and their effects.
MDL class | Effect | Remarks |
---|---|---|
mdl-checkbox |
Defines label as an MDL component | Required on label element |
mdl-js-checkbox |
Assigns basic MDL behavior to label | Required on label element |
mdl-checkbox__input |
Applies basic MDL behavior to checkbox | Required on input element (checkbox) |
mdl-checkbox__label |
Applies basic MDL behavior to caption | Required on span element (caption) |
mdl-js-ripple-effect |
Applies ripple click effect | Optional; goes on label element, not input element (checkbox) |
Note: Disabled versions of all the available checkbox types are provided, and are invoked with the standard HTML boolean attribute
disabled
.<input type="checkbox" id="checkbox-5" class="mdl-checkbox__input" disabled>
This attribute may be added or removed programmatically via scripting.
Radio button
<label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-1"> <input type="radio" id="option-1" class="mdl-radio__button" name="options" value="1" checked> <span class="mdl-radio__label">First</span> </label>
<style></style><label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-2"> <input type="radio" id="option-2" class="mdl-radio__button" name="options" value="2"> <span class="mdl-radio__label">Second</span> </label>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
Introduction
The Material Design Lite (MDL) radio component is an enhanced version of the standard HTML <input type="radio">
, or "radio button" element. A radio button consists of a small circle and, typically, text that clearly communicates a condition that will be set when the user clicks or touches it. Radio buttons always appear in groups of two or more and, while they can be individually selected, can only be deselected by selecting a different radio button in the same group (which deselects all other radio buttons in the group). The MDL radio component allows you to add display and click effects.
Radio buttons are a common feature of most user interfaces, regardless of a site's content or function. Their design and use is therefore an important factor in the overall user experience. See the radio component's Material Design specifications page for details.
The enhanced radio component has a more vivid visual look than a standard radio button, and may be initially or programmatically disabled.
To include an MDL radio component:
1. Code a <label>
element and give it a for
attribute whose value is the unique id of the radio button it will contain. The for
attribute is optional when the <input>
element is contained inside the <label>
element, but is recommended for clarity.
<label for="radio1">
...
</label>
2. Inside the label, code an <input>
element and give it a type
attribute whose value is "radio"
. Also give it an id
attribute whose value matches the label's for
attribute value, and a name
attribute whose value identifies the radio button group. Optionally, give it a value
attribute whose value provides some information about the radio button for scripting purposes.
<label for="radio1">
<input type="radio" id="radio1" name="flash" value="on">
</label>
3. Also inside the label, after the radio button, code a <span>
element containing the radio button's text caption.
<label for="radio1">
<input type="radio" id="radio1" name="flash" value="on">
<span>Always on</span>
</label>
4. Add one or more MDL classes, separated by spaces, to the label, checkbox, and caption using the class
attribute.
<label for="radio1" class="mdl-radio mdl-js-radio">
<input type="radio" id="radio1" name="flash" value="on" class="mdl-radio__button">
<span class="mdl-radio__label">Always on</span>
</label>
5. Repeat steps 1 through 4 for the other radio components in the group. For each one:
- on the
label
element, specify a uniquefor
attribute value - on the
input
element, specify anid
attribute value that matches itslabel
element'sfor
attribute value - on the
input
element, specify the samename
attribute value for all radio components in the group - optionally, on the
input
element, specify a uniquevalue
attribute value
The radio components are ready for use.
Example
A group of radio buttons to control a camera's flash setting.
<label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="flash1">
<input checked class="mdl-radio__button" id="flash1" name="flash" type="radio"
value="on">
<span class="mdl-radio__label">Always on</span>
</label>
<label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="flash2">
<input class="mdl-radio__button" id="flash2" name="flash" type="radio" value="off">
<span class="mdl-radio__label">Always off</span>
</label>
<label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="flash3">
<input class="mdl-radio__button" id="flash3" name="flash" type="radio" value="auto">
<span class="mdl-radio__label">Automatic</span>
</label>
Configuration options
The MDL CSS classes apply various predefined visual and behavioral enhancements to the radio button. The table below lists the available classes and their effects.
MDL class | Effect | Remarks |
---|---|---|
mdl-radio |
Defines label as an MDL component | Required on label element |
mdl-js-radio |
Assigns basic MDL behavior to label | Required on label element |
mdl-radio__button |
Applies basic MDL behavior to radio | Required on input element (radio button) |
mdl-radio__label |
Applies basic MDL behavior to caption | Required on span element (caption) |
mdl-js-ripple-effect |
Applies ripple click effect | Optional; goes on label element, not input element (radio button) |
Note: Disabled versions of all the available radio button types are provided, and are invoked with the standard HTML boolean attribute
disabled
.<input type="radio" id="radio5" name="flash" class="mdl-radio__button" disabled>
This attribute may be added or removed programmatically via scripting.
Icon toggle
<label class="mdl-icon-toggle mdl-js-icon-toggle mdl-js-ripple-effect" for="icon-toggle-1"> <input type="checkbox" id="icon-toggle-1" class="mdl-icon-toggle__input" checked> <i class="mdl-icon-toggle__label material-icons">format_bold</i> </label>
<style></style><label class="mdl-icon-toggle mdl-js-icon-toggle mdl-js-ripple-effect" for="icon-toggle-2"> <input type="checkbox" id="icon-toggle-2" class="mdl-icon-toggle__input"> <i class="mdl-icon-toggle__label material-icons">format_italic</i> </label>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
Introduction
The Material Design Lite (MDL) icon-toggle component is an enhanced version of the standard HTML <input type="checkbox">
element. An icon-toggle consists of a user defined icon that indicates, by visual highlighting, a binary condition that will be set or unset when the user clicks or touches it. Like checkboxes, icon-toggles may appear individually or in groups, and can be selected and deselected individually.
Icon toggles, particularly as a replacement for certain checkboxes, can be a valuable feature in user interfaces, regardless of a site's content or function. Their design and use is therefore an important factor in the overall user experience. See the icon-toggle component's Material Design specifications page for details.
The icon-toggle component can have a more customized visual look than a standard checkbox, and may be initially or programmatically disabled.
To include an MDL icon-toggle component:
1. Code a <label>
element and give it a for
attribute whose value is the unique id of the icon-toggle it will contain.
<label for="icon-toggle-1">
...
</label>
2. Inside the label, code an <input>
element and give it a type
attribute whose value is "checkbox"
. Also give it an id
attribute whose value matches the label's for
attribute value.
<label for="icon-toggle-1">
<input type="checkbox" id="icon-toggle-1">
</label>
3. Also inside the label, after the input element, code an <i>
element containing the icon-toggle's desired icon.
<label for="icon-toggle-1">
<input type="checkbox" id="icon-toggle-1">
<i class="mdl-icon-toggle__label material-icons">format_bold</i>
</label>
4. Add one or more MDL classes, separated by spaces, to the label and input elements, using the class
attribute.
<label class="mdl-icon-toggle mdl-js-icon-toggle mdl-js-ripple-effect" for="icon-toggle-1">
<input type="checkbox" id="icon-toggle-1" class="mdl-icon-toggle__input">
<i class="mdl-icon-toggle__label material-icons">format_bold</i>
</label>
The icon-toggle component is ready for use.
Example
An icon-toggle with a ripple click effect.
<label class="mdl-icon-toggle mdl-js-icon-toggle mdl-js-ripple-effect" for="icon-toggle-1">
<input type="checkbox" id="icon-toggle-1" class="mdl-icon-toggle__input">
<i class="mdl-icon-toggle__label material-icons">format_bold</i>
</label>
Configuration options
The MDL CSS classes apply various predefined visual and behavioral enhancements to the icon-toggle. The table below lists the available classes and their effects.
MDL class | Effect | Remarks |
---|---|---|
mdl-icon-toggle |
Defines label as an MDL component | Required on label element |
mdl-js-icon-toggle |
Assigns basic MDL behavior to label | Required on label element |
mdl-icon-toggle__input |
Applies basic MDL behavior to icon-toggle | Required on input element (icon-toggle) |
mdl-icon-toggle__label |
Applies basic MDL behavior to caption | Required on i element (icon) |
mdl-js-ripple-effect |
Applies ripple click effect | Optional; goes on label element, not input element (icon-toggle) |
Note: Disabled versions of all available input types are provided, and are invoked with the standard HTML boolean attribute
disabled
.<input type="checkbox" id="icon-toggle-5" class="mdl-icon-toggle__input" disabled>
This attribute may be added or removed programmatically via scripting.
Switch
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect" for="switch-1"> <input type="checkbox" id="switch-1" class="mdl-switch__input" checked> <span class="mdl-switch__label"></span> </label>
<style></style><label class="mdl-switch mdl-js-switch mdl-js-ripple-effect" for="switch-2"> <input type="checkbox" id="switch-2" class="mdl-switch__input"> <span class="mdl-switch__label"></span> </label>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
Introduction
The Material Design Lite (MDL) switch component is an enhanced version of the standard HTML <input type="checkbox">
element. A switch consists of a short horizontal "track" with a prominent circular state indicator and, typically, text that clearly communicates a binary condition that will be set or unset when the user clicks or touches it. Like checkboxes, switches may appear individually or in groups, and can be selected and deselected individually. However, switches provide a more intuitive visual representation of their state: left/gray for off, right/colored for on. The MDL switch component allows you to add both display and click effects.
Switches, particularly as a replacement for certain checkboxes, can be a valuable feature in user interfaces, regardless of a site's content or function. Their design and use is therefore an important factor in the overall user experience. See the switch component's Material Design specifications page for details.
The enhanced switch component has a more vivid visual look than a standard checkbox, and may be initially or programmatically disabled.
To include an MDL switch component:
1. Code a <label>
element and give it a for
attribute whose value is the unique id of the switch it will contain.
<label for="switch1">
...
</label>
2. Inside the label, code an <input>
element and give it a type
attribute whose value is "checkbox"
. Also give it an id
attribute whose value matches the label's for
attribute value.
<label for="switch1">
<input type="checkbox" id="switch1">
</label>
3. Also inside the label, after the checkbox, code a <span>
element containing the switch's text caption.
<label for="switch1">
<input type="checkbox" id="switch1">
<span>Sound off/on</span>
</label>
4. Add one or more MDL classes, separated by spaces, to the label, switch, and caption using the class
attribute.
<label for="switch1" class="mdl-switch mdl-js-switch">
<input type="checkbox" id="switch1" class="mdl-switch__input">
<span class="mdl-switch__label">Sound off/on</span>
</label>
The switch component is ready for use.
Example
A switch with a ripple click effect.
<label for="switch1" class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
<input type="checkbox" id="switch1" class="mdl-switch__input">
<span class="mdl-switch__label">Sound off/on</span>
</label>
Configuration options
The MDL CSS classes apply various predefined visual and behavioral enhancements to the switch. The table below lists the available classes and their effects.
MDL class | Effect | Remarks |
---|---|---|
mdl-switch |
Defines label as an MDL component | Required on label element |
mdl-js-switch |
Assigns basic MDL behavior to label | Required on label element |
mdl-switch__input |
Applies basic MDL behavior to switch | Required on input element (switch) |
mdl-switch__label |
Applies basic MDL behavior to caption | Required on span element (caption) |
mdl-js-ripple-effect |
Applies ripple click effect | Optional; goes on label element, not input element (switch) |
Note: Disabled versions of all available switch types are provided, and are invoked with the standard HTML boolean attribute
disabled
.<input type="checkbox" id="switch5" class="mdl-switch__input" disabled>
This attribute may be added or removed programmatically via scripting.
Tables
Organize data.
Material | Quantity | Unit price |
---|---|---|
Acrylic (Transparent) | 25 | $2.90 |
Plywood (Birch) | 50 | $1.25 |
Laminate (Gold on Blue) | 10 | $2.35 |
<table class="mdl-data-table mdl-js-data-table mdl-data-table--selectable mdl-shadow--2dp"> <thead> <tr> <th class="mdl-data-table__cell--non-numeric">Material</th> <th>Quantity</th> <th>Unit price</th> </tr> </thead> <tbody> <tr> <td class="mdl-data-table__cell--non-numeric">Acrylic (Transparent)</td> <td>25</td> <td>$2.90</td> </tr> <tr> <td class="mdl-data-table__cell--non-numeric">Plywood (Birch)</td> <td>50</td> <td>$1.25</td> </tr> <tr> <td class="mdl-data-table__cell--non-numeric">Laminate (Gold on Blue)</td> <td>10</td> <td>$2.35</td> </tr> </tbody> </table>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
Introduction
The Material Design Lite (MDL) data-table component is an enhanced version of the standard HTML <table>
. A data-table consists of rows and columns of well-formatted data, presented with appropriate user interaction capabilities.
Tables are a ubiquitous feature of most user interfaces, regardless of a site's content or function. Their design and use is therefore an important factor in the overall user experience. See the data-table component's Material Design specifications page for details.
The available row/column/cell types in a data-table are mostly self-formatting; that is, once the data-table is defined, the individual cells require very little specific attention. For example, the rows exhibit shading behavior on mouseover and selection, numeric values are automatically formatted by default, and the addition of a single class makes the table rows individually or collectively selectable. This makes the data-table component convenient and easy to code for the developer, as well as attractive and intuitive for the user.
To include an MDL data-table component:
1. Code a <table>
element. Include <thead>
and <tbody>
elements to hold the title and data rows, respectively.
<table>
<thead>
</thead>
<tbody>
</tbody>
</table>
2. Add one or more MDL classes, separated by spaces, to the table using the class
attribute.
<table class="mdl-data-table mdl-js-data-table">
<thead>
</thead>
<tbody>
</tbody>
</table>
2. Inside the <thead>
, code exactly one table row <tr>
containing one table header cell <th>
for each column, and include the desired text in the header cells. To ensure proper header alignment, add the "non-numeric" MDL class to the header cell of text-only columns. (Data cells are formatted as numeric by default.)
<table class="mdl-data-table mdl-js-data-table">
<thead>
<tr>
<th class="mdl-data-table__cell--non-numeric">Name</th>
<th>Age</th>
<th>ID Number</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
3. Inside the <tbody>
, code one table row <tr>
for each data row and one table data cell <td>
for each column in the row. As with the header cells, add the "non-numeric" MDL class to text-only data cells to ensure proper alignment.
<table class="mdl-data-table mdl-js-data-table">
<thead>
<tr>
<th class="mdl-data-table__cell--non-numeric">Name</th>
<th>Age</th>
<th>ID Number</th>
</tr>
</thead>
<tbody>
<tr>
<td class="mdl-data-table__cell--non-numeric">Don Aubrey</td>
<td>25</td>
<td>49021</td>
</tr>
<tr>
<td class="mdl-data-table__cell--non-numeric">Sophia Carson</td>
<td>32</td>
<td>10258</td>
</tr>
<tr>
<td class="mdl-data-table__cell--non-numeric">Steve Moreno</td>
<td>29</td>
<td>12359</td>
</tr>
</tbody>
</table>
The data-table component is ready for use.
Examples
A data-table with a "master" select checkbox and individual row select checkboxes.
<table class="mdl-data-table mdl-js-data-table mdl-data-table--selectable">
<thead>
<tr>
<th class="mdl-data-table__cell--non-numeric">Material</th>
<th>Quantity</th>
<th>Unit price</th>
</tr>
</thead>
<tbody>
<tr>
<td class="mdl-data-table__cell--non-numeric">Acrylic (Transparent)</td>
<td>250</td>
<td>$2.90</td>
</tr>
<tr>
<td class="mdl-data-table__cell--non-numeric">Plywood (Birch)</td>
<td>50</td>
<td>$1.25</td>
</tr>
<tr>
<td class="mdl-data-table__cell--non-numeric">Laminate (Gold on Blue)</td>
<td>10</td>
<td>$12.35</td>
</tr>
</tbody>
</table>
A data-table without select checkboxes containing mostly text data.
<table class="mdl-data-table mdl-js-data-table">
<thead>
<tr>
<th class="mdl-data-table__cell--non-numeric">Name</th>
<th class="mdl-data-table__cell--non-numeric">Nickname</th>
<th>Age</th>
<th class="mdl-data-table__cell--non-numeric">Living?</th>
</tr>
</thead>
<tbody>
<tr>
<td class="mdl-data-table__cell--non-numeric">John Lennon</td>
<td class="mdl-data-table__cell--non-numeric">The smart one</td>
<td>40</td>
<td class="mdl-data-table__cell--non-numeric">No</td>
</tr>
<tr>
<td class="mdl-data-table__cell--non-numeric">Paul McCartney</td>
<td class="mdl-data-table__cell--non-numeric">The cute one</td>
<td>73</td>
<td class="mdl-data-table__cell--non-numeric">Yes</td>
</tr>
<tr>
<td class="mdl-data-table__cell--non-numeric">George Harrison</td>
<td class="mdl-data-table__cell--non-numeric">The shy one</td>
<td>58</td>
<td class="mdl-data-table__cell--non-numeric">No</td>
</tr>
<tr>
<td class="mdl-data-table__cell--non-numeric">Ringo Starr</td>
<td class="mdl-data-table__cell--non-numeric">The funny one</td>
<td>74</td>
<td class="mdl-data-table__cell--non-numeric">Yes</td>
</tr>
</tbody>
</table>
Configuration options
The MDL CSS classes apply various predefined visual and behavioral enhancements to the data-table. The table below lists the available classes and their effects.
MDL class | Effect | Remarks |
---|---|---|
mdl-data-table |
Defines table as an MDL component | Required on table element |
mdl-js-data-table |
Assigns basic MDL behavior to table | Required on table element |
mdl-data-table--selectable |
Applies all/individual selectable behavior (checkboxes) | Optional; goes on table element |
mdl-data-table__header--sorted-ascending |
Applies visual styling to indicate the column is sorted in ascending order | Optional; goes on table header (th ) |
mdl-data-table__header--sorted-descending |
Applies visual styling to indicate the column is sorted in descending order | Optional; goes on table header (th ) |
mdl-data-table__cell--non-numeric |
Applies text formatting to data cell | Optional; goes on both table header and table data cells |
(none) | Applies numeric formatting to header or data cell (default) |
Text Fields
Textual input components.
<!-- Simple Textfield --> <form action="#"> <div class="mdl-textfield mdl-js-textfield"> <input class="mdl-textfield__input" type="text" id="sample1"> <label class="mdl-textfield__label" for="sample1">Text...</label> </div> </form>
<style></style><!-- Numeric Textfield --> <form action="#"> <div class="mdl-textfield mdl-js-textfield"> <input class="mdl-textfield__input" type="text" pattern="-?[0-9]*(\.[0-9]+)?" id="sample2"> <label class="mdl-textfield__label" for="sample2">Number...</label> <span class="mdl-textfield__error">Input is not a number!</span> </div> </form>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
<!-- Textfield with Floating Label --> <form action="#"> <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> <input class="mdl-textfield__input" type="text" id="sample3"> <label class="mdl-textfield__label" for="sample3">Text...</label> </div> </form>
<style></style><!-- Numeric Textfield with Floating Label --> <form action="#"> <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> <input class="mdl-textfield__input" type="text" pattern="-?[0-9]*(\.[0-9]+)?" id="sample4"> <label class="mdl-textfield__label" for="sample4">Number...</label> <span class="mdl-textfield__error">Input is not a number!</span> </div> </form>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
<!-- Floating Multiline Textfield --> <form action="#"> <div class="mdl-textfield mdl-js-textfield"> <textarea class="mdl-textfield__input" type="text" rows= "3" id="sample5" ></textarea> <label class="mdl-textfield__label" for="sample5">Text lines...</label> </div> </form>
<style></style><!-- Expandable Textfield --> <form action="#"> <div class="mdl-textfield mdl-js-textfield mdl-textfield--expandable"> <label class="mdl-button mdl-js-button mdl-button--icon" for="sample6"> <i class="material-icons">search</i> </label> <div class="mdl-textfield__expandable-holder"> <input class="mdl-textfield__input" type="text" id="sample6"> <label class="mdl-textfield__label" for="sample-expandable">Expandable Input</label> </div> </div> </form>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
Introduction
The Material Design Lite (MDL) text field component is an enhanced version of the standard HTML <input type="text">
and <input type="textarea">
elements. A text field consists of a horizontal line indicating where keyboard input can occur and, typically, text that clearly communicates the intended contents of the text field. The MDL text field component provides various types of text fields, and allows you to add both display and click effects.
Text fields are a common feature of most user interfaces, regardless of a site's content or function. Their design and use is therefore an important factor in the overall user experience. See the text field component's Material Design specifications page for details.
The enhanced text field component has a more vivid visual look than a standard text field, and may be initially or programmatically disabled. There are three main types of text fields in the text field component, each with its own basic coding requirements. The types are single-line, multi-line, and expandable.
To include a single-line MDL text field component:
1. Code a <div>
element to hold the text field.
<div>
...
</div>
2. Inside the div, code an <input>
element with a type
attribute of "text"
(the text field), and an id
attribute of your choice.
<div>
<input type="text" id="user">
</div>
3. Also inside the div, after the text field, code a <label>
element with a for
attribute whose value matches the input
element's id
value, and a short string to be used as the field's placeholder text.
<div>
<input type="text" id="user">
<label for="user">User name</label>
</div>
4. Optionally, add a pattern
attribute and value to the <input>
element (see the W3C HTML5 forms specification for details) and an associated error message in a <span>
element following the <label>
.
<div>
<input type="text" id="user" pattern="[A-Z,a-z, ]*">
<label for="user">User name</label>
<span>Letters and spaces only</span>
</div>
5. Add one or more MDL classes, separated by spaces, to the div container, text field, field label, and error message using the class
attribute.
<div class="mdl-textfield mdl-js-textfield">
<input class="mdl-textfield__input" type="text" id="user" pattern="[A-Z,a-z, ]*">
<label class="mdl-textfield__label" for="user">User name</label>
<span class="mdl-textfield__error">Letters and spaces only</span>
</div>
The single-line text field component is ready for use.
Examples
Single-line text field with a standard label.
<div class="mdl-textfield mdl-js-textfield">
<input class="mdl-textfield__input" type="text" id="fname">
<label class="mdl-textfield__label" for="fname">First name</label>
</div>
Single-line text field with a floating label.
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="addr1">
<label class="mdl-textfield__label" for="addr1">Address line 1</label>
</div>
Single-line text field with a standard label, pattern matching, and error message.
<div class="mdl-textfield mdl-js-textfield">
<input class="mdl-textfield__input" type="text" pattern="[0-9]*" id="phone">
<label class="mdl-textfield__label" for="phone">Phone</label>
<span class="mdl-textfield__error">Digits only</span>
</div>
To include a multi-line MDL text field component:
1. Code a <div>
element to hold the text field.
<div>
...
</div>
2. Inside the div, code a <textarea>
element with a type
attribute of "text"
(the multi-line text field), and an id
attribute of your choice. Include a rows
attribute with a value of "1"
(this attribute sets the number of concurrently visible input rows).
<div>
<textarea type="text" rows="1" id="address"></textarea>
</div>
3. Also inside the div, after the text field, code a <label>
element with a for
attribute whose value matches the <textarea>
element's id
value, and a short string to be used as the field's placeholder text.
<div>
<textarea type="text" rows="1" id="address"></textarea>
<label for="address">Full address</label>
</div>
4. Add one or more MDL classes, separated by spaces, to the div container, text field, and field label using the class
attribute.
<div class="mdl-textfield mdl-js-textfield">
<textarea class="mdl-textfield__input" type="text" rows="1" id="address"></textarea>
<label class="mdl-textfield__label" for="address">Full address</label>
</div>
The multi-line text field component is ready for use.
Examples
Multi-line text field with one visible input line.
<div class="mdl-textfield mdl-js-textfield">
<textarea class="mdl-textfield__input" type="text" rows="1" id="schools"></textarea>
<label class="mdl-textfield__label" for="schools">Schools attended</label>
</div>
Multi-line text field with one visible input line and floating label.
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<textarea class="mdl-textfield__input" type="text" rows= "1" id="schools"></textarea>
<label class="mdl-textfield__label" for="schools">Schools attended</label>
</div>
Multi-line text field with multiple visible input lines and a maximum number of lines.
<div class="mdl-textfield mdl-js-textfield">
<textarea class="mdl-textfield__input" type="text" rows="3" maxrows="6"
id="schools"></textarea>
<label class="mdl-textfield__label" for="schools">Schools attended (max. 6)</label>
</div>
To include an expandable MDL text field component:
1. Code an "outer" <div>
element to hold the expandable text field.
<div>
...
</div>
2. Inside the div, code a <label>
element with a for
attribute whose value will match the <input>
element's id
value (to be coded in step 5).
<div>
<label for="expando1">
...
</label>
</div>
3. Inside the label, code a <span>
element; the span should be empty, and should be the label's only content. This element will contain the expandable text field's icon.
<div>
<label for="expando1">
<span></span>
</label>
</div>
4. Still inside the "outer" div, after the label containing the span, code an "inner" (nested) <div>
element.
<div>
<label for="expando1">
<span></span>
</label>
<div>
...
</div>
</div>
5. Inside the "inner" div, code an <input>
element with a type
attribute of "text"
(the text field), and an id
attribute whose value matches that of the for
attribute in step 2.
<div>
<label for="expando1">
<span></span>
</label>
<div>
<input type="text" id="expando1">
</div>
</div>
6. Still inside the "inner" div, after the text field, code a <label>
element with a for
attribute whose value also matches the <input>
element's id
value (coded in step 5), and a short string to be used as the field's placeholder text.
<div>
<label for="expando1">
<span></span>
</label>
<div>
<input type="text" id="expando1">
<label for="expando1">Expandable text field</label>
</div>
</div>
7. Add one or more MDL classes, separated by spaces, to the "outer" div container, label, and span, and to the "inner" div container, text field, and field label using the class
attribute.
<div class="mdl-textfield mdl-js-textfield mdl-textfield--expandable">
<label class="mdl-button mdl-js-button mdl-button--icon" for="expando1">
<i class="material-icons">search</i>
</label>
<div class="mdl-textfield__expandable-holder">
<input class="mdl-textfield__input" type="text" id="expando1">
<label class="mdl-textfield__label" for="expando1">Expandable text field</label>
</div>
</div>
The expandable text field component is ready for use. It will expand when the icon (the empty <span>
) is clicked or gains focus.
Examples
Expandable text field with a standard label.
<div class="mdl-textfield mdl-js-textfield mdl-textfield--expandable">
<label class="mdl-button mdl-js-button mdl-button--icon" for="search-expandable">
<i class="material-icons">search</i>
</label>
<div class="mdl-textfield__expandable-holder">
<input class="mdl-textfield__input" type="text" id="search-expandable">
<label class="mdl-textfield__label" for="search-expandable">Search text</label>
</div>
</div>
Expandable text field with a floating label.
<div class="mdl-textfield mdl-js-textfield mdl-textfield--expandable
mdl-textfield--floating-label">
<label class="mdl-button mdl-js-button mdl-button--icon" for="search-expandable2">
<i class="material-icons">search</i>
</label>
<div class="mdl-textfield__expandable-holder">
<input class="mdl-textfield__input" type="text" id="search-expandable2">
<label class="mdl-textfield__label" for="search-expandable2">
Enter search text below
</label>
</div>
</div>
Configuration options
The MDL CSS classes apply various predefined visual and behavioral enhancements to the text field. The table below lists the available classes and their effects.
MDL class | Effect | Remarks |
---|---|---|
mdl-textfield |
Defines container as an MDL component | Required on "outer" div element |
mdl-js-textfield |
Assigns basic MDL behavior to input | Required on "outer" div element |
mdl-textfield__input |
Defines element as textfield input | Required on input or textarea element |
mdl-textfield__label |
Defines element as textfield label | Required on label element for input or textarea elements |
mdl-textfield--floating-label |
Applies floating label effect | Optional; goes on "outer" div element |
mdl-textfield__error |
Defines span as an MDL error message | Optional; goes on span element for MDL input element with pattern |
mdl-textfield--expandable |
Defines a div as an MDL expandable text field container | For expandable input fields, required on "outer" div element |
mdl-button |
Defines label as an MDL icon button | For expandable input fields, required on "outer" div's label element |
mdl-js-button |
Assigns basic behavior to icon container | For expandable input fields, required on "outer" div's label element |
mdl-button--icon |
Defines label as an MDL icon container | For expandable input fields, required on "outer" div's label element |
mdl-input__expandable-holder |
Defines a container as an MDL component | For expandable input fields, required on "inner" div element |
is-invalid |
Defines the textfield as invalid on initial load. | Optional on mdl-textfield element |
(1) The "search" icon is used here as an example. Other icons can be used by modifying the text. For a list of available icons, see this page.
Note: Disabled versions of each text field type are provided, and are invoked with the standard HTML boolean attribute
disabled
.<input class="mdl-textfield mdl-js-textfield" type="text" disabled>
This attribute may be added or removed programmatically via scripting.
Tooltips
Useful information on hover.
<!-- Simple Tooltip --> <div id="tt1" class="icon material-icons">add</div> <div class="mdl-tooltip" data-mdl-for="tt1"> Follow </div>
<style></style><!-- Large Tooltip --> <div id="tt2" class="icon material-icons">print</div> <div class="mdl-tooltip mdl-tooltip--large" for="tt2"> Print </div>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
via social media
<!-- Rich Tooltip --> <div id="tt3" class="icon material-icons">cloud_upload</div> <div class="mdl-tooltip" data-mdl-for="tt3"> Upload <strong>file.zip</strong> </div>
<style></style><!-- Multiline Tooltip --> <div id="tt4" class="icon material-icons">share</div> <div class="mdl-tooltip" for="tt4"> Share your content<br>via social media </div>
<style></style><style> body { padding: 20px; background: #fafafa; position: relative; } </style>
Introduction
The Material Design Lite (MDL) tooltip component is an enhanced version of the standard HTML tooltip as produced by the title
attribute. A tooltip consists of text and/or an image that clearly communicates additional information about an element when the user hovers over or, in a touch-based UI, touches the element. The MDL tooltip component is pre-styled (colors, fonts, and other settings are contained in material.min.css) to provide a vivid, attractive visual element that displays related but typically non-essential content, e.g., a definition, clarification, or brief instruction.
Tooltips are a ubiquitous feature of most user interfaces, regardless of a site's content or function. Their design and use is an important factor in the overall user experience. See the tooltip component's Material Design specifications page for details.
To include an MDL tooltip component:
1. Code an element, such as a <div>
, <p>
, or <span>
, and style it as desired; this will be the tooltip's target. Include an id
attribute and unique value to link the container to its tooltip.
<p id="tt1">HTML</p>
2. Following the target element, code a second element, such as a <div>
, <p>
, or <span>
; this will be the tooltip itself. Include a for
(or data-mdl-for
) attribute whose value matches that of the target's id
.
<p id="tt1">HTML</p>
<span for="tt1">HyperText Markup Language</span>
3. Add one or more MDL classes, separated by spaces, to the tooltip element using the class
attribute.
<p id="tt1">HTML</p>
<span for="tt1" class="mdl-tooltip">HyperText Markup Language</span>
The tooltip component is ready for use.
Examples
A target with a simple text tooltip.
<p>HTML is related to but different from <span id="xml"><i>XML</i></span>.</p>
<span class="mdl-tooltip" for="xml">eXtensible Markup Language</span>
A target with "rich" (containing HTML markup) tooltip text.
<p>HTML is related to but different from <span id="xml"><i>XML</i></span>.</p>
<span class="mdl-tooltip" for="xml">e<b>X</b>tensible <b>M</b>arkup <b>L</b>anguage</span>
A target with a long text tooltip that automatically wraps.
<p>HTML is related to but different from <span id="xml"><i>XML</i></span>.</p>
<span class="mdl-tooltip" for="xml">XML is an acronym for eXtensible Markup Language</span>
A target with tooltip text in a larger font size.
<p>HTML is related to but different from <span id="xml"><i>XML</i></span>.</p>
<span class="mdl-tooltip mdl-tooltip--large" for="xml">eXtensible Markup Language</span>
A target with a tooltip containing both an image and text.
<p>HTML is related to but different from <span id="xml"><i>XML</i></span>.</p>
<span class="mdl-tooltip" for="xml">
<img src="xml-logo-small.png" width="20" height="10"> eXtensible Markup Language</span>
Configuration options
The MDL CSS classes apply various predefined visual enhancements to the tooltip. The table below lists the available classes and their effects.
MDL class | Effect | Remarks |
---|---|---|
mdl-tooltip |
Defines a container as an MDL tooltip | Required on tooltip container element |
mdl-tooltip--large |
Applies large-font effect | Optional; goes on tooltip container element |
mdl-tooltip--left |
Positions the tooltip to the left of the target | Optional; goes on tooltip container element |
mdl-tooltip--right |
Positions the tooltip to the right of the target | Optional; goes on tooltip container element |
mdl-tooltip--top |
Positions the tooltip to the top of the target | Optional; goes on tooltip container element |
mdl-tooltip--bottom |
Positions the tooltip to the bottom of the target | Optional; goes on tooltip container element |