2018-09-30 23:01:58 +01:00
---
id: bad87fee1348bd9aedc08830
title: Use HTML5 to Require a Field
challengeType: 0
videoUrl: 'https://scrimba.com/p/pVMPUv/cMd4EcQ'
2019-07-31 11:32:23 -07:00
forumTopicId: 18360
2021-01-13 03:31:00 +01:00
dashedName: use-html5-to-require-a-field
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2018-09-30 23:01:58 +01:00
You can require specific form fields so that your user will not be able to submit your form until he or she has filled them out.
2020-11-27 19:02:05 +01:00
For example, if you wanted to make a text input field required, you can just add the attribute `required` within your `input` element, like this: `<input type="text" required>`
# --instructions--
Make your text `input` a `required` field, so that your user can't submit the form without completing this field.
2018-09-30 23:01:58 +01:00
Then try to submit the form without inputting any text. See how your HTML5 form notifies you that the field is required?
2020-11-27 19:02:05 +01:00
# --hints--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
Your text `input` element should have the `required` attribute.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert($('input').prop('required'));
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
# --seed--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
## --seed-contents--
2018-09-30 23:01:58 +01:00
```html
<h2>CatPhotoApp</h2>
<main>
<p>Click here to view more <a href="#">cat photos</a>.</p>
2018-10-08 01:01:53 +01:00
2021-04-26 19:04:53 +02:00
<a href="#"><img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
2021-04-26 19:04:53 +02:00
<form action="https://www.freecatphotoapp.com/submit-cat-photo">
2018-09-30 23:01:58 +01:00
<input type="text" placeholder="cat photo URL">
<button type="submit">Submit</button>
</form>
</main>
```
2020-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
2019-04-22 02:07:05 -04:00
```html
<h2>CatPhotoApp</h2>
<main>
<p>Click here to view more <a href="#">cat photos</a>.</p>
2021-04-26 19:04:53 +02:00
<a href="#"><img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>
2019-04-22 02:07:05 -04:00
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
2021-04-26 19:04:53 +02:00
<form action="https://www.freecatphotoapp.com/submit-cat-photo">
2019-04-22 02:07:05 -04:00
<input type="text" required placeholder="cat photo URL">
<button type="submit">Submit</button>
</form>
</main>
2018-09-30 23:01:58 +01:00
```