Merge Markdown table cells with colspan and rowspan

Standard Markdown tables can't merge cells. Compare HTML colspan and rowspan, extended dialect syntax and plain-text alternatives for readability, portability and accessibility.

If you want to merge cells horizontally in a Markdown table, the short answer is that the common pipe-table syntax cannot do it. Neither CommonMark nor the widely used GitHub Flavored Markdown table extension has a way to make a cell span columns or rows. To get merged cells, you either switch to raw HTML with colspan and rowspan attributes, use a Markdown dialect or plugin that adds spanning syntax, or restructure the table so it doesn't need merging. This review explains what each route changes and where it breaks.

Is merging cells suitable for your use?

Merged cells help when a table has grouped headers, for example a heading that covers several sub-columns, or when one value applies to several rows. The benefit is a table that looks less repetitive and shows grouping at a glance.

The main tradeoff is portability. Once you use HTML or dialect-specific syntax, the table only renders as intended where that HTML or syntax is supported. It is also harder to edit, harder to diff in version control, and harder for automatic table formatters to process.

Prefer a plain, unmerged table when the Markdown will move between platforms, be read as raw source, be edited often by several people, or be converted to other formats. In those cases, repeating a value in each row, or splitting a grouped header into combined labels such as "Q1 Jan" and "Q1 Feb", usually serves readers better than a merged layout that may collapse.

What merging actually changes

This is a structural formatting change, not a character transformation. Unlike reversed text, mirrored glyphs or Unicode "fonts", merging cells doesn't change the characters of your content. It changes the table structure that a renderer builds from your source. The source text gains markup, either HTML attributes or extra pipe characters, and the visual result depends entirely on whether the renderer understands that markup.

Why standard pipe tables can't merge

In a GitHub Flavored Markdown style table, every row is split into cells at unescaped pipe characters. Each cell maps to exactly one column. Leaving a cell empty produces an empty cell, not a merged one. An extra pipe doesn't create a span in this syntax either.

| Region | Q1 Jan | Q1 Feb |
| ------ | ------ | ------ |
| North  | value  | value  |
| South  | value  | value  |

Raw HTML with colspan and rowspan

Markdown generally allows raw HTML, so you can write the table directly as HTML. The colspan attribute makes a cell cover several columns, and rowspan makes it cover several rows. In the example below, "Region" spans both header rows and "Q1" spans two columns.

<table>
  <thead>
    <tr>
      <th rowspan="2" scope="col">Region</th>
      <th colspan="2" scope="colgroup">Q1</th>
    </tr>
    <tr>
      <th scope="col">Jan</th>
      <th scope="col">Feb</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">North</th>
      <td>value</td>
      <td>value</td>
    </tr>
  </tbody>
</table>

Check the column count when you write spans. Each row must add up to the same number of columns once spans are included. In the example, the first header row covers three columns: one for Region and two for Q1. The second row adds only two cells because Region already occupies the first column there.

Two practical caveats apply. First, under CommonMark rules, a block of HTML that starts with a table tag ends at the first blank line, so keep the table free of blank lines. Second, Markdown inside such a block is generally not processed. Write emphasis or code inside cells with HTML tags such as strong and code instead of asterisks or backticks.

Dialect and plugin syntax

Some extended Markdown dialects add their own spanning syntax. MultiMarkdown, for example, documents column spanning by placing extra pipes at the end of a cell, with one additional pipe for each extra column covered:

|              |       Q1        ||
| Region       | Jan    | Feb    |
| ------------ | ------ | ------ |
| North        | value  | value  |
| Note         | applies to both ||

Some other processors and plugins offer row-spanning markers or grid-table formats that support spans. The exact syntax and the versions that support it differ between tools. Confirm the behavior in the documentation for the processor you actually use. In any renderer that doesn't support the extension, this syntax shows up as stray pipes or misaligned cells.

Approach | Merges columns | Merges rows | Portability | Editing effort
Standard pipe table | No | No | Highest | Low
Raw HTML table | Yes, colspan | Yes, rowspan | Depends on whether the destination allows the HTML and attributes | High
Dialect or plugin syntax | Depends on the tool | Depends on the tool | Limited to that tool | Moderate
Restructured plain table | Not needed | Not needed | Highest | Low

Will it stay readable after copying or sharing?

Raw source: someone reading the Markdown file directly sees either verbose HTML or unusual pipe patterns. A plain pipe table stays readable as text, but an HTML table with spans is much harder to read without rendering.

Destination support: many platforms sanitize user-supplied HTML, and the allowed tags and attributes vary. A merged table that renders correctly in one editor preview may lose its spans, or its HTML entirely, on another site. Test the table in each place it will be published rather than relying on one successful preview.

Copy and paste: copying a rendered table into a plain-text field, chat message or terminal generally flattens it. How spanned cells come through depends on the source application and the destination, so check the pasted result if it matters.

Conversion and tooling: Markdown table formatters, linters and converters to other formats may not understand HTML tables or dialect spans. They may skip them, report errors or reflow them incorrectly.

Accessibility: assistive technologies rely on table semantics to tell users which headers apply to each cell. Spanned headers make that relationship more complex. Use th elements for headers and scope attributes such as col, colgroup and row. For complex tables, consider explicit id and headers associations. Keep layouts simple where possible, because deeply nested spans are harder to navigate. Behavior differs between screen readers and browsers, so verify important tables with the assistive technology your readers use.

Search and editing: the cell text remains ordinary text in either approach, so it stays searchable within the document. Editing is where the cost lies. Adding a column to a spanned table means updating span values and checking every affected row.

When to provide a plain-text equivalent

  • The content will be published to platforms you haven't tested.
  • Readers may view the raw Markdown, as with README files read in a terminal or plain-text email.
  • The table will be converted to other formats or processed by automated tools.
  • The merged layout encodes meaning that would be lost if the spans collapse, such as a value that applies to several rows.

A plain-text equivalent can be as simple as repeating the shared value in each row or flattening grouped headers into combined column names. If the merged layout is essential, a short sentence stating the grouping gives readers the same information when rendering fails.

Limits of this review

This overview is based on the general behavior of standard Markdown table syntax and HTML table markup. No platform-specific rendering tests or screen-reader tests are reported here. Check sanitizer rules, dialect syntax and assistive-technology behavior for your specific destination before relying on merged cells.