Svelte Material UI

A library of Material UI components for Svelte.

Demos, Code Samples, and Guides

https://sveltematerialui.com

Features

Here are some unique features that help SMUI stand out:

  • Full TypeScript support, including HTML attributes.
  • You can add arbitrary attributes to all of the components and many of the elements within them.
  • You can add actions to the components with use={[Action1, [Action2, action2Props], Action3]}.
  • You can add props to lower components and elements with "$" props, like input$maxlength="15".
  • SMUI supports RTL languages.

Installation

To get started, check out the installation docs or the SvelteKit docs.

Need Help?

If you need help installing or using SMUI, join the Matrix Space or the Discord server.

Svelte 5

SMUI v8 and higher requires Svelte 5.

If you are using Svelte 4, you can use SMUI v7, which is the last version to support Svelte 4. Check out the v7 branch for the v7 docs.

Migration

Upgrading from an old version? Be sure to read the migration doc.

Upgrading from v8? No more "@material" packages. Check out the upgrade instructions.

Upgrading from v7? You need Svelte 5. Event listeners no longer need to use the CustomEvent type. Check out the upgrade instructions.

Upgrading from v6? You need Svelte 4. No more elemental components; you can now use the "tag" prop to change the element. No more "ComponentDev" types; components can now be used as their type. Check out the upgrade instructions.

Upgrading from v5? If you're still using the advanced styling method, it's really time to switch to the easy styling method. '/styled' endpoints are no longer provided. Check out the upgrade instructions.

Upgrading from v4? SMUI v5 requires the TypeScript preprocessor. SMUI v6 does not though, so if you upgrade straight to v6, don't worry. Check out the upgrade instructions.

Upgrading from v3? SMUI's styling method has been simplified. Check out the upgrade instructions.

Upgrading from v2? There are lots of changes listed in the upgrade instructions.

Old Docs

You can find older versions of the docs on their respective branch:

Icons

You can include icons in a number of ways, but the easiest is the Material Icon Font. This will give you the standard set of Material Icons, available with the CSS class "material-icons".

<link
  href="https://fonts.googleapis.com/icon?family=Material+Icons"
  rel="stylesheet"
/>

However, there are two downsides. First is that all icons are downloaded, no matter which ones you use, so the size over the wire will almost certainly be more than necessary. Second is that it only includes the Material Icons from Google.

Another option is the Material Design Icons library. See the "Using SVGs" demo on the Icon Button demo page for instructions to use icons from the @mdi/js package (or any other SVG icons).

You can even use them in data URLs. To get a data URL for the icon:

  1. Find your icon and click "Copy SVG" button (it looks like </>).
  2. Base64 encode the document.
  3. Format the URL like this data:image/svg+xml;base64,encodedcontent, replacing "encodedcontent" with the Base64 results.
  4. Now you have an image URL you can use in an "img" tag src attribute or anywhere else you put an image URL (like background-image: url();).

Components

Click a component/package below to go to the documentation. (Note that this documentation is a work in progress. The demo code should be your main source of truth for how something works.)

† This is Sass based, and therefore doesn't require Svelte components. I've included a demo showing how you can use it.

  • Labels and icons are named exports in the components that use them, or you can use the 'Label' and 'Icon' exports from '@smui/common'. (Except for chips labels and icons, textfield icons, and select icons, because they are special snowflakes.)

Migrating Away from MDC-Web

SMUI v9 has migrated away from MDC-Web, to become a completely independent project. As such, SMUI v9 also gains new components to replace the functionality only found in MDC-Web packages (animation, density, dom, elevation, feature-targeting, focus, focus-ring, progress-indicator, rtl, shape, theme, tokens).

SMUI v9 includes all of the TypeScript from the upstream MDC-Web (adapters, foundations, components, etc.) in a basically unchanged state (brought up to the latest commit from the upstream repo). SMUI v10 will remove these TS files and concepts, migrating the functionality directly into the Svelte files.

I want to give a major shoutout to Google's amazing Material Design Components - Web library, without which, this project would not have been possible. SMUI has officially diverged from MDC-Web, as MDC-Web has been deprecated, but the incredible work the team at Google put in to making MDC-Web will live on, bringing Material Design to many amazing Svelte projects.

License

Portions of this project contain code from Google's MDC-Web project, and that code is licensed under the MIT License. This mainly includes the Sass styling, but may also include some TypeScript files. The files that this license applies to will include the MIT license and copyright notice. To the extent allowed under applicable law, these files will be released under the Apache License, Version 2.0 when included in this project's releases. All other code is released under the following license:

Copyright 2019-2026 Hunter Perrin

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Top categories

Loading Svelte Themes