I was building up a small library of css snippets, and mixing and matching via copy-paste was getting tiresome.
So, I knocked myself up a little solution using https://sass-lang.com/
To use this solution, you need to follow the instructions on the website to install the SASS command line utility.
For my purposes, I created a subfolder in my Obsidian vault called ./.themes
where my obsidian.scss
file lives.
I also created a subfolder for mixins (./.themes/mixins
) containing small snippets like "Andy Matuschak" mode and collapsing sidebars (and my preferred custom colours for my Base2Tone theme)
For themes I want to switch between which have git repositories, I check them out into the .themes folder, and can reference them from my obsidian.scss
with the @add
directive, alongside @add
ing any of the mixin tweaks I want (I've included an example of my obsidian.scss below)
Once I'm happy with the theme and mixins I want, I run the following command from the root of my obsidian vault: sass .\.themes\obsidian.scss .\obsidian.css
This will compile the obsidian.css file and place it in my vault. A few moments later, Obsidian is looking different!
The syntax highlighting uses Prism.js and there are plenty of themes available.
Obsidian does wrap them in .theme-dark
or .theme-light
classes though, so you can't just drop in a theme and expect it to work.
This is exactly the kind of thing SASS is good at. Just wrap the whole theme in a .theme-dark {
or .theme-light {
block, and SASS will generate the appropriate css.
I've included the theme I'm using (originally from here) as an example.
Thank you for sharing your knowledge about CSS - it is not easy to get information about it and count on contributors like you is it very nice. I don't want to bother you but I will take my chance and make a question: do you know how to add extra spaces between blocks in preview mode? I had success in the edit mode but never in preview mode.