HTML DOM Style captionSide Property


The HTML DOM captionSide property is used for getting or setting the table caption position.The table caption is only set on vertical position i.e top and bottom.

Following is the syntax for −

Setting the captionSide property −

object.style.captionSide = "top|bottom|initial|inherit"

The above properties are explained as follows:

ValueDescription
topFor positioning the table caption above the table. This is the default value.
bottomFor positioning the table caption below the table.
initialFor setting this property to initial value.
inheritTo inherit the parent property value

Let us look at an example for the captionSide property −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   #t1{
      caption-side: bottom;
      border: 2px dashed black;
   }
   td {
      border: 2px solid blue;
   }
   caption {
      font-size: 24px;
      font-weight: bold;
   }
</style>
<script>
   function changeCaptionPosition(){
      document.getElementById("t1").style.captionSide="top";
      document.getElementById("Sample").innerHTML="The caption side is now changed to top ";
   }
</script>
</head>
<body>
   <table id="t1">
      <caption>Demo Caption</caption>
      <tr>
         <th>demo head</th>
         <th>demo head</th>
      </tr>
      <tr>
         <td>there goes my data..</td>
         <td>there goes my..</td>
      </tr>
      <tr>
         <td>there goes my data..</td>
         <td>there goes my..</td>
      </tr>
   </table>
   <p>Change the above table caption position by clicking the below button</p>
   <button onclick="changeCaptionPosition()">Change Caption Position</button>
   <p id="Sample"></p>
</body>
</html>

Output

On clicking the “Change Caption Position” button

Updated on: 23-Oct-2019

22 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements