The rel attribute in the <form> tag specifies the relationship between the current document and the linked resource after form submission. It is mainly used when the target="_blank" attribute opens the response in a new tab or window.
- Defines the relationship between the current page and the destination resource.
- Common values include noopener, noreferrer, and external.
- Helps improve security and control browser behavior.
Syntax:
<form rel="value">- external: It specifies that the external document is not a part of current site.
- help: It specifies a link to a help document.
- license: It defines a copyright information for the document.
- next: It specifies the next document in a selection.
- nofollow: It specifies that the google search spider should not follow that link and mostly used for paid links.
- noreferrer: It defines the browser should not send an HTTP referrer header, if the user follows the hyperlink.
- prev: It defines a previous document in a selection.
- search: It specifies the search tool for the document.
Example 1: This example uses rel="noreferrer" to prevent the browser from sending referrer information to the target webpage during form submission.
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<body>
<h2 style="color: green">GeeksforGeeks</h2>
<h2>HTML form rel="noreferrer" Attribute</h2>
<b>This will avoid information passed to the post page </b>
<!-- It avoids passing the referrer information
to target website by removing the referral
info from the HTTP header.
It is safe to use -->
<!--Driver Code Ends-->
<form rel="noreferrer" action="mypage.php">
<input type="search" placeholder="search here" />
<input type="button" value="search" />
</form>
<!--Driver Code Starts-->
</body>
</html>
<!--Driver Code Ends-->
Example 2: This example uses rel="external" to indicate that the form submission points to a resource outside the current website.
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<head>
<style>
h2 {
font-family: Impact;
color: green;
}
body {
text-align: center;
}
</style>
</head>
<body>
<h2>GeeksforGeeks</h2>
<b> HTML Form rel="external" Attribute </b>
<!-- The referred document is not part
of the current site -->
<!--Driver Code Ends-->
<form rel="external" action="mypage.php">
User_id:<input type="text" /><br /><br />
Password:<input type="password" /><br />
<input type="submit" value="submit" />
</form>
<!--Driver Code Starts-->
</body>
</html>
<!--Driver Code Ends-->