CSS-based theming enables apps to customize the colors quickly by loading a CSS file or changing a few CSS property values.
While the application and stepped variables in the themes section are useful for changing the colors of an application, often times there is a need for variables that are used in multiple components. The following variables are shared across components to change global padding settings and more.
|Font family of the app|
|Statusbar padding top of the app|
|Adjust the safe area inset top of the app|
|Adjust the safe area inset right of the app|
|Adjust the safe area inset bottom of the app|
|Adjust the safe area inset left of the app|
|Adjust the margin of the Margin attributes|
|Adjust the padding of the Padding attributes|
|Number of columns in the grid|
|Padding of the grid for xs breakpoints|
|Padding of the grid for sm breakpoints|
|Padding of the grid for md breakpoints|
|Padding of the grid for lg breakpoints|
|Padding of the grid for xl breakpoints|
|Padding of the grid columns for xs breakpoints|
|Padding of the grid columns for sm breakpoints|
|Padding of the grid columns for md breakpoints|
|Padding of the grid columns for lg breakpoints|
|Padding of the grid columns for xl breakpoints|
There is not yet full browser support for alpha use of a hex color. The rgba() function only accepts a value in
R, G, B, A (Red, Green, Blue, Alpha) format. The following code shows examples of correct and incorrect values passed to
See the CSS Variables section for more information on how to get and set CSS variables.
Ionic uses colors with an opacity (alpha) in several components. In order for this to work, those properties must be provided in RGB format. When changing any of the properties that have a variation ending in
-rgb, it is important they are also provided in a comma separated format without parentheses. Below are some examples for changing text and background color.
Note that the RGB formatted colors are the exact same color as the hex properties, but can now be used with
rgba(). For example,
--ion-text-color-rgb can now be used in the following way
CSS variables in media queries are not currently supported, but there are open drafts to add custom media queries and custom environment variables that would solve this problem! However, with the current state of support, the following will not work:
While it is possible to easily alter a color in Sass using its built-in functions, it is currently not as easy to modify colors set in CSS Variables. This can be accomplished in CSS by splitting the RGB or HSL channels and modifying each value, but it is complex and has missing functionality.
What exactly does this mean? Basically, using a CSS preprocessor, such as Sass, allows us to use functions to manipulate a single color. For example, we can create the following colors in Sass:
After running through the Sass compiler, the colors will have the following values:
However, because CSS variables can be set at runtime and are more dynamic, it is not currently possible to manipulate them using a simple function.
This is normally not a problem, but when an application needs to have dynamic theming it presents issues. In Ionic, this is the reason that there are variations to each color, and it is also why stepped colors are necessary for theming.
There are drafts and issues discussing color modification proposals that would make this possible.