This CSS will style the “Validation errors” message box and the “Thank you for your message” message for the Contact Form 7 WordPress plugin.
By default, Contact Form 7 shows this error message when the contact form is not properly filled out:
“One or more fields have an error. Please check and try again.”
And, it shows this message when the contact form is sent:
“Thank you for your message. It has been sent.”
These response messages from Contact Form 7 have a border for styling. You can change the style of these message boxes by adding the following CSS. (See how to add CSS.)
This CSS will make the Contact Form 7 response message boxes look like in the picture above.
This CSS example uses the WordPress dashicons, so if your theme does not load the dashicons stylesheet, you can load it in the footer by adding this to your footer.php
:
<?php wp_enqueue_style( 'dashicons' ); ?>
If you prefer not add the dashicons, please see below for two other styling examples.
The CSS:
.wpcf7-form .wpcf7-response-output.wpcf7-validation-errors { color: #D8000C; background-color: #FFBABA; border: 0; padding: 10px; } .wpcf7-form .wpcf7-response-output.wpcf7-mail-sent-ok { color: #4F8A10; background-color: #DFF2BF; border: 0; padding: 10px; } div.wpcf7-mail-sent-ok:before,div.wpcf7-validation-errors:before { font: 26px/30px dashicons; margin-right: 16px; vertical-align: middle; } div.wpcf7-mail-sent-ok:before { content: "\f147"; } div.wpcf7-validation-errors:before { content: "\f158"; }
Other Styling Examples
If you prefer not to load the WordPress dashicons, here are two more examples of styling the Contact Form 7 message boxes.
- Font Awesome
If you are already using Font Awesome on your site, you can use the Font Awesome icons instead of the dashicons. To use Font Awesome icons, use this CSS instead of the one above (this assumes you have a theme or plugin which is already loading Font Awesome icons):
.wpcf7-form .wpcf7-response-output.wpcf7-validation-errors { color: #D8000C; background-color: #FFBABA; border: 0; padding: 10px; } .wpcf7-form .wpcf7-response-output.wpcf7-mail-sent-ok { color: #4F8A10; background-color: #DFF2BF; border: 0; padding: 10px; } div.wpcf7-mail-sent-ok:before,div.wpcf7-validation-errors:before { font: 26px/30px FontAwesome; margin-right: 16px; vertical-align: middle; } div.wpcf7-mail-sent-ok:before { content:'\f00c'; } div.wpcf7-validation-errors:before { content:'\f057'; }
-
No Icons
You can have the colorful red and green message boxes with no icons. To do it this way, just use only lines 1–12 of either of the CSS examples above.
You may also want to check out this lightweight contact form plugin for WordPress.
abhyudaya
January 3rd, 2017 at 2:21 pm
thnk you so much working
Miguel
February 6th, 2017 at 4:55 am
Awesome! Form responses now look great, thanks!
Isabel
February 10th, 2017 at 2:35 pm
Thank you.
Raj
February 16th, 2017 at 6:23 am
Thank you.
Suze Kenington
February 23rd, 2017 at 9:12 pm
Really helpful – thanks! I was wondering how I would structure the syntax to have the wpcf1-not-valid-tip entries to the be on a red background. I am not sure how to refer to these tips in the CSS.
Thx
Isabel
February 25th, 2017 at 4:37 pm
Thanks. To have the those be on a red background, insert this line at the very top of the CSS:
.wpcf7-not-valid-tip,
Suze Kenington
February 26th, 2017 at 4:48 pm
Thanks Isabel – worked a treat – I had put .wpcf7-form.wpcf7-not-valid-tip
Uros
March 5th, 2017 at 12:12 pm
Very good, thanks!
Michael
April 6th, 2017 at 6:47 pm
Hey there, I’m not a programmer but I managed to create a decent form using CF7. I don’t like the green response bar but could not figure out how to change the color. I tried using the first 12 lines of your code, only changed font color. Thanks in advance.
Isabel
April 8th, 2017 at 3:08 pm
Hi, in this block of code that you posted, I don’t see that you added the 12 lines. If you add the 12 lines, it would work.
Michael
April 8th, 2017 at 4:35 pm
Hi Isablel,
Thank you. I resinserted the code and it still changes nothing
Isabel
April 8th, 2017 at 6:01 pm
Is it possible that your theme is adding custom styles for Contact Form 7 (many themes do)? If so, they could be overriding these styles. You could still override those, but I would need to see a link to the page to see what CSS is overriding.
Michael
April 8th, 2017 at 6:25 pm
Here is the page:
http://reverseloansforseniors.com/
Thank you!!
Isabel
April 8th, 2017 at 9:04 pm
Okay, yes, your theme sets custom styles for Contact Form 7, and its using the keyword “!important” to force their colors to override other colors. To override that, you also have to add
!important
to the colors, like this:Note that the text color and background color are set to the same color on these lines (a wine color). So, edit them with your desired color codes. Hope that helps.
Michael
April 9th, 2017 at 6:54 am
Isabel, I added the code as stated by you. It still made no changes to the green banner. I added the purple/plum color only to see a drastic change. I really want black and white.
I really ant the form to appear like this: https://www.w3schools.com/code/tryit.asp?filename=FE1OT7GF4FJB
Question? Do I really need the theme? It changes the colors and fonts and it seems to cause more problems. In the 2 weeks i’m doing this I can manage to figure it out.
BTW, I’ve been in Mortgage Banking and real estate for 30 years. If you ever need any sound advice or strategy please don’t hesitate to contact me.
Michael
April 9th, 2017 at 6:58 am
I fixed it. Thank you so much. my offer still stands. Now I have to figure out the hover effect.
Nick
May 30th, 2017 at 7:51 am
The semicolon in front of !important is wrong!
Change…
background-color: #000; !important;
…to…
background-color: #000 !important;
…and it will work.
Danish
July 6th, 2017 at 8:11 am
Its Great! Working for me.
Thanks
m
August 1st, 2017 at 10:07 am
<3 Thank you for this. I am sending you heaps of love for fixing an issue that neither the developers of my custom theme nor the CF7 wanted to address.
Chrissy
August 5th, 2017 at 1:00 am
This was SOOO helpful!!! Thank you so much!!!!!!!!!!!
Paula
October 2nd, 2017 at 7:32 am
Fantastic! Thank you!
Vijay Rudraraju
October 18th, 2017 at 5:53 am
Hi Isabel,
Awesome code. I thought loading font-awesome for just 2 icons might be an overkill for some.
Here I am using HTML entities https://www.w3schools.com/charsets/ref_utf_dingbats.asp
[code]
.wpcf7-form .wpcf7-response-output.wpcf7-validation-errors,
.wpcf7-not-valid-tip {
color: #D8000C;
background-color: #FFBABA;
border: 0;
padding: 10px;
}
.wpcf7-form .wpcf7-response-output.wpcf7-mail-sent-ok {
color: #4F8A10;
background-color: #DFF2BF;
border: 0;
padding: 10px;
}
div.wpcf7-mail-sent-ok:before,div.wpcf7-validation-errors:before,
.wpcf7-not-valid-tip:before {
margin-right: 16px;
vertical-align: middle;
font-size: 2em;
}
div.wpcf7-mail-sent-ok:before {
content: “✔”;
}
div.wpcf7-validation-errors:before,
.wpcf7-not-valid-tip:before {
content: “✘”;
}
[code]
Ella
January 3rd, 2018 at 8:55 am
Thanks a lot!
Laura Sweet
February 13th, 2019 at 2:54 pm
Hi there – this is great! Thanks for sharing. How do I make the text inside the banner larger?
Bayar
March 18th, 2019 at 4:34 am
It works !! Thank you
karen
December 11th, 2019 at 5:41 pm
Thank you! Worked great.
Francisco Thomé Arquer
April 21st, 2020 at 10:49 am
Awesome, Isabel.
It works perfectly. Thank you ever so much.
Carlos Magallon
June 28th, 2020 at 12:33 am
Thank You Isabel, now I have a nice form 🙂
Carlos Magallon
August 11th, 2020 at 7:38 pm
Hello Isabel its seem cf7 has changed the events, I had to made some changes that I share with you 🙂
Please see below,
Regards,
Carlos Magallon
Yair
September 2nd, 2020 at 1:25 pm
Hi Isabela,
don’t know if I’m using a different version of CR7 than the one you’re using.
Your code out-of-the-box did not work.
After digging into the css, I’ve modified it a bit and now it works great for me.
I’ve also used the two symbols as mentioned here.
Maybe it’ll help someone.
Thanks a lot