How to make a placeholder for select box in HTML

featured Image

In this article, we will see how to add a placeholder in the <select> tag for multiple dropdowns of HTML.

To add a placeholder to <select> dropdown, we have to use the <option> tag and add disabled, hidden, and selected attributes to it.

The placeholder attribute is used to indicate what type of value is expected from a user.

Here is an example of using placeholder attributes to add placeholder text in a form.

<form>
    <input placeholder="Enter Name" />
    <textarea placeholder="Enter your message" />
</form>

The output will be like this,

make placeholder for select box in HTML

However, in < select > element we do not get the placeholder attribute to write the text.

So what we can do is use the < option > tag along with the disabled and selected attributes to write the placeholder text in it.

Example:

<select>
  <option value="" disabled selected hidden>Select a color</option>
  <option value="blue">Blue</option>
  <option value="green">Green</option>
  <option value="red">Red</option>
  <option value="yellow">Yellow</option>
</select>

The disabled attribute make the option unable to select from the options.

The selected attribute specifies the option that should be pre-selected when the page loads.

The hidden attribute hides the option when we open the drop-down from the < select > box on a page.

Related Posts

git commands with example

Top 40 Git commands with Examples

GitHub has become an essential tool for developers to manage, store, and collaborate with other developers on software projects. With its simple powerful git-based version control system, GitHub allows users…

Read more
Check GitHub Account in the Terminal

Check GitHub Account in the Terminal

GitHub is an integral tool for developers to store, manage, and collaborate on software projects with other developers. And as we work more and more in the command line it…

Read more
featured Image

How to make list of objects in Netlify CMS using list and object Widget

Here in this Netlify CMS tutorial we will how easily we can make a list of objects using list and object widgets. This will allow us to add multiple objects…

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *