CodeBlanks Logo Icon CodeBlanks

Form skeleton

HTML course · Beginner · Lesson 52/68

Build a form skeleton with <form> and the action/method attributes.

What is a form?

A form is the HTML container that sends the user's entered data to the server. Sign-in, sign-up, search and newsletter subscriptions all rest on a form.

A form opens with <form> and closes with </form>. It has two core attributes: action says where the data goes (a URL), method says how it is sent. The most common values are get and post.

action and method together

action and method work together. Example: <form action="/login" method="post">. Here action gives the address the data goes to, method gives how it is sent.

get appends data to the URL as ?key=value; it suits search forms. post carries data in the body; it is preferred for passwords or long content. You pick the right one for the content.

Exercise Write a form skeleton

Add a <form> to body. Give action the value /submit and method the value post. Leave a short comment inside the form; we will add fields in later lessons.

Show example solution
<body>
  <form action="/submit" method="post">
    <!-- fields go here -->
  </form>
</body>

Test yourself

  1. Which method is preferred for sending secret data like a password?

    • get
    • head
    • post
    • options
    Show answer

    post — Correct. post carries data in the request body, not the URL; that suits passwords.

  2. Send the form with post

    <form action="/signup" ____>
      <!-- fields go here -->
    </form>
    Show answer
    <form action="/signup" method="post">
      <!-- fields go here -->
    </form>
  3. Match each tag to its role

    <form>
    Form container
    action
    Where data is sent
    method
    How data is sent
    get
    Appends data to URL

All lessons in Beginner