Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <div class="container">
    <h1>Dynamic Table</h1>
      <div class="input-container">
        <input type="number" id="columns" min="1" placeholder="Number of Columns">
        <input type="number" id="rows" min="1" placeholder="Number of Rows">
        <button onclick="createTable()">Create Table</button></div>
  <table id="myTable">
    <!-- Table will be dynamically generated here -->


  width: 60%;
  margin: 0 auto;

h1 {
margin-top: 0;
text-align: center;

display: flex;
justify-content: center;
flex-wrap: wrap;

#columns {
padding: 10px;
font-size: 16px;
margin-right: 10px;
border-radius: 5px;
border: 1px solid #ccc;

border-color: #66afe9;
outline: 0;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102,175,233,.6);
box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102,175,233,.6);

button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;

button:hover {
background-color: #3e8e41;

table {
  border-collapse: collapse;
  width: 100%;
.header-input {
  width: 100%;
  box-sizing: border-box;
  font-weight: bold;
  border: none;
  outline: none;
  text-transform: uppercase;

  margin-top: 30px;

th, td {
  border: 1px solid black;
  padding: 8px;
  text-align: left;

.editable-cell {
  background-color: #f2f2f2;
  outline: none

/* Chrome, Safari, Edge, Opera */
input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;

/* Firefox */
input[type=number] {
-moz-appearance: textfield;


                var tableData = [];

    function createTable() {
      var table = document.getElementById("myTable");
      var columnsInput = document.getElementById("columns");
      var rowsInput = document.getElementById("rows");
      var columns = parseInt(columnsInput.value);
      var rows = parseInt(rowsInput.value);

      // Clear existing table
      while (table.firstChild) {

      // Create table header
      var headerRow = document.createElement("tr");
      for (var i = 0; i < columns; i++) {
        var th = document.createElement("th");
        var input = document.createElement("input");
        input.setAttribute("type", "text");
        input.setAttribute("class", "header-input");
        input.setAttribute("placeholder", "Column " + (i + 1));

      // Create table rows
      for (var i = 0; i < rows; i++) {
        var rowData = [];
        var row = document.createElement("tr");
        for (var j = 0; j < columns; j++) {
          var cell = document.createElement("td");
          cell.setAttribute("contenteditable", "true");
          cell.setAttribute("class", "editable-cell");
          cell.addEventListener("input", updateCell);

    function updateCell(event) {
      var rowIndex = - 1;
      var columnIndex =;
      var value =;
      updateData(rowIndex, columnIndex, value);

    function updateData(row, col, value) {
      tableData[row][col] = value;

    function deleteRow(row) {
      var table = document.getElementById("myTable");
      tableData.splice(row, 1);

    function updateRow(row) {
      var table = document.getElementById("myTable");
      var rowData = tableData[row];
      var cells = table.rows[row + 1].cells;
      for (var i = 0; i < rowData.length; i++) {
        var value = cells[i].textContent.trim();
        rowData[i] = value;

    function displayData() {