Your resource for web content, online publishing
and the distribution of digital products.
S M T W T F S
 
 
1
 
2
 
3
 
4
 
5
 
6
 
7
 
8
 
9
 
 
 
12
 
13
 
14
 
15
 
16
 
17
 
18
 
19
 
20
 
21
 
22
 
23
 
24
 
25
 
26
 
27
 
28
 
29
 
30
 
31
 
 
 

Accessible Custom File Upload

DATE POSTED:October 11, 2024

The motivation for writing this article is to provide clear instructions on how to create a file upload that looks attractive. The native button looks very minimalistic, but it can be improved.

Native upload file

Unfortunately, there is no browser API that allows you to open the upload dialog without the input tag, so let's clarify how to do this.

\

  • Pure JS - so it can be adapted to any framework;
  • No native upload button - we want custom button instead
  • Accessibility - strong trend of last several years
Let’s Make a Pretty Button

As I mentioned earlier, we still need to render an input with type="file" to support the browser API. Since we don’t want it to be visible, let’s hide it.

\ Here’s a code example in pure HTML/CSS/JS:

No file selected

\

Important Details
  1. Use semantic HTML tags. This will help readers understand the job better;
  2. For uploaded files, use role="status" and aria-live="polite". This way, the file upload message is accessible to users;
  3. Adding a trash icon with an aria-label helps screen readers identify its purpose, making the button more accessible;
  4. Using aria-describedby lets screen readers read content from another element, providing extra details about the component.

\

Screenshot for new button

File upload button

Conclusion

With the above implementation, you can create an accessible and customizable file upload button. The design ensures the button looks good while maintaining accessibility standards. \n

The code and explanation should now be easier to read with corrected spelling and syntax.