Getting Started with React
Material Design Icons Light can be used in React with our first-party @mdi/react
module.
Demo MaterialDesign-React on GitHubnpm install @mdi/react @mdi/light-js
View Example App on CodeSandboximport React, { Component } from 'react'; import Icon from '@mdi/react'; import { mdilAccount } from '@mdi/light-js'; class App extends Component { render() { return ( <Icon path={mdilAccount} title="User Profile" size={1} horizontal vertical rotate={90} color="red" spin /> ); } };
Prop | PropTypes | Default | Details |
---|---|---|---|
path | string | required | SVG path data from @mdi/light-js |
title | string, null | null | A11y <title>{title}</title> |
description | string, null | null | A11y <desc>{desc}</desc> |
size | number, string | null | {size * 1.5}rem , '1em' , '24px' |
horizontal | bool | false | Flip Horizontal |
vertical | bool | false | Flip Vertical |
rotate | number | 0 | degrees 0 to 360 |
color | string | currentColor | CSS color values, such as rgb() , rgba() , #000 , etc |
spin | bool, number | false | true = 2s , {spin}s |
Applying a className
attribute is usually the easiest solution. The example below demonstrates using SCSS to style the icons.
In most cases it may be a good idea to set a base size. Assuming a 16px
base font-size
in most themes applying 1.5rem
will make the icon a 24px
.
svg { width: 1.5rem; }
For more specific styling apply classes. To make selection of layers easier use the nth-child
selector.
// For <Icon className="custom-class" /> svg.custom-class { path { fill: blue; } } // For <Stack className="custom-class"> svg.custom-class { // First layer (behind) path:nth-child(1) { fill: blue; } // Second layer (infront) path:nth-child(2) { fill: red; } }
Making icons accessible can be done through the title
prop. If for some rare reason more information is required a description
field can also be used.
By leaving off the title
prop an icon is assumed to be presentation only. These will be ignored by screen readers. This is ideal for icon buttons or areas where text next to the icon suffices.
<p><Icon path={mdilAccount} /> User Profile</p> <p><Icon path={mdilAccount} title="User Profile" /></p> <button aria-label="User Profile"><Icon path={mdilAccount} /></button>