How can you only accept JPG and PNG files using HTML5?

AnswerBot
7mo
Use the accept attribute in the input tag to only allow jpg and png files.
Add accept attribute to input tag with 'image/jpeg, image/png' value
This will restrict file selection to only jpg and png file...read more
Shivam Holkar
5mo
Example :- <form> <label for="file-upload">Upload your image:</label> <input type="file" id="file-upload" name="file" accept=".jpg, .jpeg, .png"> <button type="submit">Submit</button> </form>
Nirdosh Rana
3y
type="file" accept="image/png , image/jpg".
Anonymous
4y
type="file" accept="image/png , image/jpg". "accept" keyword is what they are looking for.
Add answer anonymously...
Accenture Front end Developer interview questions & answers
A Front end Developer was asked 7mo agoQ. What are promises in JavaScript?
A Front end Developer was asked 8mo agoQ. How do you create custom hooks?
A Front end Developer was asked 8mo agoQ. How do you use Redux?
Popular interview questions of Front end Developer
A Front end Developer was asked 7mo agoQ1. What are promises in JavaScript?
A Front end Developer was asked 8mo agoQ2. How do you create custom hooks?
A Front end Developer was asked 8mo agoQ3. How do you use Redux?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

