📖 Tips and tricks for writing a userstyle

  ### Table of Contents - [How can I see my changes in real time?](#how-can-i-see-my-changes-in-real-time) - [How can I hide sensitive information in preview screenshots?](#how-can-i-hide-sensitive-information-in-preview-screenshots) - [How do I convert preview images to WebP?](#how-do-i-convert-preview-images-to-webp) - [Installation](#installation) - [Usage](#usage) - [How do I theme images and SVGs?](#how-do-i-theme-images-and-svgs) - [SVG background images](#svg-background-images) - [`` elements](#img-elements) - [How do I set a variable to RGB values?](#how-do-i-set-a-variable-to-rgb-values) - [How can I inspect hard-to-grab elements?](#how-can-i-inspect-hard-to-grab-elements) - [How do I theme code blocks / syntax highlighting?](#how-do-i-theme-code-blocks--syntax-highlighting) ### How can I see my changes in real time? See ["Initial installation and live reload" - Stylus Wiki](https://github.com/openstyles/stylus/wiki/Writing-UserCSS#initial-installation-and-live-reload).   ### How can I hide sensitive information in preview screenshots? When taking screenshots of userstyles, you may want to hide sensitive information (such as your username, email, etc.). You may use the [Flow Circular](https://fonts.google.com/specimen/Flow+Circular) font to redact details by obscuring any text on the page. Use this snippet at the top of your userstyle to import and use the font: ```less @import url("https://fonts.googleapis.com/css2?family=Flow+Circular&display=swap"); * { font-family: "Flow Circular", cursive; } ```   ### How do I convert preview images to WebP? The Catppuccin project prefers to use the [WebP image format](https://en.wikipedia.org/wiki/WebP) for the asset preview images. We recommend using Google's [`cwebp`](https://developers.google.com/speed/webp/docs/cwebp) conversion utility to convert images to WebP. #### Installation | Method | Instructions | | ------------------------------------- | -------------------------------------------------------------------------------------- | | [Homebrew](https://brew.sh/) | `brew install webp` [[view cask]](https://formulae.brew.sh/formula/webp) | | [MacPorts](https://www.macports.org/) | `sudo port install webp` [[view port]](https://ports.macports.org/port/webp/) | | Binaries | See https://storage.googleapis.com/downloads.webmproject.org/releases/webp/index.html. | #### Usage > [!TIP] > See [the full documentation on `cwebp`](https://developers.google.com/speed/webp/docs/cwebp) for further reference. ``` cwebp -lossless old-image.png -o new-image.webp ``` The command above is converting the input image `old-image.png` to the output file `new-image-webp`, with a lossless quality conversion.   ### How do I theme images and SVGs? #### SVGs as `background-image`s Websites will sometimes use the `background-image` CSS property to apply an SVG, often for icons. We will refer to these as "external SVGs" throughout the rest of this guide, as the SVGs are usually at a different URL and linked to with [`url()`](https://developer.mozilla.org/en-US/docs/Web/CSS/url). Below is an example of what a rule for an external SVG could look like. ```css .xyz { background-image: url("https://example.org/assets/xyz.svg"); } ``` The easiest way to theme external SVGs is to visit the URL of the SVG and paste its contents in between the single quotes of the `escape('')` section of the following template: ```less .xyz { @svg: escape("..."); background-image: url("data:image/svg+xml,@{svg}"); } ``` > [!NOTE] > The `Invalid % without number` error may appear if you have not done the following step. Make sure to add/replace an interpolated color in the SVG contents (as is detailed below) for this error to go away. Now, replace any colors in the SVG with their respective Catppuccin variants. For example, take the following SVG icon for Twitter: ```xml ``` There is only one color used, `fill="#1D9BF0"`. That hex code is a shade of blue, so we can replace it with the `@blue` color using the `fill="@{}"` syntax ([variable interpolation](https://lesscss.org/features/#variables-feature-variable-interpolation)). ```less .twitter-icon { @svg: escape( '' ); background-image: url("data:image/svg+xml,@{svg}"); } ``` #### `` elements Theming an inline image is similar, but `content` is used instead of `background-image` to cover up the original image with our new one. As with the previous tip for `background-image`, you only need to update the SVG inside of the `escape('')` (see above for details). ```less img.xyz { @svg: escape("..."); content: url("data:image/svg+xml,@{svg}"); } ``` Again, following the example of theming a Twitter logo: ```less img.twitter-icon { @svg: escape( '' ); content: url("data:image/svg+xml,@{svg}"); } ```   ### How do I set a variable to RGB values? You can use the following snippet to get the raw RGB values from a color. ```less #rgbify(@color) { @rgb-raw: red(@color), green(@color), blue(@color); } --ctp-base: #rgbify(@base) []; // -> 30, 30, 46 ```   ### How can I inspect hard-to-grab elements? Paste the following snippet into your browser console, then trigger the event. Adjust the delay (in milliseconds) as needed. ```js setTimeout(function () { debugger; }, 3000); ``` ![](https://i0.wp.com/css-tricks.com/wp-content/uploads/2017/02/debugger.gif?ssl=1) GIF via ["Set a Timed Debugger To Web Inspect Hard-To-Grab Elements" - CSS Tricks](https://css-tricks.com/set-timed-debugger-web-inspect-hard-grab-elements/).   ### How do I theme code blocks / syntax highlighting? If a website uses [highlight.js](https://highlightjs.org/) or [Pygments](https://pygments.org/) for syntax highlighting, follow the steps for the syntax higlighter in use below. #### highlight.js Add the following line at the top of the userstyle, beneath the `@-moz-document` line. ```css @import url("https://unpkg.com/@catppuccin/highlightjs@0.2.2/css/catppuccin.variables.important.css"); ``` Then add the following lines beneath the color definition section (`@: @catppuccin[@@lookup][@];`) in the `#catppuccin` mixin: ```css --ctp-rosewater: #rgbify(@rosewater) []; --ctp-flamingo: #rgbify(@flamingo) []; --ctp-pink: #rgbify(@pink) []; --ctp-mauve: #rgbify(@mauve) []; --ctp-red: #rgbify(@red) []; --ctp-maroon: #rgbify(@maroon) []; --ctp-peach: #rgbify(@peach) []; --ctp-yellow: #rgbify(@yellow) []; --ctp-green: #rgbify(@green) []; --ctp-teal: #rgbify(@teal) []; --ctp-sky: #rgbify(@sky) []; --ctp-sapphire: #rgbify(@sapphire) []; --ctp-blue: #rgbify(@blue) []; --ctp-lavender: #rgbify(@lavender) []; --ctp-text: #rgbify(@text) []; --ctp-subtext1: #rgbify(@subtext1) []; --ctp-subtext0: #rgbify(@subtext0) []; --ctp-overlay2: #rgbify(@overlay2) []; --ctp-overlay1: #rgbify(@overlay1) []; --ctp-overlay0: #rgbify(@overlay0) []; --ctp-surface2: #rgbify(@surface2) []; --ctp-surface1: #rgbify(@surface1) []; --ctp-surface0: #rgbify(@surface0) []; --ctp-base: #rgbify(@base) []; --ctp-mantle: #rgbify(@mantle) []; --ctp-crust: #rgbify(@crust) []; ``` Finally, add the [`#rbgify` mixin](#how-do-i-set-a-variable-to-rgb-values) above the `@catppuccin` color palette at the bottom of the userstyle. #### Pygments Add the following line at the top of the userstyle, beneath the `@-moz-document` line. ```css @import url("https://python.catppuccin.com/pygments/catppuccin-variables.important.css"); ``` You'll also need to add the following lines beneath the color definition section (`@: @catppuccin[@@lookup][@];`) in the `#catppuccin` mixin: ```css --ctp-rosewater: @rosewater; --ctp-flamingo: @flamingo; --ctp-pink: @pink; --ctp-mauve: @mauve; --ctp-red: @red; --ctp-maroon: @maroon; --ctp-peach: @peach; --ctp-yellow: @yellow; --ctp-green: @green; --ctp-teal: @teal; --ctp-sky: @sky; --ctp-sapphire: @sapphire; --ctp-blue: @blue; --ctp-lavender: @lavender; --ctp-text: @text; --ctp-subtext1: @subtext1; --ctp-subtext0: @subtext0; --ctp-overlay2: @overlay2; --ctp-overlay1: @overlay1; --ctp-overlay0: @overlay0; --ctp-surface2: @surface2; --ctp-surface1: @surface1; --ctp-surface0: @surface0; --ctp-base: @base; --ctp-mantle: @mantle; --ctp-crust: @crust; ```