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

You might also like

Get off your knees

Stop acting like your client’s servant — like you’re there to kowtow to their every whim and wish and you’re lucky they’ve graced you with

Read More »

Chicks dig this s***

Saw this scrub on Twitter post this namby-pamby bullshizen: === I will NEVER be impressed by your money, car, looks, social status or job title.

Read More »
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 secrets to high-paying freelance clients

What makes clients willing to pay $5,000, $10,000 even $20,000 and up for your services? Download and install my mobile app and I’ll show you. It’s free. Just click the button below:

Clients Like:

Inc. Magazine Logo
Lewis Howes Logo
Ray Edwards Logo

WHAT OTHERS ARE SAYING

Steve Dimmick

Steve Dimmick

John has provided expert knowledge and advice on multiple occasions that have helped me better serve my clients. John is a Rockstar!

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.

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.

Daniel Mohlendick

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

Xan Barksdale

Xan Barksdale

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

Thabo Motsoahae

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

Andrew Malone

Andrew Malone

John Morris is exceptional in his ability to give focused insight into Freelancing and starting one’s business. His direct methods inspire confidence in his honesty.

Chris Aitken

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

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!

Michael Skye

Michael Skye

John is a man of integrity, who gives generously of himself to projects and people he cares about.

Jason Rumley

Jason Rumley

John has a habit of over-delivering on the expectations he sets up. That’s why he’s the best.

Jim DeJonge

Jim DeJonge

John has a relaxed and engaging manner. His advice is solid and the explanations are well thought out.