Skip to content
  • Quizes
  • QStack
  • Blog
  • pinterest
  • instagram
  • twitter
  • linkedin
  • facebook
W3 Coding Schools
  • Home
  • HTML
    • HTML Introduction
    • HTML Editors
    • Fundamentals of HTML
    • Elements of HTML
    • HTML Attributes
    • HTML Headings
    • HTML Paragraphs
    • HTML Style Attribute
    • HTML Text Formatting
    • HTML Phrase Tags
    • HTML Comments
    • HTML with CSS
    • HTML Links
    • HTML Images
    • HTML Tables
    • HTML Lists
    • HTML Blocks
    • HTML Class Attribute
    • HTML Id Attribute
    • HTML Iframes
    • HTML JavaScript
    • HTML File Paths
    • HTML Head
    • Computer Code Elements
    • HTML Entities
    • HTML Charset
    • HTML URL Encode
    • HTML and XHTML
    • HTML Layouts
    • HTML Forms
    • HTML Form Elements
    • HTML Form Input Types
    • HTML Input Attributes
    • HTML5 Introduction
    • HTML5 New Elements
    • Semantic Elements
    • HTML5 Migration
    • Style Guide
    • HTML Canvas
  • CSS
    • CSS Introduction
    • CSS Syntax and CSS Comments
    • CSS Selectors
    • How to add CSS to a Webpage
    • CSS Color Basics
    • CSS Background Properties
    • CSS Border Properties
    • CSS Margin and Padding Properties
    • CSS Height and Width properties
    • CSS Box Model
    • CSS Outline Properties
    • CSS Fonts
    • CSS Text
    • How To Add Icons
    • CSS Links
    • CSS List-Style
    • CSS Tables
    • CSS Display Property
    • CSS Position Property
    • CSS Overflow Property
    • CSS max-width Property
    • CSS Float and Clear Properties
    • CSS Alignment
    • CSS inline-block
    • CSS Combinators
    • CSS Pseudo Classes
    • CSS Pseudo Elements
    • CSS Opacity
    • CSS Navigation Bar
    • CSS Dropdowns
    • CSS Image Gallery
    • CSS Image Sprites
    • CSS Attribute Selector
    • CSS Styling Forms
    • CSS Counters
    • CSS Units
    • CSS Specificity
    • CSS Website Layout
    • CSS Rounded Corners
    • CSS Border Image Property
    • CSS Multiple Backgrounds
    • CSS Gradient
    • CSS Shadow Effects
    • CSS Text Effects
    • CSS Web Fonts
    • CSS 2D Transforms
  • Bootstrap 4
    • Bootstrap 4 – Introduction
    • Bootstrap versions
    • Bootstrap 4 Layout
    • Bootstrap 3 Vs Bootstrap 4
    • Bootstrap 4 Grid System
    • Bootstrap 4 Typography
    • Bootstrap 4 Colors
    • Bootstrap 4 Images
    • Bootstrap 4 Tables
    • Bootstrap 4 Jumbotron
    • Bootstrap 4 Figures
    • Bootstrap 4 Alerts
    • Bootstrap 4 Buttons
    • Bootstrap 4 Button Group
    • Bootstrap 4 Badges
    • Bootstrap 4 Spinners
    • Bootstrap 4 Progress Bars
    • Bootstrap 4 Pagination
    • Bootstrap 4 Breadcrumbs
    • Bootstrap 4 List Groups
    • Bootstrap 4 Cards
  • jQuery
    • jQuery Introduction
    • jQuery Download
    • jQuery Selectors
    • jQuery Event Methods
    • jQuery Hide/Show Effects
    • jQuery Fading Effects
    • jQuery Sliding Effects
    • jQuery Animation
    • jQuery Stop and Callback
    • jQuery Get and Set Methods
    • jQuery Chaining
    • jQuery Add
    • jQuery Remove
    • jQuery CSS Classes
    • jQuery Style Properties
    • jQuery Dimensions
    • jQuery Traversing
    • jQuery Ancestors
    • jQuery Descendants
    • jQuery Siblings
  • Javascript
    • JS Introduction
    • JS Where to Put
    • JavaScript Syntax
    • JavaScript Comments
    • JavaScript Variables
    • JavaScript Data Types
    • JavaScript Operators
    • JavaScript Events
    • JavaScript Strings
    • JavaScript Numbers
  • php
    • PHP Introduction
    • Install PHP
    • PHP Syntax and Comments
    • PHP Variables
    • PHP Constants
    • PHP Echo and Print
    • PHP Data Types
    • PHP Strings
    • PHP Operators
    • PHP $ and $$ Variables
  • WordPress
    • WordPress Introduction
    • WordPress History
    • WordPress.com vs WordPress.org
    • How to Install WordPress
    • WordPress Dashboard
    • How to Create a WordPress Website
    • WordPress Posts
    • WordPress Pages
    • WordPress Posts vs Pages
    • WordPress Categories
  • SEO
    • SEO Introduction
    • SEO Tactics and Methods
    • SEO Relevant Filenames
    • SEO Domain Name
    • Website Design and SEO
    • SEO Keywords
    • Meta Tags Optimization
    • Title Tag Optimization
    • Anchor Text Optimization
    • Content Optimization
  • Android
    • Android Introduction
    • Android History and Versions
    • Android Architecture
    • Android Environment Setup
    • Android Application Components
    • Hello World Application
    • Android Activities
  • iOS
    • iOS Introduction
    • iOS Environment Setup
    • iOS Architecture

You Are Here

  • Home
  • Learn HTML
  • HTML Tables

Topics

  • HTML Introduction
  • HTML Editors
  • Fundamentals of HTML
  • HTML Elements
  • HTML Attributes
  • HTML Headings
  • HTML Paragraphs
  • HTML Style Attribute
  • HTML Text Formatting
  • HTML Phrase Tags
  • HTML Comments
  • HTML with CSS
  • HTML Links
  • HTML Images
  • HTML Tables
  • HTML Lists
  • HTML Blocks
  • HTML Class Attribute
  • Id Attribute for HTML
  • HTML Iframes
  • HTML JavaScript
  • HTML File Paths
  • HTML Head
  • HTML Computer Code Elements
  • HTML Entities
  • HTML Charset
  • HTML URL Encode
  • HTML and XHTML
  • HTML Layouts
  • HTML Forms
  • HTML Form Elements
  • HTML Form Input Types
  • HTML Input Attributes
  • HTML5 Introduction
  • HTML5 New Elements
  • Semantic Elements in HTML5
  • HTML5 Migration
  • Style Guide
  • HTML Canvas
  • HTML SVG

Oct Champs & Prizes

  • 1. Pooja Ladda
  • 2. Manjali Kuldharan
  • 3. Pranali Surawar
  • 4. Anjali Kulkarni
  • 5. Vishal Deshmukh

Recent Posts

  • HTML Media
  • jQuery Siblings
  • Bootstrap 4 Cards
  • jQuery Descendants
  • jQuery Ancestors

HTML Tables

HTML table is an arrangement of data in rows and columns.
HTML Tables allow us to arrange data like images, text, and numbers into rows and columns.
You can create a table using a <table> tag in which <tr> tag is used to create rows and <td> tag is used to create columns inside a row.
The header for the group of table cells is defined using the <th> element. By default, headings of the table  are bold and centered.

Example:

<table style=”width:100%”>
<tr>
<th> Firstname </th>
<th> Lastname </th>
<th> Contact No. </th>
</tr>
<tr>
<td> Emma </td>
<td> Reed </td>
<td> 257894 </td>
</tr>
<tr>
<td> Lucas </td>
<td> Bell </td>
<td> 325468 </td>
</tr>
<tr>
<td> Aiden </td>
<td> Carter </td>
<td> 358467 </td>
</tr>
</table>
Try it

Adding a border to an HTML Table:

If you want to add a border to the table then you can add it using the CSS table-border property.
HTML does not specify the border to the table, it will be displayed without borders.
Don’t forgot to add borders for <th> and <td> tags also to have a complete table.

Example :

table, th, td {
border: 1px solid blue;
}
Try it

Adding Collapsed Borders in an HTML Table:

For borders to collapse into one border, add the CSS border-collapse property.

Example:

table, th, td {
border: 1px solid blue;
border-collapse: collapse;
}
Try it

Adding Cell Padding in an HTML Table:

Cell padding is the space between the edges of the cells and the cell contents. If you want to specify cell-padding, then use CSS padding property.

Example:

th, td {
padding: 10px;
}
Try it

Adding Left Align Headings in an HTML Table:

Table headings are by default align in the center and styled in bold.
To align the header to the left you can use CSS text-align property.

Example:

th {
text-align: left;
}
Try it

Adding Border Spacing in an HTML Table:

The border-spacing property of CSS is used to set the distance between the adjacent cells of the table.
The border-spacing property will work only when border-collapsed is separate.

Example:

table {
border-spacing: 10px;
}
Try it

Adding Cells that Span Many Columns and Rows in HTML Tables:

If you want to merge two or more columns into a single column then you can use colspan attribute.
Similarly, rowspan attribute is used to merge two or more rows into a single row.

Example:

<!–Coloumn spanning–>
<table style=”width:100%”>
<tr>
<th> Name </th>
<th colspan=”2″> Contact No. </th>
</tr>
<tr>
<td> Lucas Bell </td>
<td> 678924 </td>
<td> 547963 </td>
</tr>
</table>
<!–Row spanning–>
<table style=”width:100%”>
<tr>
<th> Name: </th>
<td> Lucas Bell </td>
</tr>
<tr>
<th rowspan=”2″> Contact No. </th>
<td> 678924 </td>
</tr>
<tr>
<td> 547963 </td>
</tr>
</table>
Try it

Adding a Caption in an HTML Table:

If you want to add a caption to an HTML table, you can use the caption element.
The <caption> tag is inserted immediately after the <table> tag.
The caption of the table will always be placed above the table by default.
You can place the caption below, to left or to the right of the table using the align parameter.

Example:

<table style=”width:100%”>
<caption> Employee Information </caption>
<tr>
<th> Firstname </th>
<th> Lastname </th>
<th> Contact No. </th>
</tr>
<tr>
<td> Emma </td>
<td> Reed </td>
<td> 257894 </td>
</tr>
<tr>
<td> Lucas </td>
<td> Bell </td>
<td> 325468 </td>
</tr>
<tr>
<td> Aiden </td>
<td> Carter </td>
<td> 358467 </td>
</tr>
</table>
Try it

Adding a Background Colour To a Table in HTML:

The background-color property is used to add the background color to the table.
You can change the background color of a table row, you just have to apply the CSS background-color property to the table row (i.e. the tr tag). Similarly to change the background color of a single cell, you can apply the same code to the table cell(i.e. the td).

Example:

table {
width: 100%;
background-color: #32a852;
}
Try it

Post navigation

HTML Images
HTML Lists

Ask a Question Cancel reply

Your email address will not be published. Required fields are marked *

W3 CODING SCHOOLS © Copyright 2019-20
Privacy policy   Terms of use

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok