CSS
You can style your animation by tweaking the very large number of CSS variables documented on this page. There are also several style hooks that you can attach other CSS for eg. backgrounds and borders to.
General styles
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-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-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 |
Syntax highlighting
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 */
}
Line numbers
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.
Gutter decorations
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 |
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
).
Line decorations
Property | Notes |
---|---|
--cm-decoration-line-foreground-filter | See filter property |
--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-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.
Text decorations
Property | Notes |
---|---|
--cm-decoration-text-foreground-background | |
--cm-decoration-text-foreground-filter | See filter property |
--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-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-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-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.