Colors
Ionic has nine default colors that can be used to change the color of many components. Each color is actually a collection of multiple properties, including a shade
and tint
, used throughout Ionic.
A color can be applied to an Ionic component in order to change the default colors using the color
attribute. Notice in the buttons below that the text and background changes based on the color
set. When there is no color
set on the button it uses the primary
color by default.
#
Layered ColorsEach color consists of the following properties: a base
, contrast
, shade
, and tint
. The base
and contrast
colors also require a rgb
property which is the same color, just in rgb format. See The Alpha Problem for an explanation of why the rgb
property is also needed. Select from the dropdown below to see all of the default colors Ionic provides and their variations.
Name | Property | Default Value | Description |
---|
#
Modifying ColorsTo change the default values of a color, all of the listed variations for that color should be set. For example, to change the secondary color to
#006600
When secondary
is applied to a button, not only is the base color
#006600
#ffffff
#005a00
#1a751a
Not sure how to get the variation colors from the base color? Try out our Color Generator that calculates all of the variations and provides code to copy/paste into an app!
See the CSS Variables documentation for more information on CSS variables.
#
Adding ColorsColors can be added for use throughout an application by setting the color
property on an Ionic component, or by styling with CSS. Read on to see how to manually add a new color, or use the New Color Creator below for a quick way to generate the code of a new color to be copy and pasted into an application.
To add a new color, first define the CSS variables for all of the variations of the color at the root. For example, to add a new color called favorite
, we can define the following variables:
Then, create a new class that uses these CSS variables. The class must be written in the format .ion-color-{COLOR}
where {COLOR}
is the name of the color to add:
After the class is added, the color can be used on any Ionic component that supports the color
property. An example of using the favorite
color on an Ionic button is below.
The CSS variables defined at the root can also be used to style any element using CSS:
See the CSS Variables documentation for more information on setting and using CSS variables.
#
New Color CreatorCreate a new color below by changing the name and value, then copy and paste the code below into your project.