GrapesJS Web Builder Framework

0.22.15 · active · verified Sun Apr 19

GrapesJS is a free and open-source Web Builder Framework designed to facilitate the creation of HTML templates, websites, newsletters, and mobile applications. It's primarily intended for integration into Content Management Systems (CMS) to provide a powerful visual editing experience. The current stable version is `0.22.15`, with the project demonstrating a positive and sustainable release cadence, frequently publishing patch releases. Key differentiators include its framework-centric approach, offering core UI components like a Block Manager, Style Manager, Layer Manager, Code Viewer, and Asset Manager. It focuses on generating clean, standards-based HTML and CSS output, unlike some other tools that might rely on specific frontend frameworks.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes a GrapesJS editor in a designated DOM element, configures local storage for persistence, and adds a few basic draggable blocks (section, text, image). It also includes basic panel configurations and logs the generated HTML and CSS on content updates.

import grapesjs from 'grapesjs';
import 'grapesjs/dist/css/grapes.min.css';

// Ensure a DOM element exists for the editor
document.body.innerHTML = '<div id="gjs"></div>';

const editor = grapesjs.init({
  container: '#gjs',
  height: '700px',
  width: 'auto',
  fromElement: true, // Loads HTML from the container element
  storageManager: {
    type: 'local', // Use local storage
    autosave: true, // Autosave content
    autoload: true, // Autoload content on editor init
    stepsBeforeSave: 1, // Number of changes before autosave
  },
  // Add some basic blocks
  blockManager: {
    blocks: [
      {
        id: 'section', // id is a unique and required property
        label: '<b>Section</b>', // You can use HTML for the label
        category: 'Basic',
        content: '<section><h1>This is a section</h1></section>',
      },
      {
        id: 'text',
        label: 'Text',
        category: 'Basic',
        content: '<div data-gjs-type="text">Insert your text here</div>',
      },
      {
        id: 'image',
        label: 'Image',
        category: 'Basic',
        activate: true,
        select: true,
        content: { type: 'image' },
      }
    ],
  },
  // Configure the panels (optional)
  panels: {
    defaults: [
      { id: 'commands', buttons: [{ id: 'undo', command: 'undo' }, { id: 'redo', command: 'redo' }] },
      { id: 'options', buttons: [{ id: 'sw-visibility', command: 'sw-visibility', context: 'sw-visibility' }] },
      { id: 'views', buttons: [{ id: 'open-blocks', command: 'open-blocks', active: true }] }
    ]
  },
});

// Log the HTML and CSS when the editor changes
editor.on('update', () => {
  console.log('HTML:', editor.getHtml());
  console.log('CSS:', editor.getCss());
});

console.log('GrapesJS Editor initialized successfully.');

view raw JSON →