New: 77 pattern programs with tested code in C, C++, Java and Python Explore patterns

Student Registration Form in HTML and CSS Using a Table

Read summary with AI tools
Table of contents
  1. HTML table tags used in the form
  2. Form fields used
  3. HTML and CSS code for the student registration form
  4. Output
  5. How it works
  6. Frequently asked questions

A student registration form is one of the most common HTML exercises. In this tutorial you will build one with an HTML <table> for the layout and a little CSS for the styling. It has text, email, phone, date, radio, checkbox, drop-down and text-area fields, plus Submit and Reset buttons.

HTML table tags used in the form

TagPurpose
<table>Creates the table that holds the form fields
<caption>Adds a title to the table
<tr>Defines a row: one row per field
<th>A header cell, used here for the field labels
<td>A data cell, used here for the inputs

Form fields used

  • type="text" for names, city and state; type="email" and type="tel" for contact details.
  • type="date" for the date of birth, and <textarea> for the address.
  • Radio buttons for gender and course (only one can be chosen), checkboxes for hobbies (several can be chosen).
  • A <select> drop-down for the highest qualification.
  • required, maxlength and pattern attributes give basic validation without any JavaScript.

HTML and CSS code for the student registration form

Save the code below as registration.html and open it in any web browser.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Registration Form</title>
<style>
  body {
    font-family: Arial, Helvetica, sans-serif;
    background: #eef2f7;
    padding: 30px 10px;
  }
  table {
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    border-collapse: collapse;
    background: #ffffff;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  }
  caption {
    background: #2d3663;
    color: #ffffff;
    font-size: 22px;
    font-weight: bold;
    padding: 16px;
  }
  th, td {
    padding: 10px 14px;
    border-bottom: 1px solid #e4e4e9;
    text-align: left;
    vertical-align: top;
  }
  th {
    width: 32%;
    color: #2d3663;
  }
  input[type=text], input[type=email], input[type=tel],
  input[type=date], select, textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid #c4c9d6;
    border-radius: 4px;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 15px;
  }
  .buttons {
    text-align: center;
  }
  .buttons input {
    padding: 10px 28px;
    margin: 4px;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
    color: #ffffff;
    background: #006ba6;
  }
  .buttons input[type=reset] {
    background: #8a93b8;
  }
</style>
</head>
<body>

<form action="#" method="post">
  <table>
    <caption>Student Registration Form</caption>
    <tr>
      <th><label for="first-name">First Name</label></th>
      <td><input type="text" id="first-name" name="first_name" maxlength="50" placeholder="Rahul" required></td>
    </tr>
    <tr>
      <th><label for="last-name">Last Name</label></th>
      <td><input type="text" id="last-name" name="last_name" maxlength="50" placeholder="Sharma" required></td>
    </tr>
    <tr>
      <th><label for="email">Email</label></th>
      <td><input type="email" id="email" name="email" placeholder="student@example.com" required></td>
    </tr>
    <tr>
      <th><label for="mobile">Mobile Number</label></th>
      <td><input type="tel" id="mobile" name="mobile" pattern="[0-9]{10}" maxlength="10" placeholder="10-digit number" required></td>
    </tr>
    <tr>
      <th>Gender</th>
      <td>
        <label><input type="radio" name="gender" value="male" required> Male</label>
        <label><input type="radio" name="gender" value="female"> Female</label>
        <label><input type="radio" name="gender" value="other"> Other</label>
      </td>
    </tr>
    <tr>
      <th><label for="dob">Date of Birth</label></th>
      <td><input type="date" id="dob" name="dob" required></td>
    </tr>
    <tr>
      <th><label for="address">Address</label></th>
      <td><textarea id="address" name="address" rows="3" placeholder="House no, street, area"></textarea></td>
    </tr>
    <tr>
      <th><label for="city">City</label></th>
      <td><input type="text" id="city" name="city" placeholder="Bengaluru"></td>
    </tr>
    <tr>
      <th><label for="state">State</label></th>
      <td><input type="text" id="state" name="state" placeholder="Karnataka"></td>
    </tr>
    <tr>
      <th>Hobbies</th>
      <td>
        <label><input type="checkbox" name="hobbies" value="reading"> Reading</label>
        <label><input type="checkbox" name="hobbies" value="sports"> Sports</label>
        <label><input type="checkbox" name="hobbies" value="music"> Music</label>
        <label><input type="checkbox" name="hobbies" value="coding"> Coding</label>
      </td>
    </tr>
    <tr>
      <th><label for="qualification">Highest Qualification</label></th>
      <td>
        <select id="qualification" name="qualification">
          <option value="">-- Select --</option>
          <option>10th</option>
          <option>12th</option>
          <option>Graduation</option>
          <option>Post Graduation</option>
        </select>
      </td>
    </tr>
    <tr>
      <th>Course Applied For</th>
      <td>
        <label><input type="radio" name="course" value="BCA" required> BCA</label>
        <label><input type="radio" name="course" value="BSc"> B.Sc</label>
        <label><input type="radio" name="course" value="BCom"> B.Com</label>
        <label><input type="radio" name="course" value="MCA"> MCA</label>
      </td>
    </tr>
    <tr>
      <td colspan="2" class="buttons">
        <input type="submit" value="Submit">
        <input type="reset" value="Reset">
      </td>
    </tr>
  </table>
</form>

</body>
</html>

Output

This is how the form looks in the browser:

Student registration form built with an HTML table and CSS, shown in a web browser
The finished form in Chrome. Required fields are checked by the browser before submit.

How it works

  • The whole form sits inside a <form> element, and the table only controls the layout: labels in the left column, inputs in the right.
  • Each input has a name, which is what the server receives when the form is submitted, and a matching <label for="…"> for accessibility.
  • Radio buttons in the same group share one name, so only one of them can be selected.
  • The CSS adds spacing, borders, a header colour and styled buttons. width: 100% on the inputs makes them fill their cells.

Frequently asked questions

Should I use a table or CSS for form layout?

Tables are easy for beginners and fine for simple forms. For responsive production forms, CSS Grid or Flexbox is usually a better choice.

How do I send the form data somewhere?

Set the action attribute of the <form> to the URL of a server script (PHP, Node.js, Python and so on) and keep method="post".

Does this form validate the input?

Yes, basic validation: required fields, a valid email address and a 10-digit mobile number are checked by the browser before the form is submitted.

Authored by

Ghanendra Yadav runs Pattern Programs from Bangalore, India. The site started in 2020 to help students practise loops and logic through pattern programs in C, C++, Java and Python. Every program published here is compiled and run before it goes live, and the output shown is the real output.

Latest articles

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.