Line height
The line height feature lets you adjust the vertical spacing between lines of text, controlling how tightly or loosely text is packed within paragraphs. This feature is essential for document formatting, helping users create professional-looking content with proper typography spacing.
Select content and change the line height using the toolbar button
. Please note that the feature can only be applied to whole blocks of content such as paragraphs, tables or lists.Line Height Feature
This is a paragraph with default line height. Select this text and use the line height dropdown in the toolbar to change it.
This is another paragraph to test the line height feature. Try applying different line heights to see the difference.
Multiple paragraphs with different styles
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus nec metus ut elit vestibulum pellentesque. Nullam eget nisi vel neque egestas congue ac quis mauris.
This is a blockquote. Line height can be applied to this element as well.
- List item 1 - You can apply line height to individual list items
- List item 2 - Or select multiple list items at once
- List item 3 - To apply the same line height to all of them
After installing the editor, add the feature to your plugin list and toolbar configuration:
import { ClassicEditor } from 'ckeditor5';
import { LineHeight } from 'ckeditor5-premium-features';
ClassicEditor
.create( document.querySelector( '#editor' ), {
licenseKey: '<YOUR_LICENSE_KEY>',
plugins: [ LineHeight, /* ... */ ],
toolbar: [ 'lineHeight', /* ... */ ],
lineHeight: {
// Configuration.
}
} )
.then( /* ... */ )
.catch( /* ... */ );
Read more about installing plugins and toolbar configuration.
To use this premium feature, you need to activate it with proper credentials. Refer to the License key and activation guide for details.
The line height feature provides the following predefined values as options in the dropdown:
1
1.15
'default'
2
2.5
3
While rendering the UI layer, the 'default'
option is replaced with a value determined by the editor’s configuration. By default, the line-height
value is 1.5
, but you can change this by updating the configuration and content styles. The other values are multipliers of the default one.
-
Using a CSS variable in the editor’s content styles:
:root { --ck-content-line-height: 1.65; }
-
Setting a default value in the editor configuration:
lineHeight: { defaultValue: 1.65 }
The config.lineHeight.defaultValue
should be synchronized with the editor content styles.
The line height feature defines 2 named presets:
'single'
'double'
Each size assigns a corresponding class to a block element. For example, the 'double'
preset looks as follows in the editor data:
<p class="line-height-double">...</p>
The CSS definition for these classes (presets) must be included in the web page styles where the edited content is rendered.
Here is an example of the line height CSS classes:
.ck-content .line-height-single {
line-height: 1;
}
.ck-content .line-height-double {
line-height: 2;
}
An example of an editor that supports more line height sizes:
ClassicEditor
.create( document.querySelector( '#editor' ), {
// ... Other configuration options ...
lineHeight: {
options: [
'single',
'default',
'double',
{
title: 'Triple', // A name displayed in the dropdown UI.
model: 'triple', // A value used in the command and stored in the model.
view: {
key: 'class',
value: 'line-height-triple'
}
}
]
},
toolbar: [
'heading', 'bulletedList', 'numberedList', 'lineHeight', 'undo', 'redo'
]
} )
.then( /* ... */ )
.catch( /* ... */ );
.ck-content .line-height-triple {
line-height: 3;
}
This is a paragraph with triple line height.
And so is this one.
The line height feature also supports numerical values.
In this case, each size adds the style
attribute to the block element, which sets the line-height
CSS property. For example, a line height of 2
will be represented in the editor data as:
<p style="line-height: 2">...</p>
Here is an example of a WYSIWYG editor that supports numerical line heights. Note that 'default'
(1.5
) is controlled by the default styles of the web page:
ClassicEditor
.create( document.querySelector( '#editor' ), {
// ... Other configuration options ...
lineHeight: {
options: [
0.5,
1,
'default', // This will be replaced with the default value (1.5).
1.65,
2,
2.5,
3
]
},
toolbar: [
'heading', 'bulletedList', 'numberedList', 'lineHeight', 'undo', 'redo'
]
} )
.then( /* ... */ )
.catch( /* ... */ );
This is a paragraph with the line-height: 0.5
definition of style. Select this text and use the line height dropdown in the toolbar to change it.
This is a paragraph with the line-height: 1
definition of style. Select this text and use the line height dropdown in the toolbar to change it.
This is a paragraph with the line-height: 1.65
definition of style. Select this text and use the line height dropdown in the toolbar to change it.
This is a paragraph with the line-height: 2.5
definition of style. Select this text and use the line height dropdown in the toolbar to change it.
The line height feature automatically converts percentage-based values (for example, 100%
) into unitless numeric equivalents (such as 1
) to ensure consistency with CSS standards and editor rendering behavior.
By default, all line-height
values that are not specified in the config.lineHeight.options
are stripped. You can enable support for all line heights by using the config.lineHeight.supportAllValues
option.
ClassicEditor
.create( document.querySelector( '#editor' ), {
// ... Other configuration options ...
lineHeight: {
options: [
// Numerical values.
// ...
],
supportAllValues: true
},
// More of editor's configuration.
// ...
} )
.then( /* ... */ )
.catch( /* ... */ );
This paragraph uses line-height: 1.75
, which isn't one of the default values in the dropdown.
Select this text and open the line height dropdown in the toolbar - you will see a Custom: 1.75 option reflecting the applied value.
This option can be used only in combination with numerical values.
Check out also these CKEditor 5 features to gain better control over your content style and format:
- Font styles – Easily and efficiently control the font family, size, text or background color.
- Text alignment – Because it does matter whether the content is left, right, centered, or justified.
- Block indentation – Organize your content into visually separated blocks, indent crucial paragraphs, etc.
- Remove format – Easily clean basic text formatting.
The LineHeight
plugin registers:
-
The
'lineHeight'
dropdown. -
The
'lineHeight'
command.The number of options and their names correspond to the
config.lineHeight.options
configuration option.You can change the line height of the current selection by executing the command with a desired value:
// For numerical values: editor.execute( 'lineHeight', { value: 2 } ); // For named presets: editor.execute( 'lineHeight', { value: 'double' } );
Passing an empty value will remove any
config.lineHeight
set:editor.execute( 'lineHeight' );