Quantcast
Channel: Envato Tuts+ Web Design
Viewing all articles
Browse latest Browse all 4350

Learning Material Design Lite: Buttons

$
0
0

Buttons form an integral part of any functional website (plus designers love them!) User actions on the web, generally, begin and end with clicking a button. In Google Mail for example, we create a new email by clicking on the Compose button. We will likely also click a few more buttons along the way to customize the email. And lastly, we click the Send button to send out the email. In this part of our Learning Material Design Lite (MDL) series, we’ll look into theButtons component.

The Buttons component in MDL is essentially a visual enhancement of the <button>, or an <a> element to comply with the Material Design aesthetic. In accordance with the specification, there are four types of button

  • flat
  • raised
  • float
  • icon

We’ll look into how to implement each of these and when which button works best.

As a reminder, ensure that you have the MDL stylesheets and the JavaScript set out within your document’s head. You can customize the color scheme that will be applied to the components using the MDL Theme builder.

Once they are all set, we can deploy theButtons component—starting with the flat type.

The Flat Button

Creating an MDL button is fairly straightforward. We can create a button either with a button element, an input element with submit type, or an anchor tag.

Add the mdl-button class to these elements to apply the MDL button styles.

In the demo below, we have created a flat button with the default color set to black.

The button text color is customizable by including one of the following modifier classes.

  • mdl-button--colored Add this class to apply the primary color to the button text.
  • mdl-button--accent Alternately, add this class to apply the accent color.

Referring to the main stylesheet name (material.teal-red.min.css), our primary color is “teal”, whereas “red” will be applied as the accent or the secondary color (enter text in the email input below to see those colors take effect).

The flat button is the most basic button type in MDL. It will work best in a situation where an action is intuitively expected, such as in a popup dialog, in a Card component, or in a Login or Sign-up form.

Due to its appearance, however, using a flat button within body text is not recommended. The flat button appears like a regular text, as you can see above. And since it does not explicitly present common button characteristics at first glance, the flat button would not convey the affordance that most users will recognize as being a clickable button.

A flat button in a middle of body text
Is that a button?

When the flat button does not feel appropriate, consider using a raised button type.

The Raised Button

The raised button portrays typical characteristics of a button; it is square with a drop shadow to give the raised effect. To create one, we start with a button element with the mdl-button class attached.

Then add the mdl-button--raised class to the element. Ass before, the raised button can also be customized with the addition of the mdl-button--colored or mdl-button--accent class.

Here we have raised buttons with the default, primary, and the accent color set as the button background.

The raised button is prominent, which makes it appropriate when users’ attention is top priority. It could be applied, for example, to a call-to-action button in the hero section, a submit button in a subscribe form, or a “Buy Now” button in a product page.

Note: keep in mind the hierarchy when applying a raised button. Using a raised button in a content layer with drop shadows, like a popup dialog, can make the content overly busy with elements fighting for attention.

Floating Action Button (FAB)

The Floating Action Button (FAB) has been acknowledged as the signature element of Material Design. The FAB is a circular button with an icon floating on a page. The purpose of an FAB is akin to the a call-to-action button; it emphasizes an action that users would—presumably—perform the most. It’s usually present with a vivid color that makes it more prominent among the rest of the UI elements on that page.

Spot the FAB

Once again, we start a Floating Action Button with an empty button element with the mdl-button class. This time, instead of text, we include an include an icon within the button. Refer to the Material Design icon guideline to pick the icon name to display.

To turn the button into an FAB, we add the mdl-button--fab class, additionally with the mdl-button--colored to modify the background color.

As you can see below, the FAB button takes the accent color when set to a colored button, as opposed to the primary color, as we saw with the flat and raised buttons.

MDL applies the primary color throughout most of the “colored” components, such as the navigation, tabs, text fields, sliders, and checkboxes, which makes it utterly dominant. The FAB should be more prominent among the rest of the UI, thus it takes on the accent color by default.

In any case when the primary color turns out to be more apt, you can add the mdl-button--primary class instead.

Here it is with the primary color:

Icon Button

Unlike FAB, the icon does not take the form of a circle; it appears simply as an icon. An icon button comes in handy where space is limited, or it is sufficient to represent the button purpose as users are accustomed to the application. Take the Google Docs toolbar as an example:

Using a textual button for a toolbar in this case would be unimaginable.

The icon button is formed through the mdl-button and mdl-button--icon class combination:

This example displays an icon that depicts upload or backup functionality:

The Button Ripple Effect

Furthermore, these buttons can be enhanced with the ripple effect. The ripple effect is another one of Material Design’s visual signatures and provides visual feedback when the button has been clicked. The effect starts at the coordinate when the click is made, replicating how the effect works in real life. 

This enhancement comes through two classes: mdl-js-button and mdl-js-ripple-effect which can be applied to any MDL button types.

Add these two classes to the button:

and the ripple effect should now be applied:

Inactive Buttons

In some cases, such as when a required text field is still empty, or a particular option is yet to be selected, the actionable button might be better off disabled. To disable MDL buttons, add the HTML boolean attribute disabled to the button element:

The button should now be unresponsive to user interaction (the ripple effect will also be disabled). Adding the color modifier classes mdl-button--colored or mdl-button--accent, will also have no affect on disabled buttons.

The disabled attribute, though not valid HTML, is also applicable to buttons created with an anchor tag.

Wrapping Up

Buttons are pretty simple to implement. We can build a nicely styled button, with a smooth ripple effect animation, with only a couple of classes. Personally, I hope the component will be further improved by taking inspiration from the Bootstrap Button component, by perhaps including the Button Groups variant.

In the next instalment of this series, we are going to look at the Text Fields component, which we have already encountered a few times so far.

Until next time!


Viewing all articles
Browse latest Browse all 4350

Trending Articles