2

I need to set custom color as primary in Angular Material. Reading some theaming guides and SO answers like Changing Primary Color in Angular Material 2 shows that I need to pick color from predefined set of colors. Can I use custom value?

1 Answer 1

7

You can use any color you want, but it must be defined in your own custom 'palette' in order to be used in theming. Have a look at the Angular Material palettes for examples. You would then use your palette in place of the material palettes like $mat-blue when you create your theme:

$my-blue: (
  50: #e3f2fd,
  ...
)
...
$primary: mat-palette($my-blue);
...
$theme: mat-light-theme($primary, $accent);

Search the web for angular material palette tool or similar. There are a number of free online tools for creating palettes from a base color.

Sign up to request clarification or add additional context in comments.

5 Comments

How do I know how to map colors? Eg should i use 50,100 or 200 ?
You need to do some research if you don't know that. You should define all of them: 50-900, plus the 'A's, and the contrasts. As I said - find an online tool to make life easier, or simply copy one the the Angular Material ones and change the values to your color. Keep in mind that a palette represents varying shades of a single color, plus contrasts colors used to display text over the corresponding palette color (so contrasts are typically white, black, or grey and not colored).
Thats the thing, I would like to skip whole palette creation but it looks like I cannot. Thanks for answer.
Yes - that's right - you need your own palette unless the color you want is already in one of the Angular Material palettes.
@G.Tranter Thanks, voted up. I think it is enough just generate scss file and use it in our project, is that true?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.