Problem/Motivation
In Drupal 10.4.x using CKEditor 5, when applying a border to a table with the following settings:
Color: red (using HSL, e.g., hsl(0, 75%, 60%)),
Style: solid, and Width: 1px,
the visual editor displays the border correctly. However, when switching to source editing,
the generated HTML for the table (and its cells) omits the border-width property.
This causes the published content to not render the expected border.
The generated HTML looks similar to the following:
<table style="border-color:hsl(0, 75%, 60%);border-style:solid;width:100%;"> <tbody> <tr> <td style="border-color:hsl(0, 75%, 60%);width:33%;">a</td> <td style="border-color:hsl(0, 75%, 60%);width:33%;">b</td> <td style="border-color:hsl(0, 75%, 60%);width:33%;">c</td> </tr> <tr> <td style="border-color:hsl(0, 75%, 60%);width:33%;">d</td> <td style="border-color:hsl(0, 75%, 60%);width:33%;">e</td> <td style="border-color:hsl(0, 75%, 60%);width:33%;">f</td> </tr> </tbody> </table>
It can be seen that the border-width: 1px; property is missing, even though it is explicitly set in the visual editor.
This issue does not occur when using other border styles (e.g., "dotted"), which suggests a specific behavior or bug in the handling of a solid border with a width of 1px in CKEditor 5 integrated in Drupal 10.4.x.
Steps to Reproduce
- Install Drupal 10.4.x with CKEditor 5 enabled.
- Create or edit content that contains a table.
- Use the visual editor to apply the following border settings to the table (and its cells):
- Color: red (via HSL, e.g., hsl(0, 75%, 60%))
- Style: solid
- Width: 1px
- Save the content and switch to source editing to inspect the generated HTML.
- Notice that the
styleattribute on the table and its cells does not includeborder-width:1px;. - As a result, the published content does not render the border as expected.
Remaining Tasks
- Investigate the CKEditor 5 table plugin code within Drupal 10.4.x to identify the logic that omits
border-width. - Develop and test a patch that resolves this behavior.
- Verify the solution across different text formats (e.g., Full HTML, Basic HTML) to ensure consistency.
- Update any relevant documentation if necessary.
User Interface Changes
No direct changes have been detected in the user interface; the issue only affects the generated HTML and the rendering of the published content.
Introduced Terminology
No new terminology has been introduced in this issue.
API Changes
No API changes are required. The adjustment is limited to the internal processing of inline styles within the CKEditor 5 table plugin.
Data Model Changes
No changes have been reported in Drupal's data model.
Additional Information
Screenshots:
Before update (Drupal 10.3.9):
Screenshot_1.jpg
After update (Drupal 10.4.x):
Screenshot_2.jpg
| Comment | File | Size | Author |
|---|---|---|---|
| Screenshot_2.jpg | 62.85 KB | jeanbryanx | |
| Screenshot_1.jpg | 60.27 KB | jeanbryanx |
Comments
Comment #2
cilefen commentedAt a glance this seems to be how CKEditor does things, not Drupal. That is: if you pick "Solid" for the border style and "1px" for "Width, CKEditor does not create an attribute mentioning width. CKEditor will do so if you select some other options, like 2px and other styles. But it does so differently. Sometimes CKEditor adds a style for "border", and in other cases it uses the "border-width" style.
It would be good to know:
I am updating some issue metadata according to the project guidelines.
Comment #3
gaddman commentedOn a fresh install of 10.4.7 I see the same behaviour.
Some of the borders are still displayed, but it depends on the theme — with Claro a red outer border plus thin grey border between rows, and with Olivero just a red border in between rows. I gather that's due to an update to styles in #3021388, and doesn't seem possible to override while using CKEditor5.
@cilefen, in answer to your questions:
1. The problem is it's not possible to have a solid 1px border, since the attributes are removed and it seems like some defaults or theme settings are applied. If you want a border you have to set something other than solid and 1px.
2. Hard to know if the demo has the same problem — it looks OK in the editor on the demo but there's no option to save or view source to see if it has the same behaviour as in Drupal.
Comment #4
akhtardahaThe issue arises from CKEditor's default 1px border-width. To allow users to apply default browser or theme typography borders, To address the issue with CKEditor's default border-width, consider these alternatives:
1. Add theme CSS: Include
table { border-width: 1px; }in your theme's style file. This sets a default border width, unaffected by user-applied borders.2. Use relative units: Replace 1px with 0.063rem (equivalent to 1px). This allows for more flexibility.
Comment #5
quietone commentedIf this is a Drupal problem then it will be fixed on the main development branch first, then backported.
Comment #7
pavlosdanCKEditor sets defaults for table and table cell.
In the version of ckeditor we are on (45.2.2) these are:
https://github.com/ckeditor/ckeditor5/blob/v45.2.2/packages/ckeditor5-ta... and
https://github.com/ckeditor/ckeditor5/blob/v45.2.2/packages/ckeditor5-ta...
In the tablecellborderstylecommand https://github.com/ckeditor/ckeditor5/blob/v45.2.2/packages/ckeditor5-ta...
the value is not returned if it matches the default. This happens for all other values as well. So for table cells this means that if the colour matches #bfbfbf, border width is 1px, or border style is solid. Nothing will be returned.
Is there a way to override the default values through Drupal to set them to border-style none, and empty strings, to avoid this confusion?
Alternatively, the easiest way around this is to provide styling in the theme for the ckeditor defaults, so the table always has styling when those are selected. For the rest, since ckeditor will add inline styles, those will take precedence.
Comment #8
pavlosdanIf you want to override the defaults, in a custom module you can do something like:
If Core wants to provide some defaults to avoid confusion, the ckeditor5.ckeditor5.yml file can be changed to provide these defaults in the ckeditor5_table_properties and ckeditor5_table_cell_properties plugins: