Open In App

How to Create Form Submit Button in HTML ?

Last Updated : 23 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In HTML, the form submit button plays a crucial role in sending user data to the server for processing. It's typically created using either <input type="submit"> the <button> tag. Around 95% of web forms use one of these two methods, making them essential for enabling user interaction and data submission on websites.

Using <button> tag

In this approach, we are using the <button> tag to create a submit button within an HTML form. The button is styled with CSS for a green background color, white text, and a hover effect, and its functionality is defined through a JavaScript event listener to display an alert when clicked.

Syntax:

<button type="button" id="submitButton">Submit</button>

Example: The following example uses the <button> tag to create a Form Submit button in HTML.

index.html
<!DOCTYPE html>
<html>
<head>
    <title>Example 1</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <h1>GeeksforGeeks</h1>
    <h3>Using the button tag</h3>
    <form>
        <label for="username">Username:</label>
        <input type="text" id="username" 
               name="username" required>
        <label for="email">Email:</label>
        <input type="email" id="email" 
               name="email" required>
        <label for="password">Password:</label>
        <input type="password" id="password" 
               name="password" required>
        <button type="button" 
                id="submitButton">
              Submit
          </button>
    </form>
    <script>
        document.addEventListener(
              'DOMContentLoaded', () => {
            document.getElementById('submitButton').
                addEventListener('click', function () {
                    alert('Form submitted!');
                });
        });
    </script>
</body>
</html>
style.css
h1 {
    color: green;
    text-align: center;
}

body {
    text-align: center;
}

form {
    display: inline-block;
    text-align: left;
    max-width: 400px;
    margin: 20px auto;
}
label {
    display: block;
    margin-bottom: 8px;
}
input {
    width: 100%;
    padding: 8px;
    margin-bottom: 12px;
    box-sizing: border-box;
}
button {
    background-color: #4caf50;
    color: white;
    padding: 10px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}
button:hover {
    background-color: #45a049;
}

Output:

Output1

Note: To add styling in Button check out this article on CSS Buttons.

Using <input> tag

In this approach, we are using the <input> tag to create form fields and buttons within an HTML form. The styling is applied through CSS, between the submit button with a green background and the reset button with a red background. JavaScript is used to add functionality, which triggers alerts when the submit or reset buttons are clicked.

Syntax:

<input type="submit" class="submitButton" id="submitButton" value="Submit">

Example: The below example uses <input> tag to create a Form Submit button in HTML.

index.html
<!DOCTYPE html>
<html>

<head>
    <title>Example 2</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h3>Using input tag</h3>
    <form>
        <label for="username">Username:</label>
        <input type="text" id="username" 
               name="username" required>
        <label for="email">Email:</label>
        <input type="email" id="email" 
               name="email" required>
        <label for="password">Password:</label>
        <input type="password" id="password" 
               name="password" required>
        <input type="submit" class="submitButton" 
               id="submitButton" value="Submit">
        <input type="reset" class="resetButton" 
               id="resetButton" value="Reset">
    </form>

    <script>
        document.addEventListener(
              'DOMContentLoaded', function () {
            document.getElementById('submitButton').
            addEventListener('click', function () {
                alert('Submit button clicked!');
            });
            document.getElementById('resetButton').
            addEventListener('click', function () {
                alert('Reset button clicked!');
            });
        });
    </script>
</body>

</html>
style.css
h1 {
    color: green;
    text-align: center;
}

body {
    text-align: center;
}

form {
    display: inline-block;
    text-align: left;
    max-width: 400px;
    margin: 20px auto;
}

label {
    display: block;
    margin-bottom: 8px;
}

input[type="text"],
input[type="email"],
input[type="password"] {
    width: 100%;
    padding: 8px;
    margin-bottom: 12px;
    box-sizing: border-box;
}

.submitButton {
    background-color: #4caf50;
    color: white;
    padding: 10px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-right: 10px;
}

.resetButton {
    background-color: #f44336;
    color: white;
    padding: 10px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

button:hover,
.resetButton:hover {
    opacity: 0.8;
}

Output:

Output


Next Article

Similar Reads