Getting comfortable with Obsidian CSS

Thanks for the tip to checkout Hulk theme. I’ll do that.

For anyone else interested, the Hulk theme is here:
https://github.com/pgalliford/Obsidian-theme-Incredible-Hulk

3 Likes

Complete noob to css here, I’ve made some changes in the developer window (heading and code block colours) but when I exit the app it reverts to the default. Could anyone advise me how to make it stick?

As an Electron app, Obsidian operates within a quasi-browser—so you must mean that you edited the CSS or HTML of that browser’s developer tools pane/settings. Indeed, those would not save, as it’s similar to editing the CSS or HTML of any page you visit on the web—when you quit and reopen, you’ve essentially refreshed the page, so Obsidian calls its actual style code to inform how everything should look.

You should save your settings to a file called obsidian.css and keep that file at the root of your Vault.

You can create obsidian.css anew, but it may be easier to turn on a community theme and edit the one that appears with it.

I’ve been using Comfort Color Dark by ezs and tried editing the css file. Found the headers to change colours but I can’t find any reference to the code blocks anywhere. Probably missing something simple.

@andybyers I don’t see that theme in the forum or my CSS list, so I’m not sure. Try searching for the word Code. If you don’t find it then just append your own code at the bottom with !important at the end.

Here is the selector

.markdown-preview-view code {
color: red !important;
background-color: green !important;
}
1 Like

Just some notes on the CSS specific to 0.7+ that came up on the Discord:

divs with .workspace-leaf-content have a data-type (e.g. “markdown”) and they also have a data-mode="preview" when in preview mode (and corresponding data-mode="editor" for the editor).

Within the main container, there is div with class .workspace which contains:

  • the ribbons ( .workspace-ribbon.side-dock-ribbon.mod-left and .workspace-ribbon.side-dock-ribbon.mod-right )
  • the sidebars ( .workspace-split.mod-left-split and .workspace-split.mod-right-split )
  • and the main “root” workspace ( .workspace-split.mod-root ).

So, if you’re looking to target a note in a sidebar specifically, you’d probably be looking for something like .mod-left-split .workspace-leaf-content[data-type="markdown"]

5 Likes

It’s wried, I can’t open the developer window in Mac OS.

1 Like

@Jedi did you try “option+cmd+i” ?

1 Like

:+1: it works, thank you so much, now I can customize my theme.

Thank you for this! I was going crazy pressing Cmd-Shift-I and wondering why it wouldn’t work.

I have an obsidian.css now that’s based on a theme from someone else, plus, at the bottom, several additional customizations I’ve gradually accumulated.

I like to try new theme’s occasionally as they are posted here.

The issue is, it gets a little tedious each time to have to copy/paste in all my accumulating customizations on top of the new theme and then swap it in for my prev obsidian.css. Gets worse if I have more than 1 vault, using diff themes.

I thought probably there is a way in CSS to be more modular, and discovered there is in fact an @import statement.

So I tried making my obsidian.css consist soley of:

@import "obsidian-theme.css";
@import "my-customizations.css";

…so that I could easily swap in new themes, as well as easily adjust my customizations.

But not only did Obsidian not render any of the referenced styling, it seemed to confuse the parser - the cursor jumping around strangely.

Is a modular strategy like this viable, and if so, any tips on how can I get it to work?

Thanks!

3 Likes

I thought I was the only one who wanted this! Felt frivolous for me to ask for it, but seems like a few of us Theme Addicts are thinking in the same direction. However, you’re the second person to say the @import technique doesn’t work. I’m interested to see if anyone HAS gotten it to work by using a particular coding syntax. My research this morning said the @import stuff has to go at the top of the sheet, though – maybe that’s the issue? I haven’t dug into it yet because I’m still organizing my theme snippets for future import calls.

Edit: Just tried it, I can’t get it to work either. Thought maybe it was a file access permissions thing, but doesn’t appear to be.

2 Likes

Doesn’t that @import depend on the app you use for css?

Not sure if you mean the app for writing the CSS or for reading/using it, but either way, I don’t know, I am a relative CSS noob.

Was hoping there were some CSS experts here that could say how it works, and more importantly, what is possible for more modularly managing various sets of stylings.

I don’t know anything about the @import function, my comment is based an interpretation of your question, and yes, I meant the CSS writing/reading app.

I can’t help you with the @import thing… but most text editors have code snippets, maybe it’s a suitable alternative to manual copy/pasting for you ?
in Atom, you can create snippets to quickly reuse code (type aprefix + tab to auto-paste a multiline block) : https://www.hongkiat.com/blog/add-custom-code-snippets-atom/
It works with vscode, pspad, sublime, notepad++ (pick this one and NppSnippets/quicktext plugins if you want a lightweight portable solution), etc… alternatively, try a text-expander ?

TL;DR
use code snippets in atom, File>snippets :

'.source.css':
    'AnyTitleLikeAndyMode':
      'prefix': 'Andy'
      'body': """
          ....paste your snippet here between triple quotes....
          """

next open you obsidian.css, type `Andy’+tab (or whatever prefix you defined) and it will paste the rules you defined in the snippet.
Not as streamlined as @import but better than ctrlC ctrlV

1 Like

Thanks for the workaround and details, good idea

I experimented a bit further with import but obsidian seems to ignore it

other workarounds :

  • in windows cmd (win+x, run command prompt or powershell) : copy snippet1.css+snippet2.css+snippet3.css obsidian.css it will concatenate the snippets[1-3].css into a file named 'obsidian.css`

(or even faster copy *.css obsidian.css but make sure you operate from a dedicated folder with only the files you need as t will concatenate all css files into obsidian.css)

  • if you have Sass / Less : you can rename your css snippets to *.scss, then create a file obsidian.scss which contains :
@import 'snippet1';
@import 'snipper2';
@import 'snippet3';

next, open shell and run sass obsdian.scss obsidian.css
it should create a file obsidian.css which has the contents of your snippets.

4 Likes

Now you’re talking, I like the sass solution

Just quick tips that I haven’t found earlier:

  • do not create the obsidian.css file in Obsidian :wink: The filename will be obsidian.css.md, not obsidian.css. Create it in another text editor
  • Obsidian will detect changes to obsidian.css upon save and apply the stylesheet again - at least on Windows.
4 Likes