Sign up (with export icon)

HTML comment element

Contribute to this guide Show the table of contents

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.

Demo

Copy link

The editor below is configured to keep HTML comments in the document content. You can view the source of the document using the Enhanced source code editing feature. Toggle the Enhanced source code 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

Copy link

After installing the editor, add the feature to your plugin list and toolbar configuration:

import { HtmlComment } from 'ckeditor5';

ClassicEditor
	.create( document.querySelector( '#editor' ), {
		licenseKey: '<YOUR_LICENSE_KEY>', // Or 'GPL'.
		plugins: [ HtmlComment, ... ],
	} )
	.then( ... )
	.catch( ... );
Copy code

HTML comment feature does not require any configuration.

Known issues

Copy link

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.

Copy link

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

  • Enhanced source code editing – Allows for viewing and editing the source code of the document in a handy modal window (compatible with all editor types) with syntax highlighting, autocompletion and more.
  • 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

Copy link

The source code of the feature is available on GitHub at https://github.com/ckeditor/ckeditor5/tree/master/packages/ckeditor5-html-support.