diff --git a/core/modules/ckeditor5/css/editor.css b/core/modules/ckeditor5/css/editor.css
index 5c28250f97..bac24a8608 100644
--- a/core/modules/ckeditor5/css/editor.css
+++ b/core/modules/ckeditor5/css/editor.css
@@ -8,3 +8,14 @@
opacity: 1 !important;
fill-opacity: 1 !important;
}
+
+/**
+ * Set the min-height equal to configuration value for the number of rows.
+ *
+ * The `--ck-min-height` value is set on the parent `.ck-editor` element by
+ * JavaScript. We add that there because the `.ck-editor__editable` element's
+ * inline styles are cleared on focus.
+ */
+.ck-editor__editable {
+ min-height: var(--ck-min-height);
+}
diff --git a/core/modules/ckeditor5/js/ckeditor5.js b/core/modules/ckeditor5/js/ckeditor5.js
index 0dfd4f1285..ad2d7ccb6a 100644
--- a/core/modules/ckeditor5/js/ckeditor5.js
+++ b/core/modules/ckeditor5/js/ckeditor5.js
@@ -370,9 +370,37 @@
ClassicEditor.create(element, editorConfig)
.then((editor) => {
+ /**
+ * Injects a temporary
into the CKeditor and returns its height.
+ *
+ * @returns {number} - the height of a div in pixels.
+ */
+ function calculateLineHeight() {
+ const element = document.createElement('div');
+ element.setAttribute('style', 'visibility: hidden;');
+ element.innerHTML = ' ';
+ editor.ui.view.editable.element.append(element);
+ const height = element.clientHeight;
+ element.remove();
+ return height;
+ }
+
// Save a reference to the initialized instance.
Drupal.CKEditor5Instances.set(id, editor);
+ // Set the minimum height of the editable area to correspond with the
+ // user inputted value of number of rows. We attach this custom property
+ // to the `.ck-editor` element, as that doesn't get its inline styles
+ // cleared on focus. The editable element is then set to use this
+ // property within the stylesheet.
+ const rows = editor.sourceElement.getAttribute('rows');
+ editor.ui.view.editable.element
+ .closest('.ck-editor')
+ .style.setProperty(
+ '--ck-min-height',
+ rows * calculateLineHeight() + 'px',
+ );
+
// CKEditor 4 had a feature to remove the required attribute
// see: https://www.drupal.org/project/drupal/issues/1954968
if (element.hasAttribute('required')) {