Back to Freecodecamp

Add Placeholder Text to a Text Field

curriculum/challenges/english/blocks/basic-html-and-html5/bad87fee1348bd9aedf08830.md

latest2.2 KB
Original Source

--description--

Placeholder text is what is displayed in your input element before your user has inputted anything.

You can create placeholder text like so:

html
<input type="text" placeholder="this is placeholder text">

Note: Remember that input is a void element.

--instructions--

Set the placeholder value of your text input to "cat photo URL".

--hints--

You should add a placeholder attribute to the existing text input element.

js
assert.notEmpty(document.querySelectorAll('input[placeholder]'));

You should set the value of your placeholder attribute to cat photo URL.

js
assert.exists(document.querySelector('input'));
assert.exists(document.querySelector('input').getAttribute('placeholder'));
const placeholder = document.querySelector('input').getAttribute('placeholder');
assert.match(placeholder,/cat\s+photo\s+URL/gi);

The finished input element should not have a closing tag.

js
assert.notMatch(code,/<input.*\/?>.*<\/input>/gi);

The finished input element should have valid syntax.

js
assert.notEmpty(document.querySelectorAll('input[type=text]'));

--seed--

--seed-contents--

html
<h2>CatPhotoApp</h2>
<main>
  <p>Click here to view more <a href="#">cat photos</a>.</p>

  <a href="#"></a>

  <p>Things cats love:</p>
  <ul>
    <li>catnip</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>
  <input type="text">
</main>

--solutions--

html
<h2>CatPhotoApp</h2>
<main>
  <p>Click here to view more <a href="#">cat photos</a>.</p>
  
  <a href="#"></a>
  
  <p>Things cats love:</p>
  <ul>
    <li>catnip</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>
  <input type="text" placeholder="cat photo URL">
</main>