You can style your animation by tweaking the very large number of CSS variables documented on this page. There are also several style and HTML hooks that you can attach other CSS to. Some Themes also have their own CSS variables that you can change.
Property | Notes |
---|---|
font-family | Must be monospaced. See the guide on styling for information about emoji and CJK full-width characters |
font-size | Scales the entire animation, which uses a grid based on the font size |
--cm-cols | Number of columns for the animation. Defaults to the number of columns in the longest line in the input frames |
--cm-rows | Number of rows for the animation. Defaults to the max number of lines in the input frames |
--cm-line-height | Line height in multiples of 1ch (meaning a dimensionless number that scales the line height) |
--cm-content-margin-top | Distance of content (tokens, line number etc.) to the top. CSS <length> |
--cm-content-margin-left | Distance of content (tokens, line number etc.) to the left. CSS <length> |
--cm-content-margin-bottom | Distance of content (tokens, line number etc.) to the bottom. CSS <length> |
--cm-content-margin-right | Distance of content (tokens, line number etc.) to the right. CSS <length> |
--cm-align-middle | Turns vertical centering on (1 ) or off (0 ). |
--cm-animate-height | Whether to animate the container element's height (1 ) or keep it at the maximum required content height (0 ), defaults to 0 |
--cm-scene-background | See background property |
--cm-scene-filter | Global filter effect, see filter property |
--cm-code-filter | Filter effect for code, see filter property |
--cm-animation-duration | Global animation duration, see animation-duration property |
--cm-animation-timing-function | Global animation timing function, see animation-timing-function property |
The syntax highlighter categorizes each token as one of the following types, for which you can define the color
, font-weight
and font-style
.
Type | Available CSS properties |
---|---|
Generic | --cm-color --cm-style --cm-weight |
string | --cm-string-color --cm-string-weight --cm-string-style |
number | --cm-number-color --cm-number-weight --cm-number-style |
keyword | --cm-keyword-color --cm-keyword-weight --cm-keyword-style |
alternativeKeyword | --cm-alternativeKeyword-color --cm-alternativeKeyword-weight --cm-alternativeKeyword-style |
tag | --cm-tag-color --cm-tag-weight --cm-tag-style |
alternativeTag | --cm-alternativeTag-color --cm-alternativeTag-weight --cm-alternativeTag-style |
attribute | --cm-attribute-color --cm-attribute-weight --cm-attribute-style |
alternativeAttribute | --cm-alternativeAttribute-color --cm-alternativeAttribute-weight --cm-alternativeAttribute-style |
declaration | --cm-declaration-color --cm-declaration-weight --cm-declaration-style |
literal | --cm-literal-color --cm-literal-weight --cm-literal-style |
value | --cm-value-color --cm-value-weight --cm-value-style |
operator | --cm-operator-color --cm-operator-weight --cm-operator-style |
invocation | --cm-invocation-color --cm-invocation-weight --cm-invocation-style |
type | --cm-type-color --cm-type-weight --cm-type-style |
comment | --cm-comment-color --cm-comment-weight --cm-comment-style |
alternativeComment | --cm-alternativeComment-color --cm-alternativeComment-weight --cm-alternativeComment-style |
punctuation | --cm-punctuation-color --cm-punctuation-weight --cm-punctuation-style |
Token categorization is hardcoded into the syntax highlighter. If you work with multiple languages, you might want to apply different styles to different tokens depending on the language. This is possible because the output wraps tokens of each language in a container element with a class matching the language:
.cm-animation .language-ecmascript {
--cm-keyword-color: green; /* Keywords in JS/TS */
}
.cm-animation {
--cm-keyword-color: red; /* Keywords in other languages */
}
123456.cm-animation .language-ecmascript {
--cm-keyword-color: green; /* Keywords in JS/TS */
}
.cm-animation {
--cm-keyword-color: red; /* Keywords in other languages */
}
To apply filter
effects to either all syntax highlighted code or specific languages, you can use the same approach with the --cm-code-filter
variable:
.cm-animation .language-ecmascript {
--cm-code-filter: drop-shadow(2px 2px 2px #000); /* Shadow for JS/TS */
}
.cm-animation {
--cm-code-filter: hue-rotate(90deg); /* Color effect for other languages */
}
123456.cm-animation .language-ecmascript {
--cm-code-filter: drop-shadow(2px 2px 2px #000); /* Shadow for JS/TS */
}
.cm-animation {
--cm-code-filter: hue-rotate(90deg); /* Color effect for other languages */
}
Property | Notes |
---|---|
--cm-line-numbers-enabled | Turns line numbers on (1 ) or off (0 ) |
--cm-line-number-font | See font property |
--cm-line-number-color | Accepts any color value |
--cm-line-numbers-margin-left | CSS <length> |
--cm-line-numbers-margin-right | CSS <length> |
--cm-line-numbers-filter | See filter property |
--cm-line-numbers-margin-left
and --cm-line-numbers-margin-right
only have an effect when line numbers are turned on. In this case, the value of --cm-line-numbers-margin-left
gets added to --cm-content-margin-left
to determine the final left margin value.
Property | Notes |
---|---|
--cm-decoration-gutter-offset-top | CSS <length> |
--cm-decoration-gutter-offset-left | CSS <length> |
--cm-decoration-gutter-filter | See filter property |
--cm-decoration-gutter-font-family | See font-family property. |
--cm-decoration-gutter-z-index | |
--cm-decoration-gutter-mix-blend-mode |
Be extra sure to set --cm-decoration-gutter-font-family
to something that supports all the characters/emoji you want to use and make sure that the font is available to all users (eg. via @font-face
).
Property | Notes |
---|---|
--cm-decoration-line-foreground-filter | See filter property |
--cm-decoration-line-foreground-mix-blend-mode | |
--cm-decoration-line-foreground-backdrop-filter | See backdrop-filter property |
--cm-decoration-line-foreground-background | |
--cm-decoration-line-foreground-offset-left | CSS <length> |
--cm-decoration-line-foreground-offset-right | CSS <length> |
--cm-decoration-line-foreground-z-index | |
--cm-decoration-line-background-filter | See filter property |
--cm-decoration-line-background-mix-blend-mode | |
--cm-decoration-line-background-backdrop-filter | See backdrop-filter property |
--cm-decoration-line-background-background | |
--cm-decoration-line-background-offset-left | CSS <length> |
--cm-decoration-line-background-offset-right | CSS <length> |
--cm-decoration-line-background-z-index |
Keep in mind that you control the tags and attributes of your line decorations via their data
property. You can therefore have an arbitrary large collection of "classes" of line decorations that can all be styled individually.
Property | Notes |
---|---|
--cm-decoration-text-foreground-background | |
--cm-decoration-text-foreground-filter | See filter property |
--cm-decoration-text-foreground-mix-blend-mode | |
--cm-decoration-text-foreground-backdrop-filter | See backdrop-filter property |
--cm-decoration-text-foreground-z-index | |
--cm-decoration-text-foreground-underline-color | |
--cm-decoration-text-foreground-underline-width | Dimensionless number |
--cm-decoration-text-foreground-underline-scale | Dimensionless number, scales the entire SVG pattern that the underline is built from up or down |
--cm-decoration-text-foreground-underline-offset-y | CSS <length> |
--cm-decoration-text-foreground-underline-line | Turns this line style on (1 ) or off (0 ) |
--cm-decoration-text-foreground-underline-wave | Turns this line style on (1 ) or off (0 ) |
--cm-decoration-text-foreground-underline-squiggly | Turns this line style on (1 ) or off (0 ) |
--cm-decoration-text-foreground-underline-filter | See filter property |
--cm-decoration-text-foreground-underline-mix-blend-mode | |
--cm-decoration-text-foreground-underline-backdrop-filter | See backdrop-filter property |
--cm-decoration-text-foreground-underline-z-index | |
--cm-decoration-text-background-background | |
--cm-decoration-text-background-filter | See filter property |
--cm-decoration-text-background-mix-blend-mode | |
--cm-decoration-text-background-backdrop-filter | See backdrop-filter property |
--cm-decoration-text-background-z-index | |
--cm-decoration-text-background-underline-color | |
--cm-decoration-text-background-underline-width | Dimensionless number |
--cm-decoration-text-background-underline-scale | Dimensionless number, scales the entire SVG pattern that the underline is built from up or down |
--cm-decoration-text-background-underline-offset-y | CSS <length> |
--cm-decoration-text-background-underline-line | Turns this line style on (1 ) or off (0 ) |
--cm-decoration-text-background-underline-wave | Turns this line style on (1 ) or off (0 ) |
--cm-decoration-text-background-underline-squiggly | Turns this line style on (1 ) or off (0 ) |
--cm-decoration-text-background-underline-filter | See filter property |
--cm-decoration-text-background-underline-mix-blend-mode | |
--cm-decoration-text-background-underline-backdrop-filter | See backdrop-filter property |
--cm-decoration-text-background-underline-z-index |
Keep in mind that you control the tags and attributes of your text decorations via their data
property. You can therefore have an arbitrary large collection of "classes" of text decorations that can all be styled individually.