Components

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.

Primary options
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 true, file input will be disabled.

describedBy string

One or more element IDs to add to the aria-describedby attribute, used to provide additional descriptive information for screenreader users.

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 errorMessage, for example false or null.

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.

Options for formGroup
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.

Options for afterInput
Name Type Description
text string Required.

Text to add after the input. If html is provided, the text option will be ignored.

html string Required.

HTML to add after the input. If html is provided, the text option will be ignored.

Options for beforeInput
Name Type Description
text string Required.

Text to add before the input. If html is provided, the text option will be ignored.

html string Required.

HTML to add before the input. If html is provided, the text option will be ignored.

Options for hint
Name Type Description
text string Required.

If html is set, this is not required. Text to use within the hint. If html is provided, the text option will be ignored.

html string Required.

If text is set, this is not required. HTML to use within the hint. If html is provided, the text option will be ignored.

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.

Options for label
Name Type Description
text string Required.

If html is set, this is not required. Text to use within the label. If html is provided, the text option will be ignored.

html string Required.

If text is set, this is not required. HTML to use within the label. If html is provided, the text option will be ignored.

for string

The value of the for attribute, the ID of the input the label is associated with.

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.