> For the complete documentation index, see [llms.txt](https://web-dev-guide.wishtack.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://web-dev-guide.wishtack.io/forms/the-less-than-form-greater-than-tag.md).

# The \<form> tag

## `<form>` tag attributes

The first step when implementing an HTML form is to add a `form` tag.

```markup
<form>
...
</form>
```

The form tag has three main attributes:

* **action**: that describes the URL where the data should be sent when the form is submitted.
* **enctype**: that specifies the encoding to use for sending data *(`application/x-www-form-urlencoded`, `multipart/form-data` and `text/plain`)*.&#x20;
* **method**: that controls the HTTP method that will be used to send data to server.

## Example

```markup
<form
    method="post"
    enctype="application/x-www-form-urlencoded"
    action="https://mylibrary.io/books">
</form>
```

## Intercepting `submit` event

In most cases in a JavaScript application, the content shouldn't be sent directly over the network to the backend but it **should be intercepted by the JavaScript** on submission.

When the user submits the form *(e.g.: presses enter or clicks on a `<button type="submit">` inside the form)*, the `form` element triggers a `submit` event.

The JavaScript can be intercepted by adding an event listener and the default behavior *(sending the form's data to the backend)* disabled calling the `preventDefault` method on the event.

```javascript
const form = document.querySelector('form');

form.addEventListener('submit', submitEvent => {
    submitEvent.preventDefault();
    ...
});
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://web-dev-guide.wishtack.io/forms/the-less-than-form-greater-than-tag.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
