Issue #3116💬 AnsweredOpened November 6, 2020by aadilmehrajbhat1 reactions

How to load css that can viewed in code viewer and also exported while saving

快速解答by artf1

@AadilMehrajBhat First of all, display: 'block' is not a valid CSS value for that property (it should be display: block) and then .d-block is not used anywhere in your template so the result is automatically optimized by removing unused styles

Read full answer below ↓

Question

Hi :wave:

I am trying to load some CSS within the editor as part of the theme, I am able to link stylesheets as part of loading but the problem that I am facing is when loading the styles directly using <style> tag, I am able to view the serialized version via editor.getStyle() but editor.getCss() only contains the protectedCss.

I am confused about how the CSS styles are added within the template style css property when exporting or viewing within code viewer, also how to manipulate the CSS rules that are not component specific but generally.

I tried to dig more in the docs especially inCssComposer and CssRule but unfortunately couldn't find much luck there.

I have added a codepen link to demonstrate the issue I am facing. https://codepen.io/aadilmehrajbhat/pen/GRqBdQY

Thanks

Answers (2)

artfNovember 9, 2020

@AadilMehrajBhat First of all, display: 'block' is not a valid CSS value for that property (it should be display: block) and then .d-block is not used anywhere in your template so the result is automatically optimized by removing unused styles

ClaudeCodeMay 17, 2026

Thanks for reporting this, @aadilmehrajbhat.

Great question about [HELP WANTED] How to load css that can viewed in code viewer and also exported while saving. The recommended approach with StyleManager is to use the event-driven API.

Start here:

  1. Check the GrapesJS documentation for your specific module
  2. Look for the on() event listener method
  3. 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.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.