Important - Deprecation Notice
MDCToolbar component and styles will be removed in a future release. Some of its functionality
will be available in the MDC Top App Bar package instead. Bugs and feature requests
will no longer be accepted for the
mdc-toolbar package. It is recommended that you migrate to the
mdc-top-app-bar package to continue to receive new features and updates.
MDC Toolbar acts as a container for multiple rows containing items such as application title, navigation menu, and tabs, among other things. Toolbars scroll with content by default, but support fixed behavior as well.
When using the fixed pattern, a persistent elevation is added to toolbar. When using the waterfall pattern, a toolbar will have no elevation when the page is scrolled to the top, and gain elevation when a user begins to scroll down the page. Toolbars also support anchored only last row at the top behavior. For toolbars with this modifier, only the last row will be anchored at the top, while the rest of toolbar scrolls off.
Flexible behavior can be added to mdc-toolbar, where the height of the toolbar changes as the user scrolls. Flexible is defined as a modifier class of toolbar but not a standalone component. Toolbars using this modifier will have additional height added to their first rows.
npm install @material/toolbar
Wrap the items with
mdc-toolbar class in the following way:
MDC Toolbars can accommodate multiple rows using the wrapper
Toolbar sections are aligned to the toolbar's center. You can change this
behavior by applying
mdc-toolbar__section--align-end to align the sections to the start or the end
of the toolbar (respectively).
Section aligns to start.Section aligns to center.Section aligns to end.
Toolbar sections are laid out using flexbox. Each section will take up an equal
amount of space within the toolbar by default. But you can accommodate very long section (very long title)
mdc-toolbar__section--shrink-to-fit to other sections.
This is a super super super super long titlesearch
You can use the
mdc-toolbar__title element to style toolbar text representing
a page's title, or an application name.
Icons can be added as anchor tags,
mdc-toolbar. There are two types of icons,
mdc-toolbar__menu-icon represents the left most icon in
mdc-toolbar usually to the left of
mdc-toolbar__icon represents any icons placed on the right side of an
We recommend using Material Icons from Google Fonts:
However, you can also use SVG, Font Awesome, or any other icon library you wish.
When using SVG icons, ensure you wrap the
svg element in an
a and include the
By default, toolbars scroll with the page content. To keep the toolbar fixed to
the top of the screen, add an
mdc-toolbar--fixed class to the toolbar element.
Adjusting sibling elements of fixed toolbars
mdc-toolbar--fixed, you need to set the margin of the content to
prevent toolbar overlaying your content. You can add the
helper class to the toolbar's adjacent sibling element, which will add default
When you are using
wrapper element to
mdc-toolbar's instance property
mdc-toolbar aware of the wrapper class and adjust the
mdc-toolbar--fixed, fixed toolbars become
waterfall toolbars. Waterfall toolbar is initially static and has no elevation,
and then when the user starts scrolling becomes fixed and gains elevation.
TitleA demo paragraph here.
mdc-toolbar--fixed, fixed toolbars
will anchor only the last row to the top.
<!-- This row will scroll off screen --><!-- This row will anchor on top of screen -->
Flexible behavior can be added to mdc-toolbar, whose height changes as the user
scrolls. Flexible behavior is highly customizable - we only define the change of
flexible space size without making further assumptions. But we do recommend the
height of flexible space should be an integral number of
height and provide a easier way for user to customize height. Users can adjust the
height of flexible space through sass variable
or css variable
Custom height of flexible space:
Flexible toolbars emit a
change custom event with a
detail object containing
flexibleExpansionRatio property. The
flexibleExpansionRatio property is a
number from 0-1 representing the ratio of flexible space that has already been
collapsed divided by the total amount of flexible space.
For the most common use case of flexible headers, we've defined a default behavior:
- Flexible has a fixed initial height 4 times the default size of
- When it has
mdc-toolbar--flexible-default-behavior, it further defines the background and title movement behavior.
Caveat: Complex animation performance
Due to the nature of having to listen for scroll events and mutate height, this may degrade performance in some mobile browsers. For example, combining high resolution images with parallax scrolling could lead to severe performance issues in certain mobile browsers. When implementing patterns like these for a mobile device, ensure that the image is as optimized as possible and carefully test the performance to make sure that it is adequate.
mdc-toolbar is automatically RTL-aware, and will re-position elements whenever
it, or its ancestors, has a
The block class is
mdc-toolbar. This defines the top-level toolbar element.
The component accommodates multiple rows using the wrapper
For each row, it has
mdc-toolbar__title elements. You
can add multiple sections to toolbar. Refer to Sections and Toolbar title for
The provided modifiers are:
||Makes toolbar fixed on top and have persistent elevation|
||Removes fixed toolbar persistent elevation and makes it gain elevation when a user begins to scroll down the page|
||Makes only last row of fixed toolbar anchored on top|
||Makes first row of toolbar have flexible space|
||Makes section align to the start|
||Makes section align to the end|
||Makes section take the width of its content|
||Sets the ink color of the toolbar|
||Sets the fill color of the toolbar|
||Sets the fill color of the toolbar and automatically sets a high-contrast ink color|
||Sets the ink color of a toolbar icon|
Including in code
ES Module syntax
const mdcToolbar = ;const MDCToolbar = mdcToolbarMDCToolbar;const MDCToolbarFoundation = mdcToolbarMDCToolbarFoundation;
const MDCToolbar = mdctoolbarMDCToolbar;const MDCToolbarFoundation = mdctoolbarMDCToolbarFoundation;
If you do not care about retaining the component instance for the toolbar, simply call
and pass it a DOM element.
;const toolbar = document;
Using the MDCToolbar Foundation Class
|Event Name||Event Data Structure||Description|
||Emits the ratio of current flexible space to total flexible space height. So when it is minimized, ratio equals to 0 and when it is maximized, ratio equals to 1. See types.ts.|
||Checks if the root element of the component has the given className.|
||Adds a class to the root element of the component.|
||Removes a class from the root element of the component.|
||Registers a handler to be called when user scrolls. Our default implementation adds the handler as a listener to the window's
||Unregisters a handler to be called when user scrolls. Our default implementation removes the handler as a listener to the window's
||Registers a handler to be called when the surface (or its viewport) resizes. Our default implementation adds the handler as a listener to the window's
||Unregisters a handler to be called when the surface (or its viewport) resizes. Our default implementation removes the handler as a listener to the window's
||Gets viewport (window) width.|
||Gets the number of pixels that the content of body is scrolled upward|
||Gets root element
||Gets first row element offsetHeight.|
||Broadcasts an event with the remaining ratio of flexible space. See types.ts.|
||Sets flexible row element style property to provided value.|