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 Descriptionfile_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>
<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>
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