Looking for a way to spice up your Pardot email preferences page? Try using toggles instead of checkboxes. In this tutorial, I’ll show you how to create a preferences page that uses toggles instead of checkboxes. With a bit of HTML and some CSS, you can transform your preferences page in four easy steps.
Demo
Here’s an example of what we’ll be creating in this tutorial.
See the Pen Pardot Preferences Page With Toggles by Jenna Molby (@jennamolby) on CodePen.
Step 1: Style your preference page
This post does not cover the basics of styling your Pardot preferences page. Click here to learn how to customize your page from scratch.
Step 2: Update the preferences page template
To make the toggles work, you will need to edit the form section of your layout template. Navigate to the layout template and click on the form tab. Replace the content with this HTML.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
<form accept-charset="UTF-8" method="post" action="%%form-action-url%%" class="form" id="pardot-form"> %%form-opening-general-content%% %%form-if-thank-you%% %%form-javascript-focus%% %%form-thank-you-content%% %%form-thank-you-code%% %%form-end-if-thank-you%% %%form-if-display-form%% %%form-before-form-content%% %%form-if-error%% <p class="errors">Please correct the errors below:</p> %%form-end-if-error%% <ol class="switches"> %%form-start-loop-fields%% <li class="form-field %%form-field-css-classes%% %%form-field-class-type%% %%form-field-class-required%% %%form-field-class-hidden%% %%form-field-class-no-label%% %%form-field-class-error%% %%form-field-dependency-css%%"> %%form-if-field-label%% <label class="field-label" for="%%form-field-id%%">%%form-field-label%%</label> %%form-end-if-field-label%% %%form-field-input%% %%form-if-field-description%% <span class="description">%%form-field-description%%</span> %%form-end-if-field-description%% </li> <div id="error_for_%%form-field-id%%" style="display:none"></div> %%form-field-if-error%% <p class="error no-label">%%form-field-error-message%%</p> %%form-field-end-if-error%% %%form-end-loop-fields%% </ol> %%form-spam-trap-field%% <!-- forces IE5-8 to correctly submit UTF8 content --> <input name="_utf8" type="hidden" value="☃" /> <p class="submit"> <input type="submit" accesskey="s" value="%%form-submit-button-text%%" %%form-submit-disabled%%/> </p> %%form-after-form-content%% %%form-end-if-display-form%% %%form-javascript-link-target-top%% </form> <!-- Update the HTML using jQuery to create toggles --> <script src="https://code.jquery.com/jquery-latest.min.js"></script> <script type="text/javascript"> $( document ).ready(function() { $('label').contents().each(function() { if (this.nodeType == 3 && $.trim(this.nodeValue) != '') { $(this).wrap('<span class="label-wrapper"></span>'); } }); $('.label-wrapper').after('<span></span>'); }); </script> |
What’s changed?
- Instead of placing the form fields in a paragraph, the form fields are placed in an ordered list with a class named “switches”.
- Some jQuery is added to update the HTML markup of the preferences form.
Step 3: Upload icons into Pardot
There are two icons that will need to be uploaded in Pardot, a checkmark icon and a “x” icon. Download the images and then upload the images into the content library within Pardot.
Step 4: Add the CSS for the toggles
Add this CSS to your layout template. Update the first couple of lines to include the image paths to the icons you uploaded in step 4.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
/* Update this line with the URL of your checkbox image */ .switches .pd-checkbox [type="checkbox"]:checked + label span:last-child::after { background-image: url(https://); } /* Update this line with the URL of your "X" image */ .switches .pd-checkbox span:last-child::after { background: url(https://); } * { padding: 0; margin: 0; box-sizing: border-box; } ol { list-style: none; } label { cursor: pointer; } #pardot-form p { margin-left:0; padding-left:0; } /* hide the checkbox */ [type="checkbox"] { position: absolute; left: -9999px; } /* Position the checkbox label */ .switches .pd-checkbox label { display: flex; align-items: center; justify-content: space-between; } /* Style the switch */ .switches .pd-checkbox label.inline span:last-child { position: relative; width: 50px; height: 26px; border-radius: 15px; box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.4); background: #434257; transition: all 0.3s; } .switches .pd-checkbox label.inline span:last-child::before, .switches .pd-checkbox label.inline span:last-child::after { content: ""; position: absolute; } .switches .pd-checkbox span:last-child::before { left: 1px; top: 1px; width: 24px; height: 24px; background: #FFF; border-radius: 50%; z-index: 1; transition: transform 0.3s; } /* Style the "X" switch */ .switches .pd-checkbox span:last-child::after { top: 50%; right: 8px; width: 12px; height: 12px; transform: translateY(-50%); background-size: 12px 12px; } /* Style the "ON" switch */ .switches .pd-checkbox [type="checkbox"]:checked + label span:last-child { background: #00d084; } .switches .pd-checkbox [type="checkbox"]:checked + label span:last-child::before { transform: translateX(24px); } .switches .pd-checkbox [type="checkbox"]:checked + label span:last-child::after { width: 14px; height: 14px; left: 8px; background-size: 14px 14px; } |
Now your page would look something like this, with the checkboxes turned into toggles.
Optional: Add any additional CSS
I added some additional CSS to my page to style the labels, list descriptions and options for my page. Here’s the CSS I added.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#pardot-form .no-label{ text-align:center; margin-top:35px; } #pardot-form .no-label a { text-decoration:underline; } #pardot-form label { font-weight:500; font-size:15px; } .pd-email { margin:20px 0; } #pardot-form .description { text-align:left; display:block; } #pardot-form li.pd-checkbox { background-color:#FFF; margin-bottom:5px; border:solid 1px #ebebeb; padding:0px 20px 20px 20px; border-radius:5px; -moz-border-radius:5px; -webkit-border-radius:5px; } #pardot-form .label-wrapper { color:#444444; } #pardot-form { color:#737373; } #pardot-form .form-field { text-align:left; } #pardot-form input.text { border:solid 1px #ebebeb; padding:10px; border-radius:5px; -moz-border-radius:5px; -webkit-border-radius:5px; color:#737373; } #pardot-form .no-label { text-align:center; } #pardot-form .no-label a { color:#737373; } |
The final result
Here’s what my final page looks like.
See the Pen Pardot Preferences Page With Toggles by Jenna Molby (@jennamolby) on CodePen.
Questions?
Send me a tweet @jennamolby, or leave a comment.
Special thanks to Tuts+ for a great tutorial on CSS toggles. This tutorial was the inspiration for building this within Pardot.
Hey Jenna, I don’t understand where to paste the Step 4 text. Does that go into the Layout tab, Form Tab, or somewhere else?
Hi Colin, You could put it in either the layout tab or the form tab.