HTML Tutorial: HTML Tables, Classes and Ids
Tags: html, webdev, codenewbie, tutorial
Published: 2021-06-10 19:04:08

---
title: HTML Tutorial:  HTML Tables, Classes and Ids
published: true
date: 2021-01-10 01:16:04 UTC
tags: [html, webdev, codenewbie, tutorial]
canonical_url: https://www.devwares.com/blog//html-table
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wievr34jjdvawai729sr.png
series: Devwares Web development Free Course
---

## HTML Table

A html table is defined with the `<table>` tag. This allows html to arrange words in tabular form. Each table row is defined with the `<tr>` tag.

![AD-BANNER](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/41meil9ho9yx2ulb535m.png)

A table header is defined with the `<th>` tag. By default, the headings are bold and centered. A table data/cell is defined with the `<td>` tag.

**HTML Code:**

```html
<table style = “width:100%”>
  <tr>
     <th> LastName </th>
     <th> FirstName </th>
     <th> Age </th>
  </tr>
  <tr>
    <td> William</td>
    <td> Sam</td>
    <td> 30 </td>
  </tr>
</table>

```

## Adding a border

You can add border using a CSS border property to the table

**CSS Code:**

```css
Table, th, td {
  Border: 1px solid black;
}

```

Don’t worry we are going to explain better on our CSS tutorial.

# HTML Classes

The class attribute is used to specify a class for an HTML element. It is common to find multiple HTML elements sharing the same class.

**HTML Code:**

```html
<style>
  .cities {
    Background-color:blue
    Color: white;
    Margin: 20px
    Padding: 20px
  }
</style>
<div class = “cities”>
  <h2> London</h2>
  <p> London is the capital of England </p>
</div>

<div class= “cities”>
  <h2> Paris </h2>
  <p> Paris is the capital of France </p>
</div>

```

## HTML Id attribute

This is used to specify a unique id in an HTML document. It is used to point specific style declaration in a style sheet. It is also used by Javascript to access and manipulate or change the element with the specific ID.

The syntax is written with a hash character "#" followed by an id name.

**HTML Code:**

```html
<!DOCTYPE html>
<html>
 <head>
   <style>
     #myHeader{
       Background-color:lightbllue;
       Color: black;
       Padding: 40px;
       Text-align: center;
      }
   </style>
  </head>
  <body>
    <h1 id= “myHeader”>my Header</h1>
  </body>
</html>

```

## Difference between id and class

The difference lies in how they are used. A class name can be used by multiple HTML elements, while an id name must only be used by one html element within the page.


###Create Stunning Websites and Web Apps

Building different custom components in react for your web apps or websites can get very stressful. That's why we decided to build contrast. We have put together a UI kit with over 10000+ components, 5 admin dashboards and 23 additional different pages template for building almost any type of web app or webpage into a single product called Contrast Pro. [Try contrast pro!](https://www.devwares.com/product/contrast-pro)

![Contrast Design Boostrap](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ulsutxnzjpbpaauhvbew.png)

Contrast React Bootstrap PRO is a Multipurpose pro template, UI kit to build your next landing, admin, SAAS, prelaunch, etc. project with a clean, well documented, well crafted template and UI components. [Learn more about Contrast Pro](https://www.devwares.com/product/contrast-pro)

## Resources 

- [Contrast Design Bootstrap](https://www.devwares.com/docs/contrast/javascript/index/)
- [Accordion](https://www.devwares.com/docs/contrast/javascript/components/accordion/)
- [Alert](https://www.devwares.com/docs/contrast/javascript/components/alert/)
- [Animation](https://www.devwares.com/docs/contrast/javascript/components/animations/)
- [Autocomplete](https://www.devwares.com/docs/contrast/javascript/components/autocomplete/)
- [Badges](https://www.devwares.com/docs/contrast/javascript/components/badge/)
- [Box](https://www.devwares.com/docs/contrast/javascript/components/box/)
- [Breadcrumb](https://www.devwares.com/docs/contrast/javascript/components/breadcrumb/)
- [ButtonGroup](https://www.devwares.com/docs/contrast/javascript/components/buttonGroup/)
- [Button](https://www.devwares.com/docs/contrast/javascript/components/buttons/)
- [ButtonToolbar](https://www.devwares.com/docs/contrast/javascript/components/buttonToolbar/)
- [Card](https://www.devwares.com/docs/contrast/javascript/components/card/)
- [Carousel](https://www.devwares.com/docs/contrast/javascript/components/carousel/)
- [Checkbox](https://www.devwares.com/docs/contrast/javascript/components/checkbox/)
- [Collapse](https://www.devwares.com/docs/contrast/javascript/components/collapse/)
- [DataTable](https://www.devwares.com/docs/contrast/javascript/components/datatables/)
- [DatePicker](https://www.devwares.com/docs/contrast/javascript/components/datepicker/)
- [DropDown](https://www.devwares.com/docs/contrast/javascript/components/dropdown/)
- [Footer](https://www.devwares.com/docs/contrast/javascript/components/footer/)
- [Forms](https://www.devwares.com/docs/contrast/javascript/components/forms/)
- [Icon](https://www.devwares.com/docs/contrast/javascript/components/icon/)
- [Iframe](https://www.devwares.com/docs/contrast/javascript/components/iframe/)
- [Input](https://www.devwares.com/docs/contrast/javascript/components/input/)
- [InputGroup](https://www.devwares.com/docs/contrast/javascript/components/inputgroup/)
- [ListGroup](https://www.devwares.com/docs/contrast/javascript/components/listgroup/)
- [Mask](https://www.devwares.com/docs/contrast/javascript/components/mask/)
- [Modal](https://www.devwares.com/docs/contrast/javascript/components/modal/)
- [Multiselect](https://www.devwares.com/docs/contrast/javascript/components/multiselect/)
- [Notification](https://www.devwares.com/docs/contrast/javascript/components/notification/)
- [Pane](https://www.devwares.com/docs/contrast/javascript/components/pane/)
- [Panel](https://www.devwares.com/docs/contrast/javascript/components/panels/)
- [Pop Over](https://www.devwares.com/docs/contrast/javascript/components/popover/)
- [Progress](https://www.devwares.com/docs/contrast/javascript/components/progress/)
- [Radio](https://www.devwares.com/docs/contrast/javascript/components/radio/)
- [Rating](https://www.devwares.com/docs/contrast/javascript/components/rating/)
- [Select](https://www.devwares.com/docs/contrast/javascript/components/select/)
- [Select 2](https://www.devwares.com/docs/contrast/javascript/components/select2/)
- [Slider](https://www.devwares.com/docs/contrast/javascript/components/slider/)
- [Spinner](https://www.devwares.com/docs/contrast/javascript/components/spinner/)
- [Stepper](https://www.devwares.com/docs/contrast/javascript/components/stepper/)
- [Switch](https://www.devwares.com/docs/contrast/javascript/components/switch/)
- [Table](https://www.devwares.com/docs/contrast/javascript/components/table/)
- [Forms](https://www.devwares.com/docs/contrast/javascript/forms/)
- [Navbar](https://www.devwares.com/docs/contrast/javascript/navigation/navbar/)
- [Pagination](https://www.devwares.com/docs/contrast/javascript/navigation/pagination/)
- [Tab](https://www.devwares.com/docs/contrast/javascript/navigation/tabs/)
- [Sidebar](https://www.devwares.com/docs/contrast/javascript/navigation/sidebar/)
- [Time Picker](https://www.devwares.com/docs/contrast/javascript/sections/timepicker/)
- [Data Table](https://www.devwares.com/docs/contrast/javascript/table/datatables/)
- [Fixed Data Table](https://www.devwares.com/docs/contrast/javascript/table/fixed_datatables/)
- [Table](https://www.devwares.com/docs/contrast/javascript/table/table/)
- [Widgets](https://www.devwares.com/docs/contrast/javascript/widgets/)