When I have two editors in two different html DOM elements, if I dynamically change theme on one editor using updateOptions() function, theme properly changes on the editor, but the other editor takes some changes, for example font colors change but background does not.
The other editor should stay unchanged.
Reacted by Domagoj Vukovic, Pawan Kumar Singh, Russ Zhong, Emily, Tom Watson, ThibaudAV, Aleš, KeterSCP, Caleb Liu, Veli Tasalı and 9 more
It is currently not possible to have two editors have different themes.
Reacted by lewiskong, Daniele Esposti, Iman Mahmoudinasab, Arseniy Rubtsov, Jonathan Dobson, Vadym Yarovoi, 无止休, Xiangpeng Hao, SlurpTheo, Shayan Ali and 96 more
Reacted by Shripad Krishna, sutinghui24, Tucker and Andrey Dolgorukiy
Reacted by Walton Seymour, Mac Lockard, David Hsu, Iman Mahmoudinasab, Nick Aversano, Faris Masad, Chenggang Wang, coderaiser, Abhishek Kalia, Shayan Ali and 37 more
It is possible and that's the only way to do it in the current state, but that could add some unnecessary code.
What I wanted to say is that changing theme on one editor should either affect all the editors in the same way as the editor we changed theme on, or not affect them at all. This way, it just makes some changes to other editors which makes the text in them unreadable.
So I think this is more of a bug than a feature-request.
Reacted by Alexandru Dima, Shayan Ali, Nico Lueg, Luka Maljic, kayoch1n, hamflx and PetrLaskevic
changed the title [-]Changing theme does not work when there are two editors[/-][+]Changing theme in one editor should change all editors[/+]on Jan 25, 2017
Why is not possible to have multiple editors of different themes?
Reacted by SlurpTheo, David Hsu, Arseniy Rubtsov, Aleksandr Serenko, yann, Anatoli Kurtsevich, Tevfik Tümer, Tim Marwick, Season Chen, Nico Lueg and 43 more
-1 to Changing theme in one editor should change all editors
This is counter intuitive as the create editor function leads one to believe that themes should work on a per editor basis. There are many use cases (I have one right now which is broken) that require having multiple editors on a page styled differently. This also worked fine a few versions ago so not sure why it was changed... I'm interested in why the monaco-token-styles is injected globally as I would be open to working on a PR to fix this if necessary.
Reacted by SlurpTheo, Anthony, Walton Seymour, Petrisor Lacatus, Kishore, Arseniy Rubtsov, Jonathan Dobson, devxleo, Naeem, Tevfik Tümer and 36 more
Geekeren (@geekeren) excited you may have potentially found a solution to this! What is defaultTheme, is that anything special? Also, while your component successfully creates the CSS variables and scopes it, I am getting this:
That is, the style highlighted span elements have a class like mtk20 which is not scoped to monaco-editor or the CSS variables, and it uses that for color. Any ideas what I'm missing or how to get those to change?
Lance Pollard (@lancejpollard) it's unfortunately that the solution is not well solve the grammar highlight. the class name "mk-xxx" is dynamic generated differently in different theme.
Lance Pollard (@lancejpollard) the defaultTheme in my code is vs theme, or vs-dark theme, I just keep the two monaco editors' base theme is same. if they are different, the class name "mk-xxx" will be confilict
In another thought, because Sandpack does not use Monaco (it uses CodeMirror it looks like, because CodeMirror works better on mobile it sounds like), I might switch to using CodeMirror so I only have one technology in the app, if I chose to use Sandpack one of these days for something else too.
I have run into the same issue here. In my case, I have a list component where, each list item is an expandable card with editors. That particular editor has a specific style because its wrapped by the expandable card. To add list items I have a modal where i need to have another code editor instance. However, since my modal styles are different, the colors do not match so I need another style. My problem was that since the styles are different, every time I opened the modal, the global styles were changed and then, every editor on the page had the style of the modal.
I fixed this issue by using the global keyword in my scss file. I did it like so:
.CodeEditorWrapper {
// other styles from the wrapper
:global {
.monaco-editor {
--vscode-editor-background: #{#121212};
--vscode-editorGutter-background: #{#2a2a2a};
}
}
}
Please also note that I am using scss modules, so, even if I have another instances of CodeEditorWrapper with other styles, this will still work be conscious that this might not work with simple css.
Bumping because I'm trying to solve a problem where a new editor instance causes all editors to revert back to the default theme, even though I have already called monaco.editor.defineTheme(themeName, themeData) and monaco.editor.setTheme(themeName) long before.
Partial solution is to call editor.updateOptions({ theme: currentMonacoTheme }) during the provided onMount callback, but this still leaves a momentarily flash of the ugly default white theme.
EDIT: Solved my flashing issue! The trick here, at least for @monaco-editor/react is to include the current theme in the JSX options like so as the theme:
<MonacoEditorReactpath={path}options={options}// even though we have options.theme heretheme={theme}// add this herelanguage={language}value={value}beforeMount={beforeMount}onMount={onMount}onChange={onChange}/>
EDIT2: It still flashes un-syntax-highlighted code but I think this is good enough for me for now.
What about setting different language for each editor? Wouldn't that help?
It doesn't help unfortunately as Monaco would still use the same CSS variable names for all editors.
The workaround that we used was ensuring that each editor's language has unique token names so they don't overlap. It seems that for each theme rule for a specific token, Monaco creates a unique CSS variable. So for example, if you want the comments in one editor to be one color and in another editor another color, you need to give them unique token names (e.g. comment.lang1, comment.lang2, etc) and make theme rules for each of them accordingly. But if something should have the same color in all editors, it's okay to have a common token name for all of them.
Regarding the theme editor colors (e.g. editor.foreground), that unfortunately can't be solved with the above approach and all editors would need to have the same colors, which luckily worked for our use case.
It was created on January 24th, 2017, and a total of 2,950 days have passed until February 21st, 2025. I can hardly believe that there still hasn't been a good solution for it.
Reacted by Matic Jurglič, Ethan Lee, Kevin Go, Almog Baku, Aruna, ivanksh, Zihan (Lexie) Zhou, Andrey Dolgorukiy, Karakatiza666, PetrLaskevic and 6 more
Can we generate a prefix for classes that are used inside the editor to make them local instead of global? For example with some prop to generate unique classes?
Activity
alexdima commented on Jan 24, 2017
It is currently not possible to have two editors have different themes.
fzafiroski commented on Jan 24, 2017
The problem is that I can't dynamically change theme at all, because if I change to one editor, the other one gets messed up.
alexdima commented on Jan 25, 2017
Is it not possible to change it on both editors?
e.g.
var editor1 = monaco.editor.create(...);
var editor2 = monaco.editor.create(...);
...
editor1.updateOptions({ theme: ... });
editor2.updateOptions({ theme: ... });
fzafiroski commented on Jan 25, 2017
It is possible and that's the only way to do it in the current state, but that could add some unnecessary code.
What I wanted to say is that changing theme on one editor should either affect all the editors in the same way as the editor we changed theme on, or not affect them at all. This way, it just makes some changes to other editors which makes the text in them unreadable.
So I think this is more of a bug than a feature-request.
waltonseymour commented on Feb 28, 2017
Why is not possible to have multiple editors of different themes?
jrshust commented on Feb 28, 2017
-1 to Changing theme in one editor should change all editors
This is counter intuitive as the create editor function leads one to believe that themes should work on a per editor basis. There are many use cases (I have one right now which is broken) that require having multiple editors on a page styled differently. This also worked fine a few versions ago so not sure why it was changed... I'm interested in why the monaco-token-styles is injected globally as I would be open to working on a PR to fix this if necessary.
43 remaining items
lancejpollard commented on Jan 5, 2024
Geekeren (@geekeren) excited you may have potentially found a solution to this! What is defaultTheme, is that anything special? Also, while your component successfully creates the CSS variables and scopes it, I am getting this:
That is, the style highlighted span elements have a class like mtk20 which is not scoped to monaco-editor or the CSS variables, and it uses that for color. Any ideas what I'm missing or how to get those to change?
Thanks for all the help here!
lancejpollard commented on Jan 5, 2024
Geekeren (@geekeren) also, my theme is defined like this, do I need to define it differently to make this work?
geekeren commented on Jan 21, 2024
Lance Pollard (@lancejpollard) it's unfortunately that the solution is not well solve the grammar highlight. the class name "mk-xxx" is dynamic generated differently in different theme.
geekeren commented on Jan 21, 2024
Lance Pollard (@lancejpollard) the defaultTheme in my code is vs theme, or vs-dark theme, I just keep the two monaco editors' base theme is same. if they are different, the class name "mk-xxx" will be confilict
lancejpollard commented on Jan 22, 2024
Dang, didn't know if mk-xxx was dynamic or fixed, anyhow, here is what I landed on that works for my limited theme choice:
lancejpollard commented on Jan 22, 2024
In another thought, because Sandpack does not use Monaco (it uses CodeMirror it looks like, because CodeMirror works better on mobile it sounds like), I might switch to using CodeMirror so I only have one technology in the app, if I chose to use Sandpack one of these days for something else too.
studylss commented on Sep 5, 2024
Any updates on the issue?
GoncaloCamaz commented on Sep 19, 2024
I have run into the same issue here. In my case, I have a list component where, each list item is an expandable card with editors. That particular editor has a specific style because its wrapped by the expandable card. To add list items I have a modal where i need to have another code editor instance. However, since my modal styles are different, the colors do not match so I need another style. My problem was that since the styles are different, every time I opened the modal, the global styles were changed and then, every editor on the page had the style of the modal.
I fixed this issue by using the global keyword in my scss file. I did it like so:
.CodeEditorWrapper { // other styles from the wrapper :global { .monaco-editor { --vscode-editor-background: #{#121212}; --vscode-editorGutter-background: #{#2a2a2a}; } } }Please also note that I am using scss modules, so, even if I have another instances of CodeEditorWrapper with other styles, this will still work be conscious that this might not work with simple css.
calvinusesyourcode commented on Nov 27, 2024
Bumping because I'm trying to solve a problem where a new editor instance causes all editors to revert back to the default theme, even though I have already called monaco.editor.defineTheme(themeName, themeData) and monaco.editor.setTheme(themeName) long before.
Partial solution is to call editor.updateOptions({ theme: currentMonacoTheme }) during the provided onMount callback, but this still leaves a momentarily flash of the ugly default white theme.
EDIT: Solved my flashing issue! The trick here, at least for @monaco-editor/react is to include the current theme in the JSX options like so as the theme:
EDIT2: It still flashes un-syntax-highlighted code but I think this is good enough for me for now.
ElenaStoeva commented on Jan 16, 2025
It doesn't help unfortunately as Monaco would still use the same CSS variable names for all editors.
The workaround that we used was ensuring that each editor's language has unique token names so they don't overlap. It seems that for each theme rule for a specific token, Monaco creates a unique CSS variable. So for example, if you want the comments in one editor to be one color and in another editor another color, you need to give them unique token names (e.g. comment.lang1, comment.lang2, etc) and make theme rules for each of them accordingly. But if something should have the same color in all editors, it's okay to have a common token name for all of them.
Regarding the theme editor colors (e.g. editor.foreground), that unfortunately can't be solved with the above approach and all editors would need to have the same colors, which luckily worked for our use case.
shanhexi commented on Feb 21, 2025
It was created on January 24th, 2017, and a total of 2,950 days have passed until February 21st, 2025. I can hardly believe that there still hasn't been a good solution for it.
Serpentarius13 commented on Jun 12, 2025
Can we generate a prefix for classes that are used inside the editor to make them local instead of global? For example with some prop to generate unique classes?
`frontend`: Make `ReadOnlyCodeViewer` respond to theme changes. Howev…
`frontend` Solve theming conflicts between `mermaid` and `vs` light t…
MyMaNong commented on Jan 16, 2026
Is there a solution to this problem?