How to Style HTML Input Placeholders In CSS

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 more freelance clients?

I’ll show you what I learned over the last 15 years to grind out (from absolute scratch) a backlog of new clients wanting to hire you. Who your best client prospect are, what services you should be offering them, where to find them and more. Just enter your email address in the box below and let’s get started:

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.

You might also like

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Do you want more freelance clients?

Enter your email below to get started building your system for consistently bringing in new freelance clients:

WHAT OTHERS ARE SAYING

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!

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.

Ray Edwards

I recommend John every chance I get. If every person I worked with were as committed to excellence, punctuality, value, and unquestionable integrity… the world would be a better place. Highest recommendation.

Daniel Mohlendick

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

Thabo Motsoahae

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

Bob Patterson

Not only is John a very talented programmer and developer, he is also an excellent communicator. He has a talent for taking complex subjects and communicating them in terms that anyone can understand. This is a rare combination. This ability has enabled me to take my skills and knowledge to the next level. Thank you John for for all that you do.

Close Menu