×

HTML Form Action

The <form> tag has an attribute named action that contains a URL. The HTML action attribute defines the webpage URL on which you want to send the data after submitting the form, or you can redirect the user to the other page.

Examples of HTML Form Action:

Example 1:

This example creates a simple form with background color for making the web page attractive. After clicking the submit button, the data is sent, and the user is redirected to submit.html page, specfied in the action attribute.

<!DOCTYPE html>
<html>
  <title> Example 1 of Form Action Attribute </title>
<body bgcolor="cyan">


<h1> Example 1 of Form Action Attribute</h1>


<form action="submit1.html">
  <label for="Student Name"> Student Name: </label>
  <input type="text" id="Student Name" name=" Student Name"><br><br>
  <label for="email"> Email: </label>
  <input type="text" id="email" name="email"><br><br>
  <label for="age"> Age: </label>
  <input type="text" id="age" name="age"><br><br>
  <label for="Father's name"> Father's name:</label>
  <input type="text" id="Father's name" name="Father's name"><br><br>
  <label for="Mother's name"> Mother's name:</label>
  <input type="text" id="Mother's name" name="Mother's name"><br><br>
  <label for="University"> University:</label>
  <input type="text" id="University" name="University"><br><br>
  <label for="College"> College:</label>
  <input type="text" id="College" name="College"><br><br>
  <label for="Branch"> Branch:</label>
  <input type="text" id="Branch" name="Branch"><br><br>
  <label for="Hobby"> Hobby:</label>
  <input type="text" id="Hobby" name="Hobby"><br><br>
  <input type="submit" value="Submit">
</form>
</body>
</html>

Output:

The output screen has a form containing the student's name, email, age, father's name, mother's name, university, college, branch, hobby, and submit button.

HTML Form Action

On submission of the form, the user is redirected to the submit.html page, as shown below:

HTML Form Action

Example 2:

This example demonstrates the use of the form action attribute in HTML.

<!DOCTYPE html>  
<html>  
<head>  
<title> Example 2 of Form Action Attribute </title>  
<meta name="viewport" content="width=device-width, initial-scale=1">  
<style>  
body{  
font-family: Calibri, monospace, 'Segoe UI';  
background-color: rgb(192, 241, 255);  
}  
.container {  
padding: 40px;  
background-color: rgb(232, 247, 166);  
}  
  
input[type=text] {  
  width: 100%;  
  padding: 12px;  
  margin: 6px 0 24px 0;  
  display: inline-block;  
  border: none;  
  background: #b4e0e1;  
}  
input[type=text]:focus {  
background-color: rgb(93, 215, 223);  
outline: none;  
}  
 div {  
         padding: 12px 0;           
}
.btn {  
  background-color: #e7a70f;  
  color: white;  
  padding: 15px 20px;  
  margin: 6px 0;  
  border: none;  
  cursor: pointer;  
  width: 100%;  
  opacity: 1;  
}  
.btn:hover {  
opacity: 0.8;  
}  
</style>  
</head>  
<body>  
<div class="container">  
<center> <h1> Registration Form </h1> </center>


<form action="submit2.html" method="post"> 


<div>
<label> Student Name </label>   
<input type="text" name="Student Name" placeholder= "Student Name" size="14" required />   


<label> Father's Name: </label>     
<input type="text" name="Father's Name" placeholder="Father's Name" size="14"required />   


<label> Mother's Name: </label>     
<input type="text" name="Mother's Name" placeholder="Mother's Name" size="14"required />   
 
<label>   
Gender :  
</label> <br>
<input type="radio" value="Male" name="gender" > Male   
<input type="radio" value="Female" name="gender"> Female   
<input type="radio" value="Other" name="gender"> Other  <br> <br>


<label>   
Date of Birth :  
</label>  
<input type="text" name="DOB" placeholder="DOB" size="10" required>


<label>   
Mobile No. :  
</label>  
<input type="text" name="Mobile No." placeholder="Mobile No." size="10" required>
<div>  
<button type="submit" class="btn"> Register </button>
</div>    
</form>   
</body>  
</html>

Output:

The below snapshot shows the registration form, which has input fields like first name, last name, father's name, mother's name, the radio button for gender selection, date of birth, mobile number, and a register button. The web page looks colourful due to the use of CSS (Cascading Style Sheets).

HTML Form Action

When you click on the registration button, data is sent to the action page, and the user is redirected to the web page contained in the action attribute, as shown below:

HTML Form Action

Browser Support:

It supports the browsers listed below:

  • Mozilla Firefox
  • Internet Explorer
  • Google Chrome
  • Safari
  • Opera

Related Topics

HTML Id Attribute

The HTML id attribute represents the unique identifier for an element of the HTML document. Each element has its unique identifier. The id attribute is a global attribute that can be...

12 minutes read.

Html &lt;dd> Tag

In an HTML description list, an item's definition or description is indicated using the definition description ("dd" tag). A <dd> tag can contain paragraphs, line breaks, images, links, and lists. It...

4 minutes read.

How to add JavaScript to HTML

JavaScript is one of the most important languages today. It is a high-level, interpreted, lightweight programming language that makes web pages more interactive. It is a language of the web....

5 minutes read.

HTML Attributes

HTML Attributes provide the additional information about HTML elements. Attributes are always specified in the start tag. Attributes usually comes in pairs. lang Attribute This attribute helps in declaring the language...

2 minutes read.

HTML <address> Tag

Hyper Text Markup Language, HTML is the best markup language for creating Web pages. HTML consists of a wide variety of elements. In all of these elements, one element is...

4 minutes read.

HTML <samp> tag

The Samp tag in HTML is used for defining the sample output from the computer program. This tag is a phrase type tag and a container tag that means the...

2 minutes read.

Html <colgroup> Tag

A HTML table's column group is specified by the "colgroup" tag. If you want to apply various properties to one or more <col> elements in an HTML table, then you...

4 minutes read.

HTML <style> tag

The section of information that we want to style is contained in html style tag. It includes CSS, which is used to design the text and images in the web page. Syntax: <head> <title>…………....

3 minutes read.

HTML Text Format

Introduction HTML may format text in two different ways. The HTML tags define a text property to make it appear one way or another. A text element may also be formatted...

7 minutes read.

HTML <strike> tag

The HTML <strike> tag is used to specifies strikethrough text. The tag is deprecated now and <del> tag is used in HTML files instead of it. All the global and...

2 minutes read.

HTML <sub> tag

The sub element in HTML is used to describe one or more subscript texts. If The sub tag shows the text which is presented in a smaller font and below...

2 minutes read.

How to insert spaces/tabs in text using HTML/CSS

What is HTML? HTML or HyperText Markup Language is used to design web pages. It was released in 1993. The file extension name for HTML file is “.html”. An HTML file...

4 minutes read.

HTML Nested Table

HTML nested table refers to a table that is created inside another table. The table is in the form of rows and columns. From left to right are called horizontal rows,...

5 minutes read.

HTML Search Box

The HTML search box is also known as the search bar. It is an input text field that is used to search the content. If the users want to explore...

7 minutes read.

HTML Code

Before jumping into the topic, let’s understand a common scenario where we have a code snippet in our HTML file. By code snippet, we mean computer code, which is written...

5 minutes read.

How to change text color in HTML

Changing the text colour of a web page is essential because it enhances readability. There are several ways to change the colour of the text in HTML, which are as follows: Text...

7 minutes read.

HTML5 Button Tag

HTML Button Tag The < button > tag is used on the webpage to construct a clickable button inside the HTML. Within the < button>....</button > tag, we can place content...

2 minutes read.

HTML Charsets

In this tutorial, we are going to discuss about the charsets in the HTML. The letters, numbers, and several other symbols are shown correctly by the web browser. All of this...

2 minutes read.

HTML Anchor

HTML Anchor The HTML anchor tags define a hyperlink that links to other pages on one page. It can create hyperlinks to any web page and files, locations or any other...

3 minutes read.

HTML <section> tag

The section element in HTML is used to define sections in a document. Syntax of Section Tag: <body> <h1>……….</h1> <section> <h2>……….</h2> <p> …………………………</p> </section> <section> <h2>………..</h2> <p>…………………………. <p> </section> </body> Examples of Section Tag Example 1: In this example, we use the HTML "section" element...

3 minutes read.