📜  HTML<input type=”image”>(1)

📅  最后修改于: 2023-12-03 15:01:18.187000             🧑  作者: Mango

HTML Image Input

HTML <input type="image"> is a self-closing tag that displays an image as a submit button. When the image is clicked, the form will be submitted to the server.

Syntax
<input type="image" src="image_source" alt="alternative_text" />
  • type="image" specifies the type of input element as an image submit button.
  • src specifies the source URL of the image.
  • alt specifies the alternative text of the image for accessibility purposes.
Example
<form action="submit.php" method="post">
  <input type="text" name="username" placeholder="Username">
  <br>
  <input type="password" name="password" placeholder="Password">
  <br>
  <input type="image" src="submit_button.png" alt="Submit">
</form>

In the above example, an image submit button is displayed along with a text input and a password input. When the image is clicked, the form data will be submitted to submit.php.

Notes
  • Unlike <input type="submit">, <input type="image"> does not display a default value or text. The image itself is the submit button.
  • The alt attribute is important for accessibility purposes, as it provides a text alternative for the image in case the image cannot be displayed or identified by screen readers.