Unnecessary Canvas style
it is intended to store canvas styles, styles that do not affect the result of hmtl/css, styles that will not be exported, right? Correctby default the body has a white background, this seems to be the default color in all browsers, no? yeah but the iframe body doesn't have any default background color that's why that...
Read full answer below βQuestion
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
Arc Version 1.35.0 / Chromium Engine 123.0
Reproducible demo link
https://grapesjs.com/demo.html
Describe the bug
My special case:
In my case, all styles from plugins and general styles are located in the header. So, to achieve similar behavior in the editor, I add these styles to the Canvas head. And when I specify the background color in my general styles, it is overridden by the GJS Canvas styles. This obliges me to specify the !important rule, which I don't want to do.
I'm guessing this shouldn't be a rare case, even if there is no built-in mechanism for managing the contents of the Canvas head.
How to reproduce the bug?
- Go to https://grapesjs.com/demo.html
- Run the following code in the console(DevTools)
const style = document.createElement('style');
style.innerHTML = 'body { background-color: black; }';
editor.Canvas.getDocument().head.insertAdjacentElement('beforeend', style);
What is the expected behavior? GJS styles in the canvas should not affect body styles unless the body is selected or highlighted by the editor.
What is the current behavior? Defines body background-color.
Code of Conduct
- I agree to follow this project's Code of Conduct
Answers (4)
it is intended to store canvas styles, styles that do not affect the result of hmtl/css, styles that will not be exported, right?
Correct
by default the body has a white background, this seems to be the default color in all browsers, no?
yeah but the iframe body doesn't have any default background color that's why that style is there, so you'll need to figure it something for your use case.
There is canvasCss option for that.
Next time open a Discussion please, as this is not a core bug but wrong usage.
Hey @artf. Thanks for the answer. I'm not sure that we understood each other and I would like to clarify one detail.
Yes, I know about the canvasCss property, moreover, I use it to change the styles of the selected component. I understand the essence of the property: it is intended to store canvas styles, styles that do not affect the result of hmtl/css, styles that will not be exported, right?
Then why do the default canvas styles have this CSS rule body { background-color: white; } ? And why it makes sense us to override it?
I understand the case where the body element is selected, in which case it makes sense to apply some styles to the body for interactivity.
But why specify body {background-color: white; } by default, it doesnβt affect the interactivity of the editor?
Moreover, by default the body has a white background, this seems to be the default color in all browsers, no?
This is kind of unexpected behavior that requires me to apply !important to my exported style so that I can override the styles from canvasCss.
Thanks for reporting this, @ctrhub.
Great question about Unnecessary Canvas style. The recommended approach with StyleManager is to use the event-driven API.
Start here:
- Check the GrapesJS documentation for your specific module
- Look for the
on()event listener method - Most operations can be achieved by listening to editor and component events
Common patterns:
// Listen for changes
editor.on('change', () => console.log('something changed'));
// Component lifecycle
editor.on('component:mount', (c) => console.log('component ready', c));
editor.on('component:update', (c) => console.log('component updated', c));
If you're still stuck:
- Share a minimal CodeSandbox reproduction
- Include what you've already tried
- Mention your GrapesJS version
- The community is here to help!
Related Questions and Answers
Continue research with similar issue discussions.
Issue #4208
Style click state bug in every element
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Brave Last, tested on chrome last and Safa...
Issue #6663
Symbols break when loading pages progressively (instances lose __symbol link)
Here is a video showing the bug: https://github.com/user-attachments/assets/0fdc76ed-cee5-4481-98b1-cbbf52572b31 GrapesJS version [x] I con...
Issue #6549
Couldnt Resize image
GrapesJS version [x] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Reproducible demo link https://code...
Issue #6248
showOffsets bug when iframe body has zoom
GrapesJS version [x] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Reproducible demo link https://jsfi...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins βPremium plugins ship with support, regular updates, and production-ready features β save days of integration work.
Browse premium plugins βRelated tutorials
In-depth guides on the same topic.
Tutorial
Find the Right GrapesJS Plugin in Seconds: Smarter Discovery Is Live
We're shipping a set of discovery upgrades. New label filters, a proper compatibility switch for GrapesJS vs Studio, one-click and a smarter sort bar.
Tutorial
GrapesJS vs Webflow vs Tilda: What to Choose for Your Business in 2026
Choosing the right website platform in 2026 is no longer just about building a site
Tutorial
GJS Market 2.0 - Donations, Tracking, Labels and Better Product Discovery
Weβve rolled out a new set of GrapesJS marketplace updates across GJS Market, focused on improving how creators distribute products
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.