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

  1. Install Drupal 10.4.x with CKEditor 5 enabled.
  2. Create or edit content that contains a table.
  3. 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
  4. Save the content and switch to source editing to inspect the generated HTML.
  5. Notice that the style attribute on the table and its cells does not include border-width:1px;.
  6. 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

CommentFileSizeAuthor
Screenshot_2.jpg62.85 KBjeanbryanx
Screenshot_1.jpg60.27 KBjeanbryanx

Comments

jeanbryanx created an issue. See original summary.

cilefen’s picture

Title: [BUG] CKEditor 5 in Drupal 10.4.x does not include border-width for tables with a 1px solid border » Table border-width style removed for tables with a 1px solid border
Status: Active » Postponed (maintainer needs more info)
Issue tags: -ckeditor5, -table, -border-width

At 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:

  1. What difficulties or problems does this behavior cause?
  2. Is the behavior the same on the CKEditor demos? If that's the case this isn't to do with Drupal itself.

I am updating some issue metadata according to the project guidelines.

gaddman’s picture

Issue summary: View changes

On 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.

akhtardaha’s picture

The 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.

quietone’s picture

Version: 10.4.x-dev » 11.x-dev

If this is a Drupal problem then it will be fixed on the main development branch first, then backported.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

pavlosdan’s picture

CKEditor 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.

pavlosdan’s picture

If you want to override the defaults, in a custom module you can do something like:

use Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition;

/**
 * Implements hook_ckeditor5_plugin_info_alter().
 */
function MYMODULE_ckeditor5_plugin_info_alter(array &$plugin_definitions): void {
  $default_properties = [
    'borderStyle' => 'none',
    'borderColor' => '',
    'borderWidth' => '',
  ];

  assert($plugin_definitions['ckeditor5_table_properties'] instanceof CKEditor5PluginDefinition);
  $table_properties_plugin_definition = $plugin_definitions['ckeditor5_table_properties']->toArray();
  $table_properties_plugin_definition['ckeditor5']['config']['table']['tableProperties']['defaultProperties'] = $default_properties;
  $plugin_definitions['ckeditor5_table_properties'] = new CKEditor5PluginDefinition($table_properties_plugin_definition);

  assert($plugin_definitions['ckeditor5_table_cell_properties'] instanceof CKEditor5PluginDefinition);
  $table_cell_properties_plugin_definition = $plugin_definitions['ckeditor5_table_cell_properties']->toArray();
  $table_cell_properties_plugin_definition['ckeditor5']['config']['table']['tableCellProperties']['defaultProperties'] = $default_properties;
  $plugin_definitions['ckeditor5_table_cell_properties'] = new CKEditor5PluginDefinition($table_cell_properties_plugin_definition);
}

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:

ckeditor5_table_properties:
  ckeditor5:
    plugins:
      - table.TableProperties
    config:
      table:
        contentToolbar: [tableProperties]
        tableProperties:
          defaultProperties:
            borderStyle: none
            borderWidth: ''
            borderColor: ''
  drupal:
    label: Table properties
    library: ckeditor5/internal.drupal.ckeditor5.table
    conditions:
      plugins:
        - ckeditor5_table
        # When arbitrary HTML is already allowed, it's harmless to enable CKEditor 5's UI for table properties.
        - ckeditor5_arbitraryHtmlSupport
    elements:
      - <table style>

ckeditor5_table_cell_properties:
  ckeditor5:
    plugins:
      - table.TableCellProperties
    config:
      table:
        contentToolbar: [tableCellProperties]
        tableCellProperties:
          defaultProperties:
            borderStyle: none
            borderWidth: ''
            borderColor: ''
  drupal:
    label: Table cell properties
    library: ckeditor5/internal.drupal.ckeditor5.table
    conditions:
      plugins:
        - ckeditor5_table
        # When arbitrary HTML is already allowed, it's harmless to enable CKEditor 5's UI for table cell properties.
        - ckeditor5_arbitraryHtmlSupport
    elements:
      - <td style>
      - <td rowspan colspan style>
      - <th style>
      - <th rowspan colspan style>