npm package
@mdi/js review
Use @mdi/js when your app owns the SVG renderer and you want named path imports.
An icon import can give you a string when you expected a component. @mdi/js 7.4.47 supplies Material Design Icons as SVG path data. Named exports such as mdiAccount hold the value for a path element's d attribute. Your code supplies the surrounding SVG, its size, color and accessible name. That makes the package useful when you already have an icon renderer, but it leaves real UI work to you.
Use @mdi/js when your app owns the SVG renderer and you want named path imports. Start with one icon in your actual production build, then check the emitted code and the control's accessible name before adopting it across a screen.
Answers from our run
@mdi/js or @mdi/svg: which should you use?
@mdi/svg: Choose @mdi/svg when you need Material Design Icons as SVG assets rather than JavaScript path exports. Use @mdi/js when your app owns the SVG renderer and you want named path imports.
When should you not use @mdi/js?
You expect an imported icon to be a ready-made component. mdiAccount is a string, so rendering it as a component is the wrong interface.
Use it if
Skip it if
Setup reality
Install the reviewed version with npm install @mdi/js@7.4.47, then import the named paths your screen needs. The published manifest points main to commonjs/mdi.js, module to mdi.js and types to mdi.d.ts. It declares sideEffects: false. Those are packaging signals, not evidence that every build tool will remove unused paths. The pinned README names WebPack 4 and Rollup for tree shaking; check your own production build rather than treating that old statement as a guarantee for a current toolchain.
The annoying part starts after the import. A path string needs an SVG element with the right coordinate system. The version-matched account asset uses viewBox="0 0 24 24". Give the SVG explicit dimensions, set the path's fill if it should follow text color, and decide whether the picture conveys information. Hide decorative icons from assistive technology. For an icon-only button, put the action name on the button itself. A standalone meaningful graphic needs its own accessible name. These are application responsibilities, not features supplied by the path export.
Keep dynamic selection finite. Import the few icons a screen accepts and build a local map, with a fallback for unknown keys. Avoid importing the whole catalog just to look up a name received from an API. The examples below illustrate integration with native DOM APIs and CSS; they were checked against the published-version source but were not executed in a browser or installed in a test project. No install timing, accessibility result or application bundle measurement is claimed.
Ratings use a documentation-based scale: 1 means the inspected material leaves the relevant contract largely unspecified, 3 means it supports a usable approach with material gaps, and 5 means detailed guidance and verification cover the dimension. Intermediate scores reflect partial coverage. Maintenance here rates published verification signals, and ecosystem rates documented integration formats. Neither measures support response, adoption or future compatibility.
Patterns
Import path data by name import-path
import { mdiAccount } from '@mdi/js'
console.log(mdiAccount)Documentation-based, unexecuted illustration. mdiAccount is SVG path data, not SVG markup or a component. Install 7.4.47 for the version reviewed here.
Create a decorative SVG with DOM APIs create-svg
import { mdiAccount } from '@mdi/js'
function decorativeIcon(data) {
const ns = 'http://www.w3.org/2000/svg'
const svg = document.createElementNS(ns, 'svg')
svg.setAttribute('viewBox', '0 0 24 24')
svg.setAttribute('width', '24')
svg.setAttribute('height', '24')
svg.setAttribute('aria-hidden', 'true')
svg.setAttribute('focusable', 'false')
const path = document.createElementNS(ns, 'path')
path.setAttribute('d', data)
path.setAttribute('fill', 'currentColor')
svg.append(path)
return svg
}
document.body.append(decorativeIcon(mdiAccount))Unexecuted browser illustration. The account asset uses a 24 by 24 viewBox. The helper creates a decorative image, so adjacent text must carry any meaning.
Name a standalone graphic name-graphic
const profileGraphic = decorativeIcon(mdiAccount)
profileGraphic.removeAttribute('aria-hidden')
profileGraphic.setAttribute('role', 'img')
profileGraphic.setAttribute('aria-label', 'Account')
document.body.append(profileGraphic)Uses decorativeIcon and mdiAccount from the earlier example. Removing aria-hidden matters before naming the graphic. This illustrates author-supplied labeling, not an accessibility test result.
Put the action name on the button label-button
const accountButton = document.createElement('button')
accountButton.type = 'button'
accountButton.setAttribute('aria-label', 'Open account settings')
accountButton.append(decorativeIcon(mdiAccount))
document.body.append(accountButton)Uses the earlier helper and import. Keep the inner image decorative to avoid repeating its name. This snippet creates the control; your app still needs to attach its settings action.
Size the SVG without changing its coordinates size-icon
const icon = decorativeIcon(mdiAccount)
icon.classList.add('account-icon')
document.body.append(icon)
/* Put this rule in your stylesheet. */
/* .account-icon { width: 1.25rem; height: 1.25rem; } */Uses the earlier helper and import. Keep viewBox at 0 0 24 24 for this artwork. CSS dimensions scale the viewport; changing viewBox instead can crop or reposition the drawing.
Let an icon follow text color inherit-color
const badge = document.createElement('span')
badge.style.color = '#2456a6'
badge.append(decorativeIcon(mdiAccount), ' Account')
document.body.append(badge)Uses the earlier helper and import. Its path explicitly sets fill to currentColor. Setting CSS color without that fill policy does not express the same rendering intent.
Limit runtime lookup to known icons bound-lookup
import { mdiAccount, mdiCheck } from '@mdi/js'
const paths = new Map([
['account', mdiAccount],
['done', mdiCheck],
])
function pathFor(name) {
return paths.get(name) ?? mdiAccount
}
console.log(pathFor('done'))Unexecuted illustration. Both named exports exist in the pinned implementation. The map supplies a fallback and bounds the imported set, but it does not prove a particular emitted bundle size.
Keep the path boundary explicit in TypeScript type-path
import { mdiAccount } from '@mdi/js'
function iconPath(data: string): string {
return data
}
const accountPath: string = iconPath(mdiAccount)Unexecuted TypeScript illustration. The package advertises mdi.d.ts, and the implementation supplies a string. This local function is your application contract, not an API exported by @mdi/js.
Alternatives
More infra guides
How this guide is made: grounded in the library's documentation, release notes, changelog, and issue history, on a fixed rubric — not a hands-on install of every release. The 50 most-downloaded entries are additionally install-verified in clean containers. Corrections: contact the desk.