How to create a form with HTML/XHTML

A form is an area on a web page that can contain form elements.

Form elements are elements that allow the users of a web page to enter data in a form through text fields, text areas, drop-down menus, radio buttons, check-boxes, etc.

The openning <form> and closing </form> tags define a form. The openning and closing form tags on a web page by themselves will display a only blank area where the form is placed on the web page.

The attributes of a form tag configure how the form data is handled. The action attribute contains the name of the script or program on the web server that will process the data that is submitted by the user in the form. The value of the action attribute should be the file name of the script or program, including its' location on the web server.

You should specify how the data is transferred to the web server that hosts the web page that contains the form using the method attribute of the <form> tag. There method attribute has 2 possible values: get and post. Using the post method is the most common and recommended method.

The code below shows you how to create a form with a text-field with HTML/XHTML.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>Web Development Tutorials.com</title>
</head>
<body>

<form action="script.php" method="post">
user name:
<input type="text" name="username" />
</form>

</body>
</html>

The code above creates the form with a text-field below.

user name:

Use the text editor below to practice what you have learned.

Free Website Templates

Free Web Tools

Recommended Websites