HTML action Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Forms & Input

Introduction

In HTML, the action attribute plays a crucial role in defining the URL to which a form should be submitted. It is used within the <form> element to specify the server-side script or endpoint that will process the data submitted by the user.

What You’ll Learn

01

Submission URL

Where form data goes.

02

Relative Paths

Same-domain endpoints.

03

Absolute URLs

Cross-domain forms.

04

GET & POST

Pair with method.

05

JavaScript

Set action dynamically.

06

Security

Use HTTPS endpoints.

Purpose of action

The primary purpose of the action attribute is to provide the browser with the destination URL where the form data should be sent for processing. This URL could point to a server-side script, a web service, or any other resource capable of handling form submissions.

💡
Works With method

action defines where data goes; method defines how it is sent (GET or POST). Always set both intentionally.

📝 Syntax

Add action to the opening <form> tag with a valid URL as its value:

action.html
<form action="/submit-form" method="post">
  <!-- form fields -->
</form>

Syntax Rules

  • Only valid on <form> elements.
  • Value must be a valid URL (relative or absolute).
  • If omitted or empty, the form submits to the current page URL.
  • Combine with method, enctype, and accept-charset as needed.

💎 Values

The action attribute accepts various values, typically represented as URLs. These values can be absolute or relative URLs, allowing for flexibility in specifying where the form data should be sent. Here are some examples:

  • Relative URL/submit-form submits to the /submit-form endpoint on the same domain.
  • Absolute URLhttps://example.com/process-form sends data to a specific absolute URL, allowing cross-domain form submissions.
  • Empty valueaction="" submits the form to the same URL the page originated from (the current document URL).
action-values.html
<!-- Relative path -->
<form action="/submit-form" method="post">...</form>

<!-- Absolute URL -->
<form action="https://example.com/process-form" method="post">...</form>

<!-- Submit to current page -->
<form action="" method="get">...</form>

⚡ Quick Reference

Use Caseaction ValueNotes
Contact form (POST)/contactSame-domain handler
Search box (GET)/searchQuery string in URL
Third-party servicehttps://api.example.com/submitAbsolute URL
Process on same page"" or omitCurrent document URL
Applicable element<form>Form element only

Applicable Elements

ElementSupported?Notes
<form>YesPrimary and only standard use
<input>NoPlace action on the parent form
<button>NoButtons submit their parent form

Examples Gallery

POST contact forms, dynamic JavaScript action URLs, and GET search forms.

👀 Live Preview

A simple form with action="/submit-form" and method="post":

In a real app, clicking Submit would POST to /submit-form.

Example — POST Form

The action attribute is added to the opening <form> tag and takes the form of a URL. Here’s a basic example:

action.html
<form action="/submit-form" method="post" accept-charset="UTF-8">
  <label for="name">Name:</label>
  <input type="text" id="name" name="name">

  <label for="email">Email:</label>
  <input type="email" id="email" name="email">

  <input type="submit" value="Submit">
</form>
Try It Yourself

How It Works

In this example, the form data will be submitted to the /submit-form URL using the HTTP POST method. The server endpoint at that path receives the name and email fields for processing.

Dynamic Values with JavaScript

You can dynamically set the action attribute using JavaScript to modify the form submission behavior based on user interactions or other conditions. Here’s a simple illustration:

dynamic-action.html
<form id="dynamicForm" method="post">
  <!-- form fields -->
</form>

<script>
  document.getElementById("dynamicForm").action = "/submit-form";
</script>
Try It Yourself

How It Works

In this script, the action attribute of a form with the id dynamicForm is set to /submit-form. This flexibility is useful when the submission endpoint needs to change based on user selections or application state.

Example — GET Search Form

Use action with method="get" to append form fields as query parameters in the URL:

search-action.html
<form action="/search" method="get" role="search">
  <input type="search" name="q" placeholder="Search...">
  <button type="submit">Search</button>
</form>
Try It Yourself

How It Works

With GET, the browser builds a URL from action plus encoded field values. Search forms commonly use this pattern so results can be bookmarked and shared.

♿ Accessibility

  • Label every field — Use <label for="..."> so users know what data the form collects.
  • Describe submission outcome — Tell users what happens after submit (confirmation page, email sent, etc.).
  • Use role="search" — On search forms to help assistive technologies identify their purpose.
  • Provide error feedback — Return clear validation messages from the server endpoint defined in action.

🧠 How action Works

1

Author sets action on form

Define the submission URL in HTML or JavaScript.

Markup
2

User fills in fields

Inputs, selects, and textareas collect the data to send.

Input
3

Browser submits to action URL

GET appends query params; POST sends a request body.

Submit
=

Data reaches your server

The endpoint at action processes the submission and responds.

Browser Support

The action attribute is supported in all modern browsers on form elements. It has been part of HTML since early versions.

HTML4+ · Fully supported

Universal form submission

All major browsers honor action on <form> elements.

100% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
Internet Explorer All versions
Full support
Opera Fully supported
Full support
action attribute 100% supported

Bottom line: Use action confidently on every form that submits data to a server.

💡 Best Practices

✅ Do

  • Ensure the URL in action is a valid, accessible endpoint
  • Use secure HTTPS URLs when handling sensitive data
  • Pair action with the correct method (GET vs POST)
  • Validate and sanitize all submitted data on the server
  • Test forms end-to-end against the real submission endpoint

❌ Don’t

  • Point action at endpoints you do not control without review
  • Build URLs from unsanitized user input when setting action dynamically
  • Use GET for forms that change data or contain passwords
  • Forget CSRF protection on state-changing POST forms
  • Assume client-side validation replaces server-side checks

Conclusion

The action attribute is a fundamental aspect of HTML forms, guiding the browser on where to send user-entered data. Understanding how to use and customize this attribute is crucial for creating effective and functional web forms.

Whether you use a relative path, an absolute URL, or set the destination dynamically with JavaScript, always ensure your server endpoint is ready to receive, validate, and respond to submissions securely.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about action

Bookmark these before your next form.

5
Core concepts
📄 02

Form Only

On <form> element.

Scope
🌐 03

Relative or Absolute

Flexible URL values.

Values
⚙️ 04

JavaScript

form.action at runtime

Dynamic
🔒 05

HTTPS

Protect sensitive data

Security

❓ Frequently Asked Questions

It specifies the URL where form data is sent when the user submits the form.
<form> is the standard element. Other elements do not use action directly.
The form submits to the current page URL—the address shown in the browser.
Yes. Absolute URLs are valid and commonly used for third-party services or cross-domain submissions.
Yes. Assign a new URL to formElement.action based on user choices or form state.
Yes. The action attribute has universal support on form elements.

Build forms that submit correctly

Practice the action attribute with POST and GET examples in the Try It editor.

Try POST form example →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful