Issue #3119💬 AnsweredOpened November 6, 2020by makkaronis4e0 reactions

How to create custom block made of grapesjs components?

快速解答by artf

You should be able to do something like this:

Read full answer below ↓

Question

Hi, i want to have custom blocks made of grapesjs components.

I found solution how to add components: https://github.com/artf/grapesjs/issues/1334#issuecomment-411519845 but i'm struggling with adding CSS (eaiher as string or as object).

Answers (4)

artfNovember 9, 2020

You should be able to do something like this:

...
components: [
  { tagName: 'h1', components: 'Some <b>content</b>', },
  '<style>....</style>'
]
makkaronis4eNovember 9, 2020

@artf thanks it works, but i found bug there.

When you drop this block on canvas it works ok, but if you delete this element from canvas or clear whole canvas, then drop this block on canvas 2nd time, it will lose css. 2nd time, 3rd time.. doesnt matter, If you removed element from canvas once, it will lose style for next drops.

artfNovember 18, 2020

@makkaronis4e for such a case, I'd ask you a reproducible demo, please

ClaudeCodeMay 17, 2026

Thanks for reporting this, @makkaronis4e.

Great question about [QUESTION] How to create custom block made of grapesjs components?. 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 →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.