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

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.

Quick answer: To make a student registration form in HTML, put a <form> around a <table> with one row per field: the <label> in a <th> cell and the input in a <td> cell. Give every input a name, add required where a field must be filled in, and style the table with CSS.

Table of contents8 sections
  1. HTML table tags used in the form
  2. Form fields used
  3. Program in HTML and CSS: full code
  4. Output
  5. How it works
  6. Make the form fit small screens
  7. Common mistakes
  8. Frequently asked questions

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.

Student registration form in HTML and CSS: full code

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.

Make the form fit small screens

On a phone, two columns leave little room for the inputs. Add this media query at the end of the <style> block: below 600 pixels it turns every row and cell into a normal block, so each label sits above its field and the input uses the full width.

@media (max-width: 600px) {
  tr, th, td {
    display: block;
  }
  th {
    width: auto;
    border-bottom: none;
    padding-bottom: 0;
  }
}

Common mistakes

  • Giving radio buttons in one group different name values. The browser then treats them as separate groups and lets the student pick more than one gender or course.
  • Leaving out the name attribute. A field without a name is not sent when the form is submitted, even if it is filled in.
  • A <label for="…"> that does not match the input’s id. Clicking the label then does nothing, and screen readers cannot tell which field it belongs to.
  • Using placeholder instead of a label. The placeholder disappears as soon as the student starts typing, so the field loses its description.
  • Using type="number" for a phone number. Number fields are meant for amounts and show up and down arrows; type="tel" with a pattern is the right choice.

Would you like another HTML exercise, such as a login or feedback form? Suggest it on our write to us page.

Key takeaways

  • The <table> only controls the layout; the <form> element collects and submits the data.
  • Radio buttons in one group share a name, so only one can be chosen; checkboxes can be ticked in any combination.
  • required, type="email" and pattern let the browser check the input before it is sent, without JavaScript.
  • Every input needs a name for the server and a matching <label> for accessibility.

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.

What does pattern=”[0-9]{10}” on the mobile number do?

It is a regular expression the browser checks before submitting: exactly ten digits and nothing else. If the student types nine digits or a letter, the browser shows a message and does not send the form. Add a title attribute to explain the expected format in that message.

Is a table-based form accessible?

It can be. Link every input to its <label> with matching for and id values, as this form does, and give the table a <caption>. Screen readers then announce each field’s label. Do not rely on colour alone to show which fields are required.

How do I store the submitted student details?

The browser sends the fields to the URL in the form’s action attribute. A server script (PHP, Node.js, Python and so on) reads each value by its name and saves it in a database or a file. To work with the same kind of record in a program, see how to display student details using a structure in C.

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.