How to create a comparison table with CSS?



To create a responsive table with CSS, the code is as follows −

Example

 Live Demo

<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style>    table {       border-collapse: collapse;       border-spacing: 0;       width: 100%;       border: 1px solid #ddd;    }    th, td {       text-align: center;       padding: 16px;       font-weight: bold;       font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;       font-size: 18px;    }    th:first-child, td:first-child {       text-align: left;    }    tr:nth-child(even) {       background-color: #f2f2f2    } </style> </head> <body> <h1 style="text-align: center;">Comparison Table Example</h1> <table> <tr> <th style="width:50%">Features</th> <th>Basic</th> <th>Pro</th> </tr> <tr> <td>Free</td> <td>Yes</td> <td>No</td> </tr> <tr> <td>Customer Support</td> <td>No</td> <td>Yes</td> </tr> <tr> <td>Validity</td> <td>1 Year</td> <td>Lifetime</td> </tr> <tr> <td>Warranty</td> <td>No</td> <td>5 Years</td> </tr> </table> </body> </html>

Output

The above code will produce the following output −

Updated on: 2020-05-07T10:44:56+05:30

477 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements