In this article I will explain with an example, how to use INPUT "type=file" to accept CSV file in HTML.
The accept attribute is a new attribute available in HTML5.
The following HTML Markup consists of:
FileUpload – For uploading file.
The HTML5 INPUT FileUpload has been set with the following attribute.
accept - This attribute allows user to select only specified type of files from the Choose File dialog box.
Note: Please note accepting all files is default behavior and hence even if the accept attribute is not specified, by default, it will accept all files.
For example, in the following code, the HTML5 INPUT FileUpload will only allow user to select CSV file i.e. file with extension csv.
<meta charset="utf-8" />
<input type="file" accept=".csv" />
The above code has been tested in the following browsers only in versions that support HTML5.
* All browser logos displayed above are property of their respective owners.