How to Style HTML Input Placeholders In CSS

DISCLAIMER: This post may contain “affiliate” links to products and services I recommend. I’ll receive a small commission if you decide to purchase one of these products or services. I only recommend products I genuinely believe will help you in running your freelance business.

Let’s start with the HTML:

<form>
	<input type="text" placeholder="Enter your text here"><br>
	<textarea placeholder="Enter other text here"></textarea>
</form>

So, now we want to style the placeholders themselves.

If you want to keep it simple, most modern browsers support this:

::placeholder {
	color: #c90000;
}

You can use the ::placeholder pseudo-class like any other.

For older browser support it looks like this:

::-webkit-input-placeholder { /* WebKit, Blink, Edge */
	color: #c90000;
}
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
	color: #c90000;
	opacity: 1;
}
::-moz-placeholder { /* Mozilla Firefox 19+ */
	color: #c90000;
	opacity:	1;
}
:-ms-input-placeholder { /* Internet Explorer 10-11 */
	color: #c90000;
}
::-ms-input-placeholder { /* Microsoft Edge */
	color: #c90000;
}

::placeholder {
	color: #c90000;
}

So, let’s look at a real-world example:

A simple form. Nothing fancy, but notice the placeholder text for the required email field is a different color. This is one simple example of how you might use something like this.

Here’s the full HTML:

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>How to Style HTML Input Placeholders In CSS</title>
		<link rel="stylesheet" href="style.css">
	</head>
	<body>
		<form>
			<div class="form-group">
				<label for="name">Your name</label>
				<input type="text" name="name" class="text" id="name" placeholder="Enter your name here">
			</div>
			<div class="form-group">
				<label for="email">Your email</label>
				<input type="email" name="name" class="text email required" id="email" placeholder="Enter your email here (required)" required>
			</div>
			<div class="form-group">
				<input type="submit" value="Submit" class="button submit">
			</div>
		</form>
	</body>
</html>

And, here’s the full CSS:

html, body {
	margin: 0;
	padding: 0;
}

body {
	background: lightBlue;
	font-family: sans-serif;
}

form {
	width: 40vw;
	background: white;
	margin: 10vh auto;
	padding: 40px;
	border-radius: 1px;
}

.form-group {
	margin: 15px 0;
}

.form-group label {
	display: block;
	margin-bottom: 5px;
	color: #444;
}

.text {
	box-sizing: border-box;
	width: 100%;
	padding: 15px 10px;
	border: 1px solid lightGrey;
}

.text::placeholder {
	color: lightGrey;
	font-style: italic;
}

.text.required::placeholder {
	color: #c90000;
}

.button {
	border: 1px solid #333;
	background: #555;
	color: white;
	padding: 15px 40px;
	font-size: 18px;
}

So, there you go.

Now, speaking of real-world examples, I have a full course where we build a freelancer sales page from scratch using HTML, CSS, jQuery and a little PHP if you want to keep going with your learning.

In it, you’ll learn about CSS Grid, CSS transitions, making asynchronous requests using jQuery and more.

You can get access to it for nothing over on Skillshare.

Link for details is here: http://johnmorrisonline.com/webdesign

Later,

John

Do you want high-paying freelance clients?

I’ll show you what I learned over the last 15 years about building a 100K freelance business from complete scratch. What I did to land projects with Inc. Magazine, Tim Ferris, Lewis Howes, Michael Hyatt and others. Just enter your email address in the box below and let’s get started:

Leave a Reply on Twitter

Due to excessive spam, I’ve disabled comments on my website. If you have a question or would like to leave a comment, don’t hesitate to contact me on Twitter.

You might also like

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on reddit
Reddit
Share on pinterest
Pinterest
John Morris

JOHN MORRIS

I’m a 15-year veteran of freelance web development. I’ve worked with bestselling authors and average Joe’s next door. These days, I focus on helping other freelancers build their freelance business and their lifestyles.

The simple secret to high-paying freelance clients?

Enter your email below and I’ll show how to charge more and build a 100K freelance business from scratch:

Clients Like:

Inc. Magazine Logo
Lewis Howes Logo
Ray Edwards Logo

WHAT OTHERS ARE SAYING

Bradley Smith

John and I have worked together on numerous projects. John is very quick and efficient and was a pleasure to work with.

Lewis Howes

John is amazing at building membership sites. He converted one of my sites over from it’s existing (hardly working) platform over to the clean and simple to use WishList membership platform. I highly recommend using John and WishList for any of your membership site needs.

Lori Grant

John did an outstanding job on my project. I highly recommend him and look forward to working with him on future projects.

Thabo Motsoahae

John is one of the best instructors I have come across, I learned a lot from his online tutorials.

Chris Aitken

He significantly improved my site through his expert knowledge of PHP, CSS and Javascript. Would definitely recommend John to others.

Daniel Mohlendick

On the Freelancing on Upwork course: “This is by far the best course i have watched on Skillshare!! Thank you so much.”

Sukh Plaha

John is a fantastic and patient tutor, who is not just able to share knowledge and communicate it very effectively – but able to support one in applying it. However, I believe that John has a very rare ability to go further than just imparting knowledge and showing one how to apply it. He is able to innately provoke one’s curiosity when explaining and demonstrating concepts, to the extent that one can explore and unravel their own learning journey. Thanks very much John!