Custom styles
The comments widget loads one stylesheet of your own, custom.css, from your Remark42 instance, after its built-in styles. A rule in it wins over the built-in ones, whatever their selectors, as long as you do not put it in a cascade layer of your own. The class names and the color variables on this page are fixed: a release that renames or removes one says so in its notes.
Serving your file
The widget asks for /web/custom.css on your instance. Remark42 carries an empty one, so the request always succeeds, and a file of yours takes its place.
With Docker, mount your file into the image's web root:
services:
remark42:
image: ghcr.io/umputun/remark42:latest
volumes:
- ./var:/srv/var
- ./custom.css:/srv/web/custom.css:ro
Run docker compose up -d after adding the volume, which recreates the container with it. Later edits to the file need no restart: the widget checks the file on every load and fetches it again when it has changed. A mount of a single file follows the file it started with, though, so when the file is replaced instead of edited in place, as git pull and some editors do, run docker compose up -d --force-recreate to mount the new one.
Behind a proxy, you can answer the same address from the proxy instead. With nginx, in the server block of your instance, before the location that passes requests to Remark42:
location = /web/custom.css {
alias /etc/nginx/remark42/custom.css;
}
When the instance is served under a path of your site, as in Without subdomain, the address carries the path too, such as /remark42/web/custom.css.
When Remark42 runs as a binary, --web-root (REMARK_WEB_ROOT) names a directory that replaces the frontend built into the binary as a whole. A web root that holds only custom.css leaves the widget without its scripts and styles, so put your file next to a full copy of the frontend build, or serve it from your proxy.
There is no remark_config option that points the widget at a stylesheet elsewhere. A stylesheet loaded inside the widget's frame can read what the frame shows, the reader's name and the comment form included, and the page that embeds the widget is not always run by whoever runs the instance. The file comes from the instance, so only its owner decides what it contains.
The widget's frame allows no web fonts and loads images only from the sources the instance allows, so @font-face rules and fonts from a font service have no effect: name fonts your readers already have installed.
How your rules win
The built-in styles are in a cascade layer named remark42, and a rule outside any layer wins over every rule in one. You can write .comment-username { color: darkred; } and it applies, although the built-in rule it replaces, .comment-user .comment-username, has a longer selector. Rules of your own compete with each other as usual, by their selectors and their order. You never need !important against a built-in rule, and the built-in styles use none.
Browsers older than Chrome and Edge 99, Firefox 97 and Safari 15.4, all released in early 2022, ignore styles in a layer and show the widget without its built-in styles. The widget is built for newer versions than these.
Two kinds of value still win over your file:
- the values a page passes in
remark_config.custom_propertiesandcustom_properties_dark(see Changing the widget's colors): the first are set inline on the widget's root element and the second in an!importantrule for it, so for the same variable on the root they win over a declaration incustom.cssthat is not!important. Leave a variable out ofremark_configto set it from your file; - a few styles the widget's scripts set on elements while it runs: the height of the comment field as it grows with its text, the size of the placeholder that stands in for a comment until it first comes into view, the position of an open dropdown and of the emoji suggestions, the height and padding of the root element and the body in the profile view, the minimum height of the page while a dropdown is open and the color scheme of the root element. These follow what the reader does and are not meant to be restyled.
Colors first
The quickest change is a color variable. Most hold the three channels of a color, r, g, b, and the stylesheets read them as rgb(var(--name)), so a value is written without rgb() around it; the exceptions are below the table. A variable set on :root applies in both themes:
:root {
--link-color: 180, 30, 60;
--link-hover-color: 220, 50, 90;
}
The light and the dark theme are the classes light and dark on the root element. To give a theme a value of its own, set the variable for that theme:
:root.light {
--primary-color: 0, 100, 200;
}
:root.dark {
--primary-color: 90, 160, 255;
}
The variables and their built-in values:
| Variable | Light | Dark |
|---|---|---|
--chroma-bg | rgb(0, 0, 0, 0.05) | rgb(255, 255, 255, 0.05) |
--chroma-base | #586e75 | #a0b2b2 |
--chroma-c | #7d7d7d | #586e75 |
--chroma-01 | #589000 | #9ef203 |
--chroma-02 | #cb4b16 | #cb4b16 |
--chroma-03 | #268bd2 | rgb(80, 180, 252) |
--chroma-04 | #2aa198 | #2aa198 |
--chroma-06 | #d33682 | #ed403d |
--chroma-07 | #00aee2 | #a1e6fb |
--primary-color | 0, 117, 117 | 0, 153, 153 |
--primary-brighter-color | 0, 92, 92 | 0, 170, 170 |
--link-color | 0, 117, 117 | 0, 170, 170 |
--link-hover-color | 0, 92, 92 | 0, 197, 197 |
--primary-text-color | 38, 38, 38 | 241, 245, 249 |
--secondary-text-color | 100, 116, 139 | 209, 213, 219 |
--inverse-text-color | 255, 255, 255 | 255, 255, 255 |
--lighter-text-color | 106, 106, 106 | 150, 150, 150 |
--deactivated-color | 106, 106, 106 | 136, 136, 136 |
--primary-background-color | 255, 255, 255 | 38, 38, 38 |
--secondary-background-color | 238, 238, 238 | 51, 51, 51 |
--highlight-color | 241, 245, 249 | 64, 64, 64 |
--selection-color | 198, 239, 239 | 198, 239, 239 |
--shadow-color | 27, 31, 35, 0.15 | 27, 31, 35, 0.15 |
--downvote-color | 204, 6, 6 | 204, 6, 6 |
--upvote-color | 37, 158, 6 | 37, 158, 6 |
--verified-color | 14, 126, 157 | 14, 126, 157 |
--ghost-color | 156, 221, 219 | 156, 221, 219 |
--white-color | 255, 255, 255 | 255, 255, 255 |
--error-color | 185, 28, 28 | 255, 160, 160 |
--error-background | 255, 222, 230 | 103, 35, 35 |
--line-color | 226, 239, 239 | 87, 87, 87 |
--line-brighter-color | 203, 213, 225 | 136, 136, 136 |
--font-family | system-ui, -apple-system, 'Segoe UI', roboto, ubuntu, cantarell, 'Noto Sans', sans-serif | system-ui, -apple-system, 'Segoe UI', roboto, ubuntu, cantarell, 'Noto Sans', sans-serif |
--shadow-color adds a fourth number, the opacity. --font-family holds the list of fonts, and the --chroma- variables of the code highlighting hold whole colors, without the r, g, b form.
How the class names are built
Every class of the widget's own markup starts with the name of the part of the widget it belongs to, the block, as in comment. An element inside the block adds a word after a hyphen, as in comment-body and comment-text, and a variant of the block or of an element adds one after an underscore, as in comment_collapsed or comment-votes-score_negative. The root element of the widget's document carries light or dark for its theme, and its body carries dark in the dark theme as well, so .dark .comment-text reaches comment text in the dark theme only.
A few names are older than this scheme and keep their form, such as auth-button or profile-emptyState, and the code highlighter of the server marks the tokens of code in comments with short names of its own, such as k or nx.
Examples
Links in comments in a color of your own:
.comment-text a {
color: rgb(180, 30, 60);
}
Larger comment text in another font:
.comment-text {
font-size: 18px;
}
:root {
--font-family: Georgia, serif;
}
No avatars next to comments:
.comment-avatar {
display: none;
}
Commenters' names in the dark theme only:
.dark .comment-username {
color: rgb(255, 200, 0);
}
Square buttons in the comment form:
.comment-form-button {
border-radius: 0;
}
Finding a name
Open a page with comments, right-click the part of the widget you want to change and choose Inspect. The element is inside the widget's frame, and its class attribute holds the names below. The styles panel shows the built-in rules under the remark42 layer and yours above them.
If you injected styles through a proxy
Earlier versions gave the widget's elements generated class names, such as a_d, that changed from one release to the next, and the usual workaround was a proxy that added a stylesheet to the widget's document. Those names no longer exist. Rewrite your selectors with the names below, put the rules in custom.css, and remove the injection from the proxy.
Last comments and the counter
The last comments widget and the comment counter draw into your own page, so the styles of your site already reach them and custom.css does not. The last comments widget's classes start with remark42__last-comments, apart from raw-content on the text of each comment, and are listed below with the rest. Its built-in rules are in no layer, and it adds its stylesheet to your page after your own, so a rule of your site needs a selector that weighs more than the built-in one to win over it.
The class names
The widget and its theme
light, preloader, preloader_view_iframe, dark
Page layout
root, root-input, root-pinned-comment, root-pinned-comments, root-preloader, root-threads, root-copyright, root-sort-picker, root-more-comments, root-copyright-link, sort-picker
Threads
thread, thread_indented, thread-collapse, thread-collapse_collapsed
Comments
comment-user, comment-verification-button, comment-verification-icon, comment-verification-icon_inactive, comment-thread-starter, comment, comment-avatar, comment-body, comment-info, comment-input, comment-status, comment-warning, comment-text, comment-time, comment-username, comment_collapsed, comment-hidden-note, comment_editing, comment_replying, comment_useless, comment_view-admin, comment_view-user, comment-title, comment-title-link, comment_highlighting
Comment text
raw-content, sized, c1, cm, c, ch, cp, cpf, cs, ge, gr, gs, kd, kn, k, kc, kp, kr, kt, ow, nb, nc, bp, n, na, fm, nd, ne, nf, ni, nl, nn, no, nt, nv, nx, py, vc, vg, vi, vm, dl, il, l, ld, m, mb, mf, mh, mi, mo, s, s1, s2, sa, sb, sc, sd, se, sh, si, sr, ss, sx, g, gd, gh, gi, gl, go, gp, gt, gu
Comment actions
comment-actions, comment-actions-additional, comment-actions-countdown
Votes
comment-votes, comment-votes_disabled, comment-votes-button, comment-votes-up, comment-votes-up_active, comment-votes-down, comment-votes-down_active, comment-votes-score, comment-votes-score_negative, comment-votes-score_positive, comment-votes-up-icon, comment-votes-error, tooltip-root, tooltip, tooltip_permanent, tooltip_top-left
Comment form
comment-form, comment-form_simple, comment-form_reply, comment-form-control-panel, comment-form-field-wrapper, comment-form-field, comment-form-counter, comment-form-error, comment-form-actions, comment-form-button, comment-form-rss, comment-form-preview-wrapper, comment-form-preview, comment-form-markdown, comment-form-markdown-link, markdown-toolbar, markdown-toolbar-file-input, markdown-toolbar-item, markdown-toolbar-icon, markdown-toolbar-group, text-expander, text-expander-item, text-expander-emoji
Subscriptions
subscribe-by-email, subscribe-by-email-subscribed, subscribe-by-email-unsubscribed, subscribe-by-email-title, subscribe-by-email-description, subscribe-by-email-button, subscribe-by-email-preloader, subscribe-by-email-token-input, subscribe-by-email-error, subscribe-by-rss-dropdown, subscribe-by-rss-link, subscribe-by-telegram, subscribe-by-telegram-preloader, telegram, telegram-qr, telegram-submit
Sign-in
auth, auth-dropdown, auth-form-title, auth-divider, auth-tabs, auth-tabs-item, auth-tabs-radio, auth-row, auth-back, auth-back-arrow, auth-close-button, auth-token-textarea, auth-error, oauth, oauth-item, oauth-button, oauth-button_name, oauth-button_full, action-button, action-button-suffix, action-button_selected, action-button_xs, action-button_sm, action-button_transparent, action-button_hollow, action-button_link, auth-panel, auth-panel-column, auth-panel-text-link, auth-panel-column_separated, auth-panel-admin-action, auth-panel-user, auth-panel-user-button, auth-panel-user-logout-button, auth-panel-user-avatar, auth-back-button, auth-button, auth-form, auth-input-email, auth-input-username, auth-submit, oauth-icon
Settings
settings, settings-section, settings-action, settings-list, settings-list-item, settings-username, settings-user-id, settings-username_invisible, settings-dimmed
Profile
profile, profile_appear, profile_disappear, profile-sidebar, profile-close-button-wrapper, profile-header, profile-edit-avatar, profile-edit-avatar-hint, profile-comments, profile-error-content, profile-error, profile-footer, profile-avatar, profile-info, profile-name, profile-id, profile-signout, profile-title-wrapper, profile-comments-title, profile-counter-wrapper, profile-preloader, profile-emptyState, profile-load-more-wrapper, comments-counter, avatar, avatar_identicon, avatar_ghost, profile-title, profile_current
Controls
form-button, form-button_link, form-button_primary, form-button_secondary, form-button_middle, form-button_large, icon-button, input, select, select_sm, select_focused, select-element, select-arrow, dropdown, dropdown-content, dropdown-items, dropdown-title, dropdown_active, spinner, spinner_dark
Last comments
remark42__last-comments, remark42__last-comments-item, remark42__last-comments-title, remark42__last-comments-title-link, remark42__last-comments-info, remark42__last-comments-username, remark42__last-comments-text, remark42__last-comments-body, remark42__last-comments-item_deleted