To group related data in HTML forms use the <fieldset> tag. This tag creates a box around the related elements. The <legend> tag is used inside the <fieldset> tag to give a caption to the group.
Example
You can try to run the following code to group data in HTML forms −
<!DOCTYPE html> <html> <body> <form> <fieldset> <legend>Student Information:</legend> Student Name:<br> <input type="text" name="sname"> <br> Student Subject:<br> <input type="text" name="ssubject"> <br> </fieldset> </form> </body> </html>