To create a table in HTML, put rows inside a <table> element using <tr>, with <th> for header cells and <td> for data cells. Write the markup in a plain-text or code editor, save the document with an .html extension, and open it in a browser. Start with the example below, then add your content and CSS styling.
The short version
- Basic structure: Create rows containing header cells and data cells.
- Clear headings: Use headers and a caption to explain your table.
- Appearance: Add borders, padding and colors with CSS.
- Other routes: Use a visual generator, an editor or your website’s table block.
| Option | What you can do |
|---|---|
| Write HTML directly | Create rows, headers and data cells |
| Merge cells | Span multiple columns or rows |
| Add accessible headers | Identify headings and label the table |
| Style with CSS | Control borders, spacing and colors |
| VS Code Emmet | Expand an abbreviation into table markup |
| VS Code AI assistant | Generate proposed HTML from a request |
| Dreamweaver visual editor | Choose table dimensions and enter content |
| Dreamweaver data import | Convert delimited text into a table |
| TablesGenerator editor | Build a table visually in a browser |
| TablesGenerator import | Convert spreadsheet, CSV or XLSX data |
| WordPress.com Table block | Create a table inside the block editor |
| Self-hosted WordPress Table block | Configure a table without a table plugin |
| WordPress.com Custom HTML | Insert handwritten or generated markup |
| Google Sites embed | Add supplied HTML table code |
| Excel webpage export | Save selected cells as static HTML |
| Excel AutoRepublish | Regenerate exported HTML when saving |
| JavaScript DOM methods | Generate rows and cells for dynamic data |
| VS Code download | Get an editor for HTML and Emmet |
| Dreamweaver product page | Get a visual HTML editor |
Create your first HTML table
Open a plain-text or code editor and place the following markup inside your HTML document’s <body> element. It creates a header row with two columns and a data row containing a name and score.
<table> <tr><th>Name</th><th>Score</th></tr> <tr><td>Ada</td><td>95</td></tr> </table>Save the document with an .html extension, then open it in your browser. This structure works in current Chrome, Edge, Firefox and Safari, including their mobile browsers. Replace the example’s headings and values with your own tabular data.
Each <tr> groups the cells belonging to one row. Keep headings in <th> elements and ordinary values in <td> elements as you edit. Reserve tables for tabular data and use CSS layout to arrange page navigation and other page content.
Add rows and merge cells
For another row, add another <tr> inside the table and put its data cells inside it. To add another column, add a matching header cell and the corresponding data cell in each ordinary row. Keep the cells in the same column order throughout the table.
To stretch a heading or value across two columns, add colspan="2" to its <th> or <td> element. To span two rows, use rowspan="2" instead. This example creates one heading covering two columns:
<tr><th colspan="2">Scores</th></tr>Adjust the surrounding cells so they do not occupy positions already covered by the merged cell. If the columns stop lining up after a merge, check the cells alongside and below that span. A spanning cell takes the place of the separate cells it covers.
Add a caption and style the table
Give your table a caption by placing <caption> immediately inside <table>. For tables with both row and column headings, add scope="col" to column headers and scope="row" to row headers. These associations help people using screen readers understand which headings apply to the data.
Group header rows with <thead> and data rows with <tbody>; use <tfoot> for footer rows when appropriate. The following version combines a caption, column headers and a row header:
<table> <caption>Scores</caption> <thead><tr><th scope="col">Name</th><th scope="col">Score</th></tr></thead> <tbody><tr><th scope="row">Ada</th><td>95</td></tr></tbody> </table>Use CSS to add visible borders and space inside the cells. Apply the following CSS to give header and data cells a black border with padding, while collapsing adjacent borders:
table { border-collapse: collapse; } th, td { border: 1px solid black; padding: 8px; }Adjust presentation with CSS properties such as width, background-color and text-align. Older table attributes such as border, cellpadding, cellspacing, align and bgcolor are deprecated or obsolete. Use CSS borders, padding, border spacing, margins and background colors instead.
Generate markup with editor tools or JavaScript
If you need an HTML editor, get it from the official Visual Studio Code download page for Windows, macOS or Linux. VS Code includes Emmet, so you do not need to install an Emmet extension. Open an HTML file and type this abbreviation:
table>tr*3>td*2Open the Command Palette and select Emmet: Expand Abbreviation. The abbreviation creates three rows with two data cells each. Fill in the content, then change the appropriate header cells to <th>.
With AI access configured in VS Code, you can also generate a table from a written request. Select Chat > Open Inline Chat, or press Ctrl + I on Windows or Linux and Command + I on macOS. Describe the table, its data, headers and caption, then press Enter.
Review the proposed changes and select Keep, then save and preview the HTML in a browser. Files already belonging to a chat editing session may open Ask in Chat instead; enter your request there. Write your own request describing the table you want.
For dynamic data, you can create rows and cells with JavaScript using current browser DOM APIs. Start with a table whose id is results, then run the script after that element:
<table></table> <script> const table = document.getElementById('results'); const row = table.insertRow(-1); const cell = row.insertCell(0); cell.textContent = 'Example'; </script>Repeat the row and cell insertion operations for additional data, setting each cell’s textContent to its value. Add semantic headers separately using <th> elements.
Build or import a table online
For a visual approach in a modern desktop browser, open the TablesGenerator HTML editor. Click a cell and type its content, then press Tab to move between cells. Pressing Tab at the end adds a row.
Adjust formatting with the toolbar and Theme. The generated result updates automatically, so click Copy to clipboard beneath it when the table is ready. Paste the generated <style> and <table> into your HTML page.
To bring in existing spreadsheet data, copy the cells, click an editor cell and press Ctrl + V. Alternatively, click Import a CSV or Excel file and select a .csv or .xlsx file, choosing the worksheet for an Excel workbook. Review the imported result and click Copy to clipboard to obtain the HTML.
Create a table visually in Dreamweaver
Dreamweaver offers a visual table editor for Windows and macOS; you can obtain it from the official Adobe Dreamweaver product page. Place the insertion point in your HTML document, then select Insert > Table. Another route is to choose HTML in the Insert panel and click Table.
Set Rows and Columns, choose the appropriate header arrangement and optionally enter a Caption. Click OK, then enter your content in the cells. Use CSS for the table’s presentation.
For an import, prepare a text file with values separated by tabs, commas, colons or semicolons. Select File > Import > Import Tabular Data, then use Browse to select the Data File. Set Delimiter to match your file, select Fit to Data if desired, and click OK. This workflow imports delimited text rather than an Excel workbook directly.
Add a table in WordPress
In the WordPress.com page, post or template editor, click the + block inserter, search for table and select Table. Alternatively, type /table on a new line and press Enter. Enter the column and row counts, click Create table and type into the cells. Use Edit table to change rows or columns.
In the self-hosted WordPress block editor, select Add block > Table, or type /table, then configure the table and enter its content. Select the block and open Settings to enable Header section or Footer section, or change Fixed width table cells. This route uses the built-in block and does not require a table plugin.
To insert existing markup on WordPress.com, open the target page, post or template and click + Block Inserter. Search for HTML, choose Custom HTML, then click Edit HTML and paste your table markup. Inspect the preview and click Update.
Basic table tags are allowed on all WordPress.com plans. Restricted tags, including <style> and <script>, require a paid plan with hosting features activated. If your plan does not meet that condition, use basic table markup without those restricted tags or create the table with the Table block.
Embed the table in Google Sites
On a computer, open your Google site and select Insert > Embed > Embed code. Paste your HTML table code, placing any CSS inside <style> tags. Click Next, then Insert, then Publish.
This workflow embeds HTML you supply. Create the table markup first using the handwritten example or a generator, then add that code to your site.
Export Excel cells as an HTML webpage
In Excel for Microsoft 365 or Excel 2024 desktop, select the cells you want to export. Choose File > Save As, select Web Page (*.htm; *.html) and save the selected content. The same export workflow also covers Excel 2021, 2019 and 2016 desktop.
For more control, click Publish and choose Range of cells under Choose. Specify the range and File name, then click Publish. Retain any accompanying supporting-files folder with the exported webpage.
Frequently Asked Questions
How do you expand an Emmet abbreviation with Tab?
In VS Code’s settings.json, set "emmet.triggerExpansionOnTab": true. Type your Emmet abbreviation in an HTML file, then press Tab to expand it.
How do you connect data cells to several headers?
For complex header associations, give the header cells id attributes. Add a headers attribute to each relevant data cell and reference the identifiers of its associated headers.
Can Excel update the exported HTML whenever you save?
Yes, AutoRepublish regenerates the exported HTML whenever you save the workbook in the Excel desktop versions covered by the export workflow. During webpage publishing, select AutoRepublish every time this workbook is saved and click Publish. When the subsequent save message appears, click Enable the AutoRepublish feature.
Can a Google Sites table embed occupy a whole page?
Yes, you can use a full page embed in the Google Sites desktop editor. Select Pages > Add > Full page embed before entering your HTML code.
Why are wide table options missing in self-hosted WordPress?
Your theme’s support determines whether Wide width and Full width are available for the Table block. To adjust cell widths instead, select the block, open Settings and change Fixed width table cells.
What should replace an old table summary attribute?
Replace the deprecated summary attribute with an appropriate caption or explanatory text. Use that text to explain the table rather than retaining the old attribute.











