# Create (horizontally) scrollable tables using markdown syntax

**URL:** <https://talk.jekyllrb.com/t/create-horizontally-scrollable-tables-using-markdown-syntax/6805>\
**Category:** Help\
**Created:** [December 13, 2021, 2:31pm UTC](https://talk.jekyllrb.com/t/create-horizontally-scrollable-tables-using-markdown-syntax/6805 "2021-12-13T14:31:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zabetak](https://avatars.discourse-cdn.com/v4/letter/z/e68b1a/32.png) [@zabetak](https://talk.jekyllrb.com/u/zabetak)\
**Post date:** [December 13, 2021, 2:31pm UTC](https://talk.jekyllrb.com/t/create-horizontally-scrollable-tables-using-markdown-syntax/6805/1 "2021-12-13T14:31:15Z")

</div>

In order to have responsive tables, I want to be able to display an horizontal scrollbar in the table when the window/screen size becomes small.

I want to have a table with `width: 100%` and it’s contents stretched to fill the full width (so I can’t have a `display: block` on the table). But I also want an `overflow: auto` on the table, so if the screen is too narrow, the table scrolls horizontally.

To the best of my knowledge this cannot be done by pure CSS so I need to wrap the inside a

 element to make that work.

From the discussion in [Wrap Kramdown tables in a div · Issue #69 · gettalong/kramdown · GitHub](https://github.com/gettalong/kramdown/issues/69) it seems that I need to customize the kramdown HTML converter but I am not sure what’s the best way to do it via Jekyll. Any thoughts?

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [December 14, 2021, 4:45am UTC](https://talk.jekyllrb.com/t/create-horizontally-scrollable-tables-using-markdown-syntax/6805/2 "2021-12-14T04:45:00Z")

</div>

## Table structure and Kramdown

Okay you want to make a table using Markdown rather than HTML?

It doesn’t matter here. Make a Markdown table and then target with `table` in CSS. at the risk of affecting all tables.

```auto
| A | B | C |
--- | --- | ---
| some | table | here |

```

```auto
table {
 ...
}

```

* * *

If you want to narrow it down though, you could add a wrapper around your Markdown table to give it a div and an ID or class. See below.

No extra Kramdown configuration needed. That is what the linked issue says and that is my experience too, putting any element like Markdown image for example inside HTML as long as there is whitespace and you don’t indent.

```auto
<div class="overflow-table">

| A | B | C |
--- | --- | ---
| some | table | here |

</div>

```

```auto
.overflow-table {
 ...
}

```

* * *

Or you can just make a plain HTML table.

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [December 14, 2021, 4:51am UTC](https://talk.jekyllrb.com/t/create-horizontally-scrollable-tables-using-markdown-syntax/6805/3 "2021-12-14T04:51:58Z")

</div>

## CSS solution

I implemented this before, for scrolling table on mobile.

```auto
@media (max-width: 1000px) {
  table {
    overflow-x: auto;
    width: 100%;
  }
}

```

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [December 14, 2021, 4:54am UTC](https://talk.jekyllrb.com/t/create-horizontally-scrollable-tables-using-markdown-syntax/6805/4 "2021-12-14T04:54:10Z")

</div>

> [@zabetak](#):
>
> done by pure CSS so I need to wrap the inside a
> 
> element to make that work.

Oops you didn’t check your question formatting. Your element got lost

Remember to add codeblock

With backticks

````
```
<div></div>
```

````

Result

```auto
<div></div>

```

---

<div class="post-metadata">

**Author:** ![zabetak](https://avatars.discourse-cdn.com/v4/letter/z/e68b1a/32.png) [@zabetak](https://talk.jekyllrb.com/u/zabetak)\
**Post date:** [December 14, 2021, 8:57am UTC](https://talk.jekyllrb.com/t/create-horizontally-scrollable-tables-using-markdown-syntax/6805/5 "2021-12-14T08:57:55Z")

</div>

Thanks for taking the time to help @MichaelCurrin

If you don’t have a wrapper div it cannot be done with pure CSS associated to the table as demonstrated also by the fiddle: [Edit fiddle - JSFiddle - Code Playground](https://jsfiddle.net/rxpvwuqc/)

I want to add a div wrapper around the table but I want this to be done for **all** markdown tables transparently without having to modify each and every one manually. That is why I mentioned extending the HTML converter. Apologies if it was not clear from the beginning.
