In HTML, forms are used to collect user input. The <form>
element is used to create a form, and inside the form, we can use <input>
elements of type submit
and reset
to create submit and reset buttons respectively.
<input type="submit">
or <button type="submit">
.<input type="reset">
or <button type="reset">
.CSS (Cascading Style Sheets) is used to style HTML elements, including buttons. Color can be specified in CSS using different color models such as named colors (e.g., blue
), hexadecimal values (e.g., #0000FF
), RGB values (e.g., rgb(0, 0, 255)
), or HSL values (e.g., hsl(240, 100%, 50%)
).
First, let’s create a simple HTML form with a submit button:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF - 8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blue Submit Button</title>
</head>
<body>
<form action="#">
<input type="text" placeholder="Enter some text">
<input type="submit" value="Submit">
</form>
</body>
</html>
To make the submit button blue, we can use CSS. We’ll target the input[type="submit"]
selector.
input[type="submit"] {
background-color: blue;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
}
Combining the HTML and CSS:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF - 8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blue Submit Button</title>
<style>
input[type="submit"] {
background-color: blue;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
}
</style>
</head>
<body>
<form action="#">
<input type="text" placeholder="Enter some text">
<input type="submit" value="Submit">
</form>
</body>
</html>
We can also add some hover and active states to the button to enhance the user experience:
input[type="submit"] {
background-color: blue;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
transition: background - color 0.3s ease;
}
input[type="submit"]:hover {
background-color: darkblue;
}
input[type="submit"]:active {
background-color: lightblue;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF - 8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reset Button Color</title>
</head>
<body>
<form action="#">
<input type="text" placeholder="Enter some text">
<input type="reset" value="Reset">
</form>
</body>
</html>
We can use CSS to style the reset button. Let’s give it a different color, for example, red.
input[type="reset"] {
background-color: red;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
}
input[type="reset"]:hover {
background-color: darkred;
}
input[type="reset"]:active {
background-color: lightcoral;
}
Combining the HTML and CSS:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF - 8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reset Button Color</title>
<style>
input[type="reset"] {
background-color: red;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
}
input[type="reset"]:hover {
background-color: darkred;
}
input[type="reset"]:active {
background-color: lightcoral;
}
</style>
</head>
<body>
<form action="#">
<input type="text" placeholder="Enter some text">
<input type="reset" value="Reset">
</form>
</body>
</html>
em
for sizing.<button>
elements instead of <input>
elements when possible, as they are more flexible and semantically correct. For example:<form action="#">
<input type="text" placeholder="Enter some text">
<button type="submit">Submit</button>
<button type="reset">Reset</button>
</form>
button[type="submit"] {
background-color: blue;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
}
button[type="reset"] {
background-color: red;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
}
In this blog post, we’ve explored how to create and style blue submit buttons and reset buttons in HTML and CSS. We’ve covered the fundamental concepts, usage methods, and provided clear code examples. By following common and best practices, you can create buttons that not only look good but also provide a great user experience. Whether you are building a simple form or a complex web application, having well - designed buttons is essential for effective user interaction.