Contribute to this guide

guideHTML comment element

By default, the editor filters out all HTML comments on initialization. The HtmlComment feature lets developers keep HTML comments in the document without displaying them to the user.

The HTML comments feature is experimental and not yet production-ready.

The support for HTML comments is at the basic level so far - see the known issues section below.

# Demo

The editor below is configured to keep HTML comments in the document content. You can view the source of the document using the source editing feature. Toggle the source editing mode Source editing to see there is an HTML comment in the document source. Try uncommenting the paragraph below the picture. Once you leave the source editing mode, you will see this paragraph in the editable area.

The great things you learn from traveling

A lone wanderer looking at Mount Bromo volcano in Indonesia.

Appreciation of diversity

Getting used to an entirely different culture can be challenging. While it’s also nice to learn about cultures online or from books, nothing comes close to experiencing cultural diversity in person. You learn to appreciate each and every single one of the differences while you become more culturally fluid.

# Installation

This feature is enabled by default in the superbuild only.

To add this feature to your rich-text editor, install the @ckeditor/ckeditor5-html-support package:

npm install --save @ckeditor/ckeditor5-html-support

Then add it to the editor configuration:

import { HtmlComment } from '@ckeditor/ckeditor5-html-support';

    .create( document.querySelector( '#editor' ), {
        plugins: [ HtmlComment, ... ],
    } )
    .then( ... )
    .catch( ... );

Read more about installing plugins.

HTML comment feature does not require any configuration.

# Known issues

The main issue with the HTML comments feature is that comments can be easily repositioned or lost in various cases #10118, #10119. Also copying and pasting (or dragging and dropping) elements containing HTML comments within the editor does not work as expected #10127.

We are open for feedback, so if you find any issue, feel free to report it in the main CKEditor 5 repository.

CKEditor 5 has other features related to HTML editing you may want to check:

  • Source editing – Provides the ability for viewing and editing the source of the document. When paired, these two plugins let the user gain powerful control over the content editing.
  • HTML embed – Allows embedding an arbitrary HTML snippet in the editor. It is a more constrained and controllable approach to arbitrary HTML than GHS.

# Contribute

The source code of the feature is available on GitHub at