HTML & CSS Interview Question #23

What is the difference between GET and POST in an HTML form?

HTML Fundamentals, Structure, Semantics, Links, Images, Tables & Forms Junior Beginner

Quick Interview Answer

With method="get", successful form controls are encoded into the request URL query string. GET is appropriate for safe, repeatable operations such as search and filtering, and the resulting URL can often be bookmarked or shared.

Detailed Explanation

With method="get", successful form controls are encoded into the request URL query string. GET is appropriate for safe, repeatable operations such as search and filtering, and the resulting URL can often be bookmarked or shared.

With method="post", form data is sent in the request body. POST is commonly used for operations that create or change server state. Neither method provides security by itself; HTTPS and proper server-side validation and authorization are still required.

Code Example

<!-- Search/filter -->
<form action="/search" method="get">
    <input name="q" type="search">
    <button type="submit">Search</button>
</form>

<!-- State-changing submission -->
<form action="/profile/update" method="post">
    <input name="displayName">
    <button type="submit">Save</button>
</form>