Duplicated CSS while multi page creation
This is intentional and I'm not planning to change this behaviour as you can easily create specific CSS selectors if you need different styles per page. The big benefit of this approach is to allow reusing selectors across pages.
Read full answer below ↓Question
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
Chrome latest
Reproducible demo link
https://codesandbox.io/s/withered-bush-wv29dx?file=/index.js
Describe the bug
How to reproduce the bug?
- ... create multi pages in grapesjs.init()
- ... check the styles of each page
What is the expected behavior? every page contains there own style not include the CSS of other pages ...
What is the current behavior? currently the CSS of all pages will merged and apply on all pages. for more details visit the reproduction link and check the code of all pages ...
If is necessary to execute some code in order to reproduce the bug, paste it here below:
// simple code for demonstration
import grapesjs from "grapesjs";
import "grapesjs-blocks-basic";
const paperCode = [
{
css: "p{color:red}",
html: "<p>first page</p>"
},
{
css: "p{color:blue}",
html: "<p>second page</p>"
},
{
css: "p{color:green}",
html: "<p>third page</p>"
}
];
const editor = grapesjs.init({
container: "#gjs",
fromElement: 1,
storageManager: { type: 0 },
plugins: ["gjs-blocks-basic"],
pageManager: {
pages: paperCode.map((page, index) => {
return {
name: `page ${index + 1}`,
id: `${index + 1}`,
styles: page.css,
component: page.html
};
})
}
});
editor.Pages.select("1"); // in order to see other pages, change the value from 1 to 3. eg, "1", "2", "3"
Code of Conduct
- I agree to follow this project's Code of Conduct
Answers (3)
This is intentional and I'm not planning to change this behaviour as you can easily create specific CSS selectors if you need different styles per page. The big benefit of this approach is to allow reusing selectors across pages.
I think I'm experiencing an issue with this approach. I'm saving the pages to server like this:
const component = page.getMainComponent();
const css = editor.getCss({ component, avoidProtected: true })
saveToBackendApi(component,css)
and loading them like this in a loop:
const page = pageManager.add({
name: pageName,
component: pageHtml || `<div> ${pageName} </div>`,
styles:css,
});
The css rules targeting ids are working fine, but the rules with a class are duplicating even when loaded in separate pages.
For instance the # of css rules for .gjs-row class keeps increasing after after each save + load.
Thanks for reporting this, @gxanshu.
Great question about Duplicated CSS while multi page creation. 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 #6685
Custom component styles are not applied after deletion and re-addition
GrapesJS version [x] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v143.0.7499.193 Reproducible demo l...
Issue #4572
Page update event doesn't fire
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? chrome Reproducible demo link https://jsfi...
Issue #5019
Can't set preview mode on editor init when using loadProjectData()
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v111 Reproducible demo link https:/...
Issue #4900
setStyle/getCss() produces duplicated css
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? Chrome LatestReproducible demo link https://...
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.