Skip to content

Commit

Permalink
Convert file contents to Markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
wbamberg committed Sep 27, 2021
1 parent 875f11a commit 831fd0a
Show file tree
Hide file tree
Showing 234 changed files with 29,559 additions and 25,119 deletions.
598 changes: 288 additions & 310 deletions files/en-us/web/html/applying_color/index.md

Large diffs are not rendered by default.

226 changes: 110 additions & 116 deletions files/en-us/web/html/attributes/accept/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,156 +9,150 @@ tags:
- Input
- Reference
---
<p>{{HTMLSidebar}}</p>
{{HTMLSidebar}}

<p>The <strong><code>accept</code></strong> attribute takes as its value a comma-separated list of one or more file types, or {{anch("Unique file type specifiers", "unique file type specifiers")}}, describing which file types to allow.</p>
The **`accept`** attribute takes as its value a comma-separated list of one or more file types, or {{anch("Unique file type specifiers", "unique file type specifiers")}}, describing which file types to allow.

<p>The accept property is an attribute of the {{HTMLElement("input/file", "file")}} {{htmlelement("input")}} type. It was supported on the {{htmlelement("form")}} element, but was removed in favor of {{HTMLElement("input/file", "file")}} in HTML5.</p>
The accept property is an attribute of the {{HTMLElement("input/file", "file")}} {{htmlelement("input")}} type. It was supported on the {{htmlelement("form")}} element, but was removed in favor of {{HTMLElement("input/file", "file")}} in HTML5.

<p>Because a given file type may be identified in more than one manner, it's useful to provide a thorough set of type specifiers when you need files of specific type, or use the wild card to denote a type of any format is acceptable.</p>
Because a given file type may be identified in more than one manner, it's useful to provide a thorough set of type specifiers when you need files of specific type, or use the wild card to denote a type of any format is acceptable.

<p>For instance, there are a number of ways Microsoft Word files can be identified, so a site that accepts Word files might use an <code>&lt;input&gt;</code> like this:</p>
For instance, there are a number of ways Microsoft Word files can be identified, so a site that accepts Word files might use an `<input>` like this:

<pre class="brush: html">&lt;input type="file" id="docpicker"
accept=".doc,.docx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document"&gt;</pre>
```html
<input type="file" id="docpicker"
accept=".doc,.docx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document">
```

<p>Whereas if you're accepting a media file, you may want to be include any format of that media type:</p>
Whereas if you're accepting a media file, you may want to be include any format of that media type:

<pre class="brush: html">&lt;input type="file" id="soundFile" accept="audio/*"&gt;
&lt;input type="file" id="videoFile" accept="video/*"&gt;
&lt;input type="file" id="imageFile" accept="image/*"&gt;</pre>
```html
<input type="file" id="soundFile" accept="audio/*">
<input type="file" id="videoFile" accept="video/*">
<input type="file" id="imageFile" accept="image/*">
```

<p>The <code>accept</code> attribute doesn't validate the types of the selected files; it provides hints for browsers to guide users towards selecting the correct file types. It is still possible (in most cases) for users to toggle an option in the file chooser that makes it possible to override this and select any file they wish, and then choose incorrect file types.</p>
The `accept` attribute doesn't validate the types of the selected files; it provides hints for browsers to guide users towards selecting the correct file types. It is still possible (in most cases) for users to toggle an option in the file chooser that makes it possible to override this and select any file they wish, and then choose incorrect file types.

<p>Because of this, you should make sure that expected requirement is validated server-side.</p>
Because of this, you should make sure that expected requirement is validated server-side.

<h2 id="Examples">Examples</h2>
## Examples

<p>When set on a file input type, the native file picker that opens up should only enable selecting files of the correct file type. Most operating systems lighten the files that don't match the criteria and aren't selectable.</p>
When set on a file input type, the native file picker that opens up should only enable selecting files of the correct file type. Most operating systems lighten the files that don't match the criteria and aren't selectable.

<pre class="brush: html">&lt;p&gt;
&lt;label for="soundFile"&gt;Select an audio file:&lt;/label&gt;
&lt;input type="file" id="soundFile" accept="audio/*"&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;label for="videoFile"&gt;Select a video file:&lt;/label&gt;
&lt;input type="file" id="videoFile" accept="video/*"&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;label for="imageFile"&gt;Select some images:&lt;/label&gt;
&lt;input type="file" id="imageFile" accept="image/*" multiple&gt;
&lt;/p&gt;</pre>
```html
<p>
<label for="soundFile">Select an audio file:</label>
<input type="file" id="soundFile" accept="audio/*">
</p>
<p>
<label for="videoFile">Select a video file:</label>
<input type="file" id="videoFile" accept="video/*">
</p>
<p>
<label for="imageFile">Select some images:</label>
<input type="file" id="imageFile" accept="image/*" multiple>
</p>
```

<p>{{EmbedLiveSample('Examples', '100%', 200)}}</p>
{{EmbedLiveSample('Examples', '100%', 200)}}

<p>Note the last example allows you to select multiple images. See the <code><a href="multiple">multiple</a></code> attribute for more information.</p>
Note the last example allows you to select multiple images. See the [`multiple`](multiple) attribute for more information.

<h2 id="Unique_file_type_specifiers">Unique file type specifiers</h2>
## Unique file type specifiers

<p>A <strong>unique file type specifier</strong> is a string that describes a type of file that may be selected by the user in an {{HTMLElement("input")}} element of type <code>file</code>. Each unique file type specifier may take one of the following forms:</p>
A **unique file type specifier** is a string that describes a type of file that may be selected by the user in an {{HTMLElement("input")}} element of type `file`. Each unique file type specifier may take one of the following forms:

<ul>
<li>A valid case-insensitive filename extension, starting with a period (".") character. For example: <code>.jpg</code>, <code>.pdf</code>, or <code>.doc</code>.</li>
<li>A valid MIME type string, with no extensions.</li>
<li>The string <code>audio/*</code> meaning "any audio file".</li>
<li>The string <code>video/*</code> meaning "any video file".</li>
<li>The string <code>image/*</code> meaning "any image file".</li>
</ul>
* A valid case-insensitive filename extension, starting with a period (".") character. For example: `.jpg`, `.pdf`, or `.doc`.
* A valid MIME type string, with no extensions.
* The string `audio/*` meaning "any audio file".
* The string `video/*` meaning "any video file".
* The string `image/*` meaning "any image file".

<p>The <code>accept</code> attribute takes as its value a string containing one or more of these unique file type specifiers, separated by commas. For example, a file picker that needs content that can be presented as an image, including both standard image formats and PDF files, might look like this:</p>
The `accept` attribute takes as its value a string containing one or more of these unique file type specifiers, separated by commas. For example, a file picker that needs content that can be presented as an image, including both standard image formats and PDF files, might look like this:

<pre class="brush: html">&lt;input type="file" accept="image/*,.pdf"&gt;</pre>
```html
<input type="file" accept="image/*,.pdf">
```

<h2 id="Using_file_inputs">Using file inputs</h2>
## Using file inputs

<h3 id="A_basic_example">A basic example</h3>
### A basic example

<pre class="brush: html">&lt;form method="post" enctype="multipart/form-data"&gt;
&lt;div&gt;
&lt;label for="file"&gt;Choose file to upload&lt;/label&gt;
&lt;input type="file" id="file" name="file" multiple&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;button&gt;Submit&lt;/button&gt;
&lt;/div&gt;
&lt;/form&gt;</pre>
```html
<form method="post" enctype="multipart/form-data">
<div>
<label for="file">Choose file to upload</label>
<input type="file" id="file" name="file" multiple>
</div>
<div>
<button>Submit</button>
</div>
</form>
```

<pre class="brush: css hidden">div {
```css hidden
div {
margin-bottom: 10px;
}</pre>
}
```

<p>This produces the following output:</p>
This produces the following output:

<p>{{EmbedLiveSample('A_basic_example', 650, 60)}}</p>
{{EmbedLiveSample('A_basic_example', 650, 60)}}

<div class="note">
<p><strong>Note:</strong> You can find this example on GitHub too — see the <a href="https://github.com/mdn/learning-area/blob/master/html/forms/file-examples/simple-file.html">source code</a>, and also <a href="https://mdn.github.io/learning-area/html/forms/file-examples/simple-file.html">see it running live</a>.</p>
</div>
> **Note:** You can find this example on GitHub too — see the [source code](https://github.com/mdn/learning-area/blob/master/html/forms/file-examples/simple-file.html), and also [see it running live](https://mdn.github.io/learning-area/html/forms/file-examples/simple-file.html).
<p>Regardless of the user's device or operating system, the file input provides a button that opens up a file picker dialog that allows the user to choose a file.</p>
Regardless of the user's device or operating system, the file input provides a button that opens up a file picker dialog that allows the user to choose a file.

<p>Including the <code><a href="multiple">multiple</a></code> attribute, as shown above, specifies that multiple files can be chosen at once. The user can choose multiple files from the file picker in any way that their chosen platform allows (e.g. by holding down <kbd>Shift</kbd> or <kbd>Control</kbd>, and then clicking). If you only want the user to choose a single file per <code>&lt;input&gt;</code>, omit the <code>multiple</code> attribute.</p>
Including the [`multiple`](multiple) attribute, as shown above, specifies that multiple files can be chosen at once. The user can choose multiple files from the file picker in any way that their chosen platform allows (e.g. by holding down <kbd>Shift</kbd> or <kbd>Control</kbd>, and then clicking). If you only want the user to choose a single file per `<input>`, omit the `multiple` attribute.

<h3 id="Limiting_accepted_file_types">Limiting accepted file types</h3>
### Limiting accepted file types

<p>Often you won't want the user to be able to pick any arbitrary type of file; instead, you often want them to select files of a specific type or types. For example, if your file input lets users upload a profile picture, you probably want them to select web-compatible image formats, such as {{Glossary("JPEG")}} or {{Glossary("PNG")}}.</p>
Often you won't want the user to be able to pick any arbitrary type of file; instead, you often want them to select files of a specific type or types. For example, if your file input lets users upload a profile picture, you probably want them to select web-compatible image formats, such as {{Glossary("JPEG")}} or {{Glossary("PNG")}}.

<p>Acceptable file types can be specified with the {{htmlattrxref("accept","input/file")}} attribute, which takes a comma-separated list of allowed file extensions or MIME types. Some examples:</p>
Acceptable file types can be specified with the {{htmlattrxref("accept","input/file")}} attribute, which takes a comma-separated list of allowed file extensions or MIME types. Some examples:

<ul>
<li><code>accept="image/png"</code> or <code>accept=".png"</code> — Accepts PNG files.</li>
<li><code>accept="image/png, image/jpeg"</code> or <code>accept=".png, .jpg, .jpeg"</code> — Accept PNG or JPEG files.</li>
<li><code>accept="image/*"</code> — Accept any file with an <code>image/*</code> MIME type. (Many mobile devices also let the user take a picture with the camera when this is used.)</li>
<li><code>accept=".doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document"</code> — accept anything that smells like an MS Word document.</li>
</ul>
* `accept="image/png"` or `accept=".png"` — Accepts PNG files.
* `accept="image/png, image/jpeg"` or `accept=".png, .jpg, .jpeg"` — Accept PNG or JPEG files.
* `accept="image/*"` — Accept any file with an `image/*` MIME type. (Many mobile devices also let the user take a picture with the camera when this is used.)
* `accept=".doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document"` — accept anything that smells like an MS Word document.

<p>Let's look at a more complete example:</p>
Let's look at a more complete example:

<pre class="brush: html">&lt;form method="post" enctype="multipart/form-data"&gt;
&lt;div&gt;
&lt;label for="profile_pic"&gt;Choose file to upload&lt;/label&gt;
&lt;input type="file" id="profile_pic" name="profile_pic"
accept=".jpg, .jpeg, .png"&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;button&gt;Submit&lt;/button&gt;
&lt;/div&gt;
&lt;/form&gt;</pre>
```html
<form method="post" enctype="multipart/form-data">
<div>
<label for="profile_pic">Choose file to upload</label>
<input type="file" id="profile_pic" name="profile_pic"
accept=".jpg, .jpeg, .png">
</div>
<div>
<button>Submit</button>
</div>
</form>
```

<pre class="brush: css hidden">div {
```css hidden
div {
margin-bottom: 10px;
}</pre>

<p>{{EmbedLiveSample('Limiting_accepted_file_types', 650, 60)}}</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('HTML WHATWG', 'input.html#attr-input-accept', 'accept attribute')}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
</tr>
<tr>
<td>{{SpecName('HTML5.1', 'sec-forms.html#attr-input-accept', 'accept attribute')}}</td>
<td>{{Spec2('HTML5.1')}}</td>
</tr>
</tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{Compat("html.elements.attribute.accept")}}</p>

<h2 id="See_also">See also</h2>

<ul>
<li><a href="/en-US/docs/Web/API/File/Using_files_from_web_applications">Using files from web applications</a></li>
<li><a href="/en-US/docs/Web/API/File">File API</a></li>
</ul>
}
```

{{EmbedLiveSample('Limiting_accepted_file_types', 650, 60)}}

## Specifications

| Specification | Status |
| -------------------------------------------------------------------------------------------------------- | -------------------------------- |
| {{SpecName('HTML WHATWG', 'input.html#attr-input-accept', 'accept attribute')}} | {{Spec2('HTML WHATWG')}} |
| {{SpecName('HTML5.1', 'sec-forms.html#attr-input-accept', 'accept attribute')}} | {{Spec2('HTML5.1')}} |

## Browser compatibility

{{Compat("html.elements.attribute.accept")}}

## See also

* [Using files from web applications](/en-US/docs/Web/API/File/Using_files_from_web_applications)
* [File API](/en-US/docs/Web/API/File)
Loading

0 comments on commit 831fd0a

Please sign in to comment.