Sign up (with export icon)

Content styles

Contribute to this guideShow the table of contents

We distribute CKEditor 5 with two types of styles:

  • Editor styles for the editor’s user interface – see the Editor styles guide.
  • Content styles for the content inside the editor – covered in this guide.

If you went through our Quick start, you probably noticed that attaching the styles in JavaScript is pretty standard, and we provide CSS style sheets that have both the editor and content styles combined. There are separate styles for open-source and premium features:

import 'ckeditor5/ckeditor5.css';

import 'ckeditor5-premium-features/ckeditor5-premium-features.css';
Copy code

It is as easy in HTML if you decide to use our CDN:

<link rel="stylesheet" href="https://cdn.ckeditor.com/ckeditor5/49.1.0/ckeditor5.css" />

<link rel="stylesheet" href="https://cdn.ckeditor.com/ckeditor5-premium-features/49.1.0/ckeditor5-premium-features.css" />
Copy code

Why do I need content styles?

Copy link

Some core editor features bring additional CSS to control the look of the content they produce. One such example is the image feature, which requires special content styles to render images and their captions within the content. Another would be the block quote feature that displays quotes in italics with a subtle border on the side. You can see both of these pictured below.

Editor content styles.

Customizing content styles

Copy link

Content inside the editor is styled with native CSS variables, so you can adjust its look without touching the source styles.

Note

If the editor runs inside a shadow root, load the style sheets into that root and override the variables on the shadow host instead of :root. See the Shadow DOM guide for details.

General content styling

Copy link

CKEditor 5 provides CSS variables to standardize font and line height styling across the content. These variables control the default appearance of text in the content. You can override them in the following way:

:root {
	/* Override the default font family */
	--ck-content-font-family: "Roboto";

	/* Override the default font size */
	--ck-content-font-size: 16px;

	/* Override the default font color */
	--ck-content-font-color: hsl(225, 5%, 45.00%);

	/* Override the default line height */
	--ck-content-line-height: 2;
}
Copy code

The general content CSS variables are listed in the table below. Each defaults to the value shown.

Variable Controls Default
--ck-content-font-familyContent font familyHelvetica, Arial, Tahoma, Verdana, Sans-Serif
--ck-content-font-sizeContent font sizemedium
--ck-content-font-colorContent text color#000
--ck-content-line-heightContent line height1.5
--ck-content-word-breakWord breakingnormal
--ck-content-overflow-wrapWrapping of long wordsbreak-word

Feature-specific styling

Copy link

Individual features also provide CSS variables for their specific styling needs. For example, to recolor the mentions’ background and text:

:root {
	--ck-content-mention-background: black;
	--ck-content-mention-text-color: white;
}
Copy code

The content CSS variables are grouped by feature in the table below. Each defaults to the value shown; override it on :root (or on the shadow host when using the Shadow DOM) to restyle the published content.

Variable Controls Default
Block quote
--ck-content-block-quote-border-colorSide border colorhsl(213, 40%, 90%)
--ck-content-block-quote-border-widthSide border thickness5px
--ck-content-block-quote-border-styleSide border stylesolid
Code block
--ck-content-code-block-text-colorText colorhsl(0, 0%, 20.8%)
--ck-content-code-block-backgroundBackgroundhsl(0, 0%, 96%)
--ck-content-code-block-border-colorBorder colorhsl(213, 40%, 90.2%)
--ck-content-code-block-border-widthBorder thickness1px
--ck-content-code-block-border-styleBorder stylesolid
--ck-content-code-block-border-radiusCorner radius2px
Inline code
--ck-content-inline-code-background-colorBackgroundhsla(0, 0%, 78%, 0.3)
Font size
--ck-content-font-size-tiny"Tiny" font size0.7em
--ck-content-font-size-small"Small" font size0.85em
--ck-content-font-size-big"Big" font size1.4em
--ck-content-font-size-huge"Huge" font size1.8em
Horizontal line
--ck-content-horizontal-line-backgroundLine colorhsl(213, 40%, 90.2%)
Image
--ck-content-image-caption-background-colorCaption backgroundhsl(0, 0%, 97%)
--ck-content-image-caption-text-colorCaption text colorhsl(0, 0%, 20%)
--ck-content-image-style-spacingSpacing around styled block images1.5em
--ck-content-inline-image-style-spacingSpacing around styled inline imagescalc(var(--ck-content-image-style-spacing) / 2)
Media embed
--ck-content-media-style-spacingSpacing around styled media1.5em
Table
--ck-content-table-border-colorOuter border colorhsl(0, 0%, 70%)
--ck-content-table-border-widthOuter border thickness1px
--ck-content-table-border-styleOuter border styledouble
--ck-content-table-cell-border-colorCell border colorhsl(0, 0%, 75%)
--ck-content-table-cell-border-widthCell border thickness1px
--ck-content-table-cell-border-styleCell border stylesolid
--ck-content-table-header-backgroundHeader cell backgroundhsla(0, 0%, 0%, 5%)
--ck-content-table-caption-background-colorCaption backgroundhsl(0, 0%, 97%)
--ck-content-table-caption-text-colorCaption text colorhsl(0, 0%, 20%)
--ck-content-table-style-spacingSpacing around styled tables1.5em
Mention
--ck-content-mention-backgroundMention backgroundhsla(341, 100%, 30%, 0.1)
--ck-content-mention-text-colorMention text colorhsl(341, 100%, 30%)
Highlight
--ck-content-highlight-marker-yellowYellow markerhsl(60, 97%, 73%)
--ck-content-highlight-marker-greenGreen markerhsl(120, 93%, 68%)
--ck-content-highlight-marker-pinkPink markerhsl(345, 96%, 73%)
--ck-content-highlight-marker-blueBlue markerhsl(201, 97%, 72%)
--ck-content-highlight-pen-redRed penhsl(0, 85%, 49%)
--ck-content-highlight-pen-greenGreen penhsl(112, 100%, 27%)
Page break
--ck-content-page-break-line-colorLine colorhsl(0, 0%, 77%)
--ck-content-page-break-line-widthLine thickness2px
--ck-content-page-break-line-styleLine styledashed
--ck-content-page-break-label-text-colorLabel text colorhsl(0, 0%, 20%)
--ck-content-page-break-label-backgroundLabel backgroundhsl(0, 0%, 100%)
--ck-content-page-break-label-border-colorLabel border colorhsl(0, 0%, 77%)
--ck-content-page-break-label-border-widthLabel border thickness1px
--ck-content-page-break-label-border-styleLabel border stylesolid
--ck-content-page-break-label-shadow-colorLabel shadow colorhsla(0, 0%, 0%, 0.15)
To-do list
--ck-content-todo-list-checkmark-sizeCheckbox size16px
--ck-content-todo-list-checkmark-border-colorCheckbox border colorhsl(0, 0%, 20%)
--ck-content-todo-list-checkmark-checked-backgroundChecked backgroundhsl(126, 64%, 41%)
--ck-content-todo-list-checkmark-checked-border-colorChecked border colorhsl(126, 64%, 41%)
--ck-content-todo-list-checkmark-tick-border-colorTick mark colorhsl(0, 0%, 100%)
List marker
--ck-content-list-marker-colorMarker colorvar(--ck-content-font-color)
--ck-content-list-marker-font-familyMarker font familyvar(--ck-content-font-family)
--ck-content-list-marker-font-sizeMarker font sizevar(--ck-content-font-size)
Note

The table caption, image caption, and mention variables were renamed in v49.x to follow a single naming convention. The former --ck-content-color-table-caption-*, --ck-content-color-image-caption-*, and --ck-content-color-mention-* names still work as fallbacks but are deprecated. See the Update to v49.x guide.

The defaults of these renamed variables are still declared under the former names, so the new names work as override points only. If your own CSS reads one of them with var() and you have not set it, the value is empty. Set the variable first, or read the former name to get the default.

Styling the published content

Copy link

Your application is typically divided into two areas. Content creation, which hosts the editor and is a writing tool, and content publishing, which presents the written content.

It is important to use the content styles on the publishing side of your application. Otherwise, the content will look different in the editor and for your end users.

There are two ways to obtain the content styles:

  • From the npm packages, in the dist/ckeditor5-content.css and ckeditor5-premium-features-content.css location.
  • From our CDN, https://cdn.ckeditor.com/ckeditor5/

Below is an example with placeholder paths showing how to load the ckeditor5-content.css (and ckeditor5-premium-features-content.css, if needed) file on the publishing side.

<link rel="stylesheet" href="path/to/assets/ckeditor5-content.css">

<link rel="stylesheet" href="path/to/assets/ckeditor5-premium-features-content.css">

<link rel="stylesheet" href="path/to/assets/styles.css">
Copy code

The final setup depends on how your application is structured. As mentioned earlier, you can use our CDN, or your JS bundler already creates and serves combined style sheets. Choose the solution that works best for your case.

Optimizing the size of style sheets

Copy link

The ckeditor5 package distributes three style sheets:

  • ckeditor5.css – combined editor and content styles,
  • ckeditor5-content.css – only content styles,
  • ckeditor5-editor.css – only editor styles.

The same is true for the ckeditor5-premium-features package, but the filenames are different:

  • ckeditor5-premium-features.css – combined editor and content styles,
  • ckeditor5-premium-features-content.css – only content styles,
  • ckeditor5-premium-features-editor.css – only editor styles.

However, these style sheets include styles for all editor plugins. If you want to optimize the size of the style sheet, to only include styles for the plugins you use, you can follow the Optimizing build size guide.