Issue #6502πŸ’¬ AnsweredOpened April 25, 2025by jsxOverdose0 reactions

Inline style overrides ID-based CSS rules

Quick answerby artf

Thanks for the report @jsxOverdose Will be fixed in the next release

Read full answer below ↓

Question

GrapesJS version

  • I confirm to use the latest version of GrapesJS

What browser are you using?

Chrome v135.0.7049.96

Reproducible demo link

https://jsfiddle.net/bqkLwt8j/

Describe the bug

When an element has an inline style and also matches an ID-based CSS rule, the styles from the ID selector are removed - even if the inline style doesn’t override those properties. However, this issue does not occur with class-based CSS rules, which behave as expected.

How to reproduce the bug?

  1. Add a CSS rule for a specific ID, e.g. #frame2 { color: red; }
  2. Add an element with that ID and an inline style, e.g. <div id="frame" style="font-size: 14px;">
  3. Observe that the color is no longer applied from the CSS rule, despite not being overridden.

What is the expected behavior? An inline style should only override conflicting properties explicitly set in the inline style. Other styles (e.g., from ID-based selectors) should remain intact and apply as expected.

For example:

<style>
  #test {
    color: red;
    font-weight: bold;
  }
</style>

<div id="test" style="font-weight: normal;">Hello</div>

The expected result is:

  • color: red should still apply from the ID-based rule.
  • font-weight: normal should override the ID rule for font-weight.

What is the current behavior? The entire set of styles defined in the ID selector (e.g., #test { ... }) is disregarded as soon as an inline style is added, even if the inline style does not override any of those properties.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Answers (2)

artfβ€’ May 16, 2025

Thanks for the report @jsxOverdose Will be fixed in the next release

ClaudeCodeβ€’ May 17, 2026

Thanks for reporting this, @jsxOverdose.

Great question about Inline style overrides ID-based CSS rules. 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.