{"id":13405855,"url":"https://github.com/johannesjo/angular-material-css-vars","last_synced_at":"2025-12-29T23:34:10.529Z","repository":{"id":35063190,"uuid":"202175458","full_name":"johannesjo/angular-material-css-vars","owner":"johannesjo","description":"Little library to use css variables with @angular/material","archived":false,"fork":false,"pushed_at":"2024-10-11T14:36:57.000Z","size":11035,"stargazers_count":194,"open_issues_count":6,"forks_count":32,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-20T11:54:24.047Z","etag":null,"topics":["angular","hacktoberfest"],"latest_commit_sha":null,"homepage":"https://johannesjo.github.io/angular-material-css-vars/","language":"SCSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/johannesjo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["json-derulo","johannesjo"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2019-08-13T15:40:33.000Z","updated_at":"2024-10-11T14:37:01.000Z","dependencies_parsed_at":"2023-10-11T12:34:01.956Z","dependency_job_id":"f6957fc3-4790-4995-ad43-4a46f32e4c7f","html_url":"https://github.com/johannesjo/angular-material-css-vars","commit_stats":{"total_commits":342,"total_committers":19,"mean_commits":18.0,"dds":0.4093567251461988,"last_synced_commit":"35b0f316fc083528c058b952c01529962b51a32b"},"previous_names":[],"tags_count":59,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johannesjo%2Fangular-material-css-vars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johannesjo%2Fangular-material-css-vars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johannesjo%2Fangular-material-css-vars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johannesjo%2Fangular-material-css-vars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johannesjo","download_url":"https://codeload.github.com/johannesjo/angular-material-css-vars/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221458242,"owners_count":16825276,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","hacktoberfest"],"created_at":"2024-07-30T19:02:13.986Z","updated_at":"2025-12-29T23:34:10.524Z","avatar_url":"https://github.com/johannesjo.png","language":"SCSS","readme":"\u003cp align=\"center\"\u003e\u003cimg alt=\"logo\" src=\"logo.png\"\u003e\u003c/p\u003e\n\nYou want to style your angular material dynamically with all the colors in the rainbow? Look no further!\n\n[Check out the Demo!](https://johannesjo.github.io/angular-material-css-vars/)\n\n## Setup\n\n1. Install:\n   ```bash\n   npm i angular-material-css-vars -S\n   ```\n2. If @angular/material is already configured remove `@include mat.core()` from your main stylesheet file if present.\n3. Add this to your main stylesheet instead:\n\n   ```scss\n   @use \"angular-material-css-vars\" as mat-css-vars;\n\n   @include mat-css-vars.init-material-css-vars();\n   ```\n\n4. Add to your main module:\n\n```typescript\nimport { MaterialCssVarsModule } from \"angular-material-css-vars\";\n\n@NgModule({\n  imports: [\n    MaterialCssVarsModule.forRoot({\n      // all optional\n      isAutoContrast: true,\n      primary: \"#3f51b5\",\n      // ...\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\nIn standalone workspaces, add the following to your `app.config.ts`:\n\n```typescript\nimport { ApplicationConfig } from \"@angular/core\";\nimport { provideMaterialCssVars } from \"angular-material-css-vars\";\n\nexport const appConfig: ApplicationConfig = {\n  providers: [\n    provideMaterialCssVars({\n      // all optional\n      isAutoContrast: true,\n      primary: \"#3f51b5\",\n      // ...\n    }),\n  ],\n};\n```\n\n5. If you want to adjust the theme at runtime, you can use `MaterialCssVarsService`:\n\n   ```typescript\n   import { MaterialCssVarsService } from \"angular-material-css-vars\";\n\n   export class SomeComponentOrService {\n     constructor(public materialCssVarsService: MaterialCssVarsService) {\n       const hex = \"#3f51b5\";\n       this.materialCssVarsService.setDarkTheme(true);\n       this.materialCssVarsService.setPrimaryColor(hex);\n       this.materialCssVarsService.setAccentColor(\"#333\");\n     }\n   }\n   ```\n\n\u003e Angular Material v18 introduced stable support for M3 theme.\n\u003e For now, this library only supports M2.\n\u003e More information can be found in this [issue](https://github.com/johannesjo/angular-material-css-vars/issues/166).\n\n## Additional Features\n\n- Auto or manually set contrast color via\n  - `setAutoContrastEnabled(bool)`\n  - `setContrastColorThreshold(hueVal: HueValue)`\n- Helper to set all variables\n  - `setVariable(cssVarName: MaterialCssVariables, value: string)`\n  - You can use the `MaterialCssVariables` enum [from here](https://github.com/johannesjo/angular-material-css-vars/blob/master/projects/material-css-vars/src/lib/model.ts) to make sure you get the variable name right.\n- Rudimentary dark theme support via body class\n  - `setDarkTheme(isDark: boolean)`\n\n## Utility\n\nThere are also several [utility functions and mixins](https://github.com/johannesjo/angular-material-css-vars/blob/master/projects/material-css-vars/src/lib/_public-util.scss).\n\n```scss\n@use \"angular-material-css-vars\" as mat-css-vars;\n\n.with-color {\n  border-color: mat-css-vars.mat-css-color-primary(300);\n}\n\n.color-and-contrast {\n  @include mat-css-vars.mat-css-color-and-contrast(300);\n}\n\n.with-bg {\n  @include mat-css-vars.mat-css-bg(300);\n}\n```\n\nThere are also [some additional hacks](additional-hacks.md) (e.g. adding a color to the elevation shadow) available in case you need them.\n\n## Initialization Options\n\nYou can provide different options before initialization to change the body class used for the dark theme and to provide different default styles:\n\n```scss\n...\n@use 'angular-material-css-vars' as mat-css-vars with (\n  $dark-theme-selector: '.isDarkTheme',\n  $light-theme-selector: '.isLightTheme'\n);\n...\n\n@include mat-css-vars.init-material-css-vars();\n\n```\n\n### Set default (fallback palettes)\n\nThere are two ways to set the default fallback theme. One is using the `mat-css-palette-defaults` mixin.\n\n```scss\n@use \"angular-material-css-vars\" as mat-css-vars;\n@use \"@angular/material\" as mat;\n\n@include mat-css-vars.init-material-css-vars();\n\n@include mat-css-vars.mat-css-set-palette-defaults(mat.$light-blue-palette, \"primary\");\n@include mat-css-vars.mat-css-set-palette-defaults(mat.$pink-palette, \"accent\");\n@include mat-css-vars.mat-css-set-palette-defaults(mat.$red-palette, \"warn\");\n```\n\nThe other is to include your own variables for [$default-light-theme](https://github.com/johannesjo/angular-material-css-vars/blob/master/projects/material-css-vars/src/lib/_variables.scss).\n\n```scss\n@use \"angular-material-css-vars\" as mat-css-vars with (\n  $default-light-theme: (\n    --palette-primary-50: mat-css-vars.hex-to-rgb(#e1f5fe),\n    --palette-primary-100: mat-css-vars.hex-to-rgb(#b3e5fc),\n    --palette-primary-200: mat-css-vars.hex-to-rgb(#81d4fa),\n    --palette-primary-300: mat-css-vars.hex-to-rgb(#4fc3f7),\n    --palette-primary-400: mat-css-vars.hex-to-rgb(#29b6f6),\n    --palette-primary-500: mat-css-vars.hex-to-rgb(#03a9f4),\n    // ...\n  )\n);\n\n@include mat-css-vars.init-material-css-vars();\n```\n\n### Set global density\n\nTo set the global density level, just pass the `$density` variable to the `init-material-css-vars()` mixin like the following:\n\n```scss\n@use \"angular-material-css-vars\" as mat-css-vars;\n\n@include mat-css-vars.init-material-css-vars($density: -2);\n```\n\n## App Theme Mixins\n\nThe `init-material-css-vars` mixin allows content to be passed into it. This allows you to create app themes that can take advantage of the dynamic theme created inside this mixin. It may be possible to do all theming using the utility mixins outlined above, but in other cases, you may need access to the theme palette, including foreground and background palettes.\n\nSee the Material guide on [Theming your custom component](https://material.angular.io/guide/theming-your-components) for more information.\n\n## Font config\n\nIf needed the typography can be adjusted as well. You can introduce your own CSS variables, if you wish.\n\n```scss\n@use \"angular-material-css-vars\" as mat-css-vars;\n@use \"@angular/material\" as mat;\n\n// example\n$custom-typography: mat.define-typography-config(\n  // optionally, you introduce your own CSS variables: `$font-family: var(--my-custom-font-family)`\n  $font-family: \"Roboto, monospace\",\n  $headline: mat.define-typography-level(32px, 48px, 700),\n  $body-1: mat.define-typography-level(16px, 24px, 500)\n);\n\n@include mat-css-vars.init-material-css-vars($typography-config: $custom-typography) using($mat-css-theme) {\n  @include app-theme($mat-css-theme);\n}\n\n@mixin app-theme($theme) {\n  // Your app theme\n}\n```\n\n## Legacy components support\n\nAngular Material v15 introduces MDC based components, which is basically a re-write for a lot of the available components. `angular-material-css-vars` v5+ only supports MDC components.\n\nIn case you are still using the legacy components, you can use the package [angular-material-css-vars-legacy](https://github.com/json-derulo/angular-material-css-vars-legacy).\n\n## Angular compatibility table\n\n| Angular | angular-material-css-vars |\n| ------- | ------------------------- |\n| 21      | 10.x                      |\n| 20      | 9.x                       |\n| 19      | 8.x                       |\n| 18      | 7.x                       |\n| 17      | 6.x                       |\n| 16      | 5.x                       |\n| 15      | 4.x                       |\n| 13/14   | 3.x                       |\n| 12      | 2.x                       |\n| 11      | 1.x                       |\n\n## Credit...\n\n...goes to @zbirizdo [project](https://github.com/zbirizdo/material-css-vars) on which parts of this are based which is in turn supposedly based on [this gist](https://gist.github.com/shprink/c7f333e3ad51830f14a6383f3ab35439).\n\n...and to @pedrojrivera without whom there would be no support for @angular/material v12.\n\n## Development server\n\nRun `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.\n","funding_links":["https://github.com/sponsors/json-derulo","https://github.com/sponsors/johannesjo"],"categories":["SCSS","Third Party Components"],"sub_categories":["UI Libraries built on Material"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohannesjo%2Fangular-material-css-vars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohannesjo%2Fangular-material-css-vars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohannesjo%2Fangular-material-css-vars/lists"}