A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/html/html-input-accept-attribute/ below:

HTML < input> accept Attribute

HTML < input> accept Attribute

Last Updated : 12 Jul, 2025

The HTML <input> accept attribute is used to control the type of files that can be selected for input, restricting the file selection to specific formats such as image/* for images or .pdf for PDF files.

Syntax:  

<input accept = "file_extension | audio/* | video/* | image/* | media_type">
HTML
<html>
  <body>
    <form>
      <label for="fileUpload">Upload an image file:</label>
      <input type="file" id="fileUpload" name="fileUpload" accept="image/*">
      <input type="submit" value="Submit">
    </form>
  </body>
</html>

Attribute Values:

Value Description

file_extension

Specify the file extension(s) like .gif, .jpg, .png, .doc) the user can pick from.

audio/*

The user can pick all sound files.

image/*

A valid media type, with no parameters. Look at IANA Media Types for a complete list of standard media types.

media_type

A valid media type without parameters.

More example of HTML <input> accept Attribute

HTML <input> accept Attribute html
<html >
  <body>
    <form>
      <label for="imageUpload">Upload an image (JPEG or PNG):</label>
      <input type="file" id="imageUpload" name="imageUpload" accept=".jpeg, .jpg, .png">
      <input type="submit" value="Submit">
    </form>
  </body>
</html>
Styled File Input for PDF Documents HTML
<html>
<head>
	<style>
		.file-input {
			display: inline-block;
			padding: 10px 20px;
			font-size: 16px;
			cursor: pointer;
			background-color: #4CAF50;
			color: white;
			border: none;
			border-radius: 4px;
		}
		.file-input:hover {
			background-color: #45a049;
		}
		#pdfUpload {
			display: none;
		}
	</style>
</head>
<body>
	<form>
		<label for="pdfUpload" class="file-input">Choose a PDF file</label>
		<input type="file" id="pdfUpload" name="pdfUpload" accept="application/pdf">
		<input type="submit" value="Submit">
	</form>
</body>
</html>
Best Practices for Using the HTML <input> accept Attribute:

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4