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:

How to Style HTML Input Placeholders In CSS 1

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

You might also like

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.

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

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.”

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.

Thabo Motsoahae

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

Xan Barksdale

Xan Barksdale

Very professional worker who is extremely knowledgable in WordPress and Wishlist Member. I would definitely hire again.

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.

Lori Grant

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

Close Menu