How to Add CSS Classes and ID’s to Contact Form 7

Learn how to add CSS Classes and ID's to Contact Form 7 easily for greater styling control and the ability to add specific CSS to each section of the form.

In this article we’re taking a look at how to add CSS Classes and ID’s to Contact Form 7 Fields to style a specific field.

As a default Contact Form 7 styling can be fairly broad for example let’s say you want to style all of the text input fields, you would write some CSS like this:

.wpcf7 input[type="text"] {

background-color: orange;

}

The above code sets the background color for all input types that match the text format to be orange. So whether you have 30 fields in your form that are for entering text or 1 all of them will have an orange background. This is great when it comes to styling your entire form all at once and ensuring that it’s consistent and uniform.

Examples:

Another good example of this is: 

.wpcf7 input[type=”email”]

Setting Generic Contact Form 7 Styles:

The above sets the style for all of the email fields within the contact form for example:


.wpcf7 input[type="email"] {

Background-color: orange;

}

This code does the same as the above code for the text fields and sets the background of all email fields to orange.

To find the input type of any other fields you can use the browser inspect tool to select the specific field type that you want the input format for. From this you will need to identify the section type in the same format as the above or without the input type if it’s a textarea for example.

It’s then important to ensure that you keep the .wpcf7 class in front of that class when styling it or the styling will apply to all elements of a similar format throughout your site. However when using the specific Contact Form 7 class it will only apply to the elements within your form.

To add custom ID’s and Classes for more specific fields, for example one text field that is styled differently to others you can simply add the ID or Class to the form side element for example:

[text* your-name class:contact-form-name “John Smith”]

[text* your-name id:contact-form-id “John Smith”]

So in the above examples the class is ‘contact-form-name’ and the ID in the other example is ‘contact-form-id’ to assign styles to these would use the respective CSS formatting:

Styling a Class:
.contact-form-name {

Background-color: orange;

}

And

Styling an ID:
#contact-form-id {

Background-color: orange;

}

These examples use the relevant . for a class an the # for an ID and then assign a background color of orange to the element.

Further Reading:

Storing Contact Form 7 Submissions

How to Add ReCaptcha to Contact Form 7

Summary:

Adding CSS Classes and ID’s to Contact Form 7 is relatively easy, and isn’t always necessary unless styling specific elements within the form. It’s often easier to style the elements that make up the form collectively to ensure that every section you create looks consistent. If you found this useful we would really appreciate a comment and a share thanks!

Tech Typed
Tech Typed
Articles: 186

Leave a Reply

Your email address will not be published. Required fields are marked *