html

How to Make HTML Table Cell Editable?

In web development, users can utilize various HTML components for designing applications. The table component is one of them that is used for organizing the data in rows and columns. Furthermore, the user can make the table or a specific table cell editable with the help of the HTML “contenteditable” attribute.

This tutorial will state:

How to Create/Make a Table in HTML?

To make a table in HTML, check out the given instructions:

  • Create a table with the help of the HTML “<table>” element and add a table border using the “border” property.
  • Specify the table rows using the “<tr>” tag.
  • To add headings in table cells, utilize the “<th>” inside the “<tr>” tag.
  • Add the “<td>” tag to create cells for data.
  • Add data between the “<td>” elements as follows:
<table border="1px">
<tr> <th>Name</th> <th>ID</th> <th> Category</th> </tr>
<tr> <td>Jenny</td> <td>001</td> <td> A</td></tr>
<tr> <td>Hafsi</td> <td>002</td> <td> B</td></tr>
<tr> <td>Mari</td> <td>003</td> <td> C</td></tr>
</table>

Output

How to Make a Table Cell Editable in HTML?

Users can edit a specific cell in real-time by making the table cell editable. To do so, utilize the “contenteditable” attribute inside the “<td>” tag of the specific cell you want to edit:
[/cc]

<table border="1px">
<tr> <th> Name </th> <th>ID</th> <th> Category</th> </tr>
<tr> <td contenteditable> Jenny </td> <td>001</td> <td> A</td></tr>
<tr> <td> Hafsi</td> <td>002</td> <td> B</td></tr>
<tr> <td> Mari </td> <td>003</td> <td> C</td></tr>
</table>

From the output, you can see the table cell with the “Jenny” is editable:

How to Make a Whole Table Editable in HTML?

To make the complete table editable, use the “contenteditable” attribute in the “<table>” element:

<table contenteditable border="1px">
<tr> <th> Name </th> <th>ID</th> <th> Category</th> </tr>
<tr> <td> Jenny </td> <td>001</td> <td> A</td></tr>
<tr> <td> Hafsi</td> <td>002</td> <td> B</td></tr>
<tr> <td> Mari </td> <td>003</td> <td> C</td></tr>
</table>

It can be seen that the complete table is now-editable. Here, we can edit or remove the data of any table cell:

This article has demonstrated the method for making the HTML table cell editable.

Conclusion

To make the HTML cell editable, first, create the table in HTML by utilizing the “<table>” element. Then, add the “contenteditable” attribute in the “<td>” tag of a specific cell to make the cell editable. However, to make the whole table editable, utilize the contenteditable attribute inside the <table> element. This post demonstrated the method to make HTML table cells editable.

About the author

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.