File upload
Help users select and upload a file.
<div class="govuk-form-group">
<label class="govuk-label" for="file-upload-1">
Upload a file
</label>
<input class="govuk-file-upload" id="file-upload-1" name="file-upload-1" type="file">
</div>
{% from "file-upload/macro.njk" import govukFileUpload %}
{{ govukFileUpload({
id: "file-upload-1",
name: "file-upload-1",
label: {
text: "Upload a file"
}
}) }}
When to use this component
You should only ask users to upload something if it’s critical to the delivery of your service.
How it works
There are 2 ways to use the file upload component. You can use HTML or, if you’re using Nunjucks or the GOV.UK Prototype Kit, you can use the Nunjucks macro.
<div class="govuk-form-group">
<label class="govuk-label" for="file-upload-1">
Upload a file
</label>
<input class="govuk-file-upload" id="file-upload-1" name="file-upload-1" type="file">
</div>
{% from "file-upload/macro.njk" import govukFileUpload %}
{{ govukFileUpload({
id: "file-upload-1",
name: "file-upload-1",
label: {
text: "Upload a file"
}
}) }}
Error messages
Error messages should be styled like this:
<div class="govuk-form-group govuk-form-group--error">
<label class="govuk-label" for="file-upload-1">
Upload a file
</label>
<span id="file-upload-1-error" class="govuk-error-message">
<span class="govuk-visually-hidden">Error:</span> The CSV must be smaller than 2MB
</span>
<input class="govuk-file-upload govuk-file-upload--error" id="file-upload-1" name="file-upload-1" type="file" aria-describedby="file-upload-1-error">
</div>
{% from "file-upload/macro.njk" import govukFileUpload %}
{{ govukFileUpload({
id: "file-upload-1",
name: "file-upload-1",
label: {
text: "Upload a file"
},
errorMessage: {
text: "The CSV must be smaller than 2MB"
}
}) }}
Make sure errors follow the guidance in error message and have specific error messages for specific error states.
If no file has been selected
Say ‘Select a [whatever they need to select]’.
For example, ‘Select a report’.
If the file is the wrong file type
Say ‘The selected file must be a [list of file types]’.
For example, ‘The selected file must be a CSV or ODS’ or ‘The selected file must be a JPG, BMP, PNG, TIF or PDF’.
If the file is too big
Say ‘The selected file must be smaller than [largest file size]’.
For example, ‘The selected file must be smaller than 2MB’.
If the file is empty
Say ‘The selected file is empty’.
If the file contains a virus
Say ‘The selected file contains a virus’.
If the file is password protected
Say ‘The selected file is password protected’.
If there was a problem and the file was not uploaded
Say ‘The selected file could not be uploaded – try again’.
If there is a limit on how many files the user can select
Say ‘You can only select up to [highest number] files at the same time’.
For example, ‘You can only select up to 10 files at the same time’.
If the file is not in a template that must be used or the template has been changed
Say ‘The selected file must use the template’.
Research on this component
Read a blog post about design tips for helping users upload things.
Help improve this page
To help make sure the File upload page is useful, relevant and up to date, you can:
- share research or feedback about the File upload component on GitHub
- propose a change to this page - read more about how to propose changes in GitHub
Need help?
If you’ve got a question about the GOV.UK Design System you can contact the team: