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>
Nunjucks macro options
Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.
Some options are required for the macro to work; these are marked as "Required" in the option description.
If you’re using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
Name | Type | Description |
---|---|---|
name | string | Required. The name of the input, which is submitted with the form data. |
id | string | Required. The ID of the input. |
value | string | Optional initial value of the input. |
disabled | boolean | If |
describedBy | string | One or more element IDs to add to the |
label | object | Required. The label used by the file upload component. See label. |
hint | object | Can be used to add a hint to the file upload component. See hint. |
errorMessage | object | Can be used to add an error message to the file upload component. The error message component will not display if you use a falsy value for See error message. |
formGroup | object | Additional options for the form group containing the file upload component. See formGroup. |
classes | string | Classes to add to the file upload component. |
attributes | object | HTML attributes (for example data attributes) to add to the file upload component. |
Name | Type | Description |
---|---|---|
classes | string | Classes to add to the form group (for example to show error state for the whole group). |
attributes | object | HTML attributes (for example data attributes) to add to the form group. |
beforeInput | object | Content to add before the input used by the file upload component. See beforeInput. |
afterInput | object | Content to add after the input used by the file upload component. See afterInput. |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add after the input. If |
html | string | Required. HTML to add after the input. If |
Name | Type | Description |
---|---|---|
text | string | Required. Text to add before the input. If |
html | string | Required. HTML to add before the input. If |
Name | Type | Description |
---|---|---|
text | string | Required. If |
html | string | Required. If |
id | string | Optional ID attribute to add to the hint span tag. |
classes | string | Classes to add to the hint span tag. |
attributes | object | HTML attributes (for example data attributes) to add to the hint span tag. |
Name | Type | Description |
---|---|---|
text | string | Required. If |
html | string | Required. If |
for | string | The value of the |
isPageHeading | boolean | Whether the label also acts as the heading for the page. |
classes | string | Classes to add to the label tag. |
attributes | object | HTML attributes (for example data attributes) to add to the label tag. |
{% from "moduk/components/file-upload/macro.njk" import modukFileUpload -%}
{{ modukFileUpload({
id: "file-upload-1",
name: "file-upload-1",
label: {
text: "Upload a file"
}
}) -}}
See GOV.UK file upload component guidance for:
- when to use this component
- how it works
Changes from the GOV.UK version
MOD.UK Design System components are closely based on GOV.UK Design System components.
For this component we’ve changed the font.
Have you tested this component?
Let us know how we could improve this component or share your user research findings.
Email the MOD.UK Design System team at design-system@digital.mod.uk
Need help?
Email the MOD.UK Design System team at design-system@digital.mod.uk if you have questions or feedback.