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 use any MDL component, you must include the minified CSS and JavaScript files using standard relative-path references in the <head>
section of the page, as described in the MDL Introduction.
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--heading">
...
</div>
<div class="mdl-card--img-container">
...
</div>
<div class="mdl-card--lower">
...
</div>
<div class="mdl-card--bottom">
...
</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--heading">
<h2 class="mdl-card--heading-text">Heading Text Goes Here</h2>
</div>
<div class="mdl-card--img-container">
<img src="photo.jpg" width="220" height="140" border="0" alt="" style="padding:20px;">
</div>
<div class="mdl-card--lower">
This text might describe the photo and provide further information, such as where and when it was taken.
</div>
<div class="mdl-card--bottom">
<a href="(URL or function)">Related Action</a>
</div>
</div>
The card component is ready for use.
A card (no shadow) with a heading, image, text, and action.
<div class="mdl-card">
<div class="mdl-card--heading">
<h2 class="mdl-card--heading-text">Auckland Sky Tower<br/>Auckland, New Zealand</h2>
</div>
<div class="mdl-card--img-container"><img src="skytower.jpg" width="173" height="157" border="0" alt="" style="padding:10px;">
</div>
<div class="mdl-card--lower">
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--bottom">
<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--z3">
<div class="mdl-card--img-container"><img src="skytower.jpg" width="173" height="157" border="0" alt="" style="padding:10px;">
</div>
<div class="mdl-card--caption">
Auckland Sky Tower, taken March 24th, 2014
</div>
<div class="mdl-card--lower">
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>
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-shadow--z1 through mdl-shadow--z5 |
Assigns variable shadow depths (1-5) to card | Optional, goes on "outer" div; if omitted, no shadow is present |
mdl-card--heading |
Defines div as a card heading container(1) | Required on "inner" heading div |
mdl-card--heading-text |
Assigns appropriate text characteristics to card heading | Required on head tag (H1 - H6) inside heading div |
mdl-card--img-container |
Defines div as a card image container | Required on "inner" image div |
mdl-card--lower |
Defines div as a card body text container(1) 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--caption |
Defines div as a card caption container and assigns appropriate text characteristics to caption text | Required on "inner" caption div; text goes directly inside the div with no intervening containers |
mdl-card--bottom |
Defines div as a card bottom text container(1) (typically an action bar) and assigns appropriate text characteristics to bottom text | Required on "inner" bottom div; content goes directly inside the div with no intervening containers |
For working examples of the card component, see the MDL card demo page.
Copyright Google, 2015. Licensed under an Apache-2 license.