# File Field

Mero UI 1.1.0 · Forms

Choose a file with a native file input styled like Mero buttons.

[Integration patterns and API reference](../llms-patterns.txt)

## Default

Use it in a plain <form method="post" enctype="multipart/form-data">. The browser shows the chosen file name next to the button. For your own echo, such as a list of several files, put an element with data-mero-file-name in the same mero-field.

Page assets

```html
<link rel="stylesheet" href="/mero.css">
<script defer src="/mero.js"></script>
```

Template

````html
<div class="mero-scope" data-mero-scope>
  <div class="mero-field">
    <label class="mero-label" for="demo-file-field">Favicon</label>
    <input class="mero-file" id="demo-file-field" name="favicon" type="file" accept="image/png,image/svg+xml" aria-describedby="demo-file-field-hint">
    <p class="mero-description" id="demo-file-field-hint">PNG or SVG, at least 512 px square.</p>
  </div>
</div>
````

## Error

Ask for a different file after the server rejected the last one.

Render aria-invalid and the error from your server. The browser cannot keep the rejected file, so the person chooses it again.

Page assets

```html
<link rel="stylesheet" href="/mero.css">
<script defer src="/mero.js"></script>
```

Template

````html
<div class="mero-scope" data-mero-scope>
  <div class="mero-field">
    <label class="mero-label" for="demo-file-error">Watermark</label>
    <input class="mero-file" id="demo-file-error" name="watermark" type="file" accept="image/png" aria-invalid="true" aria-describedby="demo-file-error-message">
    <p class="mero-field-error" id="demo-file-error-message">The watermark must be a PNG under 1 MB.</p>
  </div>
</div>
````
