Divi Tutorial – Styling the toggle icons

Divi Tutorial – Styling the toggle icons

Edited on May 27th 2022

Toggles and accordions. First, read up on when they’re useful for UI, and when they are not.

So for this tutorial, let’s assume using them are helpful for the page.

Somehow, they get real boring quickly, and they’re not always the coolest.

Check out the toggle on the demo site. The icon is different, plus check out the sweet animation on the toggles. (The accordions are slightly different)

The snippet

Here, copy this and paste it somewhere that custom code is welcomed.

.et_pb_toggle_open .et_pb_toggle_title:before {
  content: "\4c";
  color: black;
  font-size: 36px;
  -webkit-transition: all 0.5s ease-in-out;
  -moz-transition: all 0.5s ease-in-out;
  -o-transition: all 0.5s ease-in-out;
  -ms-transition: all 0.5s ease-in-out;
  transition: all 0.5s ease-in-out;
  -webkit-transform: rotate(45deg);
  -moz-transform: rotate(45deg);
  -o-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  transform: rotate(45deg);
}
 
.et_pb_toggle_close .et_pb_toggle_title:before {
  color: black;
  font-size: 36px;
  content: "\4c";
  -webkit-transition: all 0.5s ease-in-out;
  -moz-transition: all 0.5s ease-in-out;
  -o-transition: all 0.5s ease-in-out;
  -ms-transition: all 0.5s ease-in-out;
  transition: all 0.5s ease-in-out;
  -webkit-transform: rotate(0deg);
  -moz-transform: rotate(0deg);
  -o-transform: rotate(0deg);
  -ms-transform: rotate(0deg);
  transform: rotate(0deg);
}

Some explanations

What we’re using here is a pseudo element. Simply put, it’s something you attach before or after an element to make it display something extra. It’s really useful in many ways of styling things, and here, the toggle gets some.

One styles the open toggle, the other one styles the closed toggle.

  • color: black; -> The color of the icon
  • font-size: 36px; -> It’s gotta be a certain size, otherwise it’s too small.
  • content: “\4c”; -> This is based off of the Elegant Themes Iconset. You can change this if you want. To learn how to add more icons, check out an example of the method here.
  • transition: all 0.5s ease-in-out; -> a bunch of transitions with vendor prefixes. You can change the 0.5s from half a sec to something else if you want.
  • transform: rotate(45deg); -> a bunch of transforms with vendor prefixes. You can probably see that this rotates the icon by 45 degrees.

So yeah, change the values to get what you want. Have fun!

[sc name=”learn css”]

[sc name=”podcast”]

Leave a Reply

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

  1. zea says:

    Hi there, I send a message to the link you’ve posted. I’m happy that you reply on my post.

  2. zea says:

    Hi there!

    I really like the toggle icon when you click it it turns out to X., but I can’t add that on the website of my client. Can you help me please?

New tutorials

Use a featured video in post templates with Breakdance
ACF repeater fields as accordions in Breakdance
Breakdance 2 vs. Divi 4
Breakdance 2 for Agencies

Why no ads?

Hi, I'm PK, and I maintain and publish content on this site for two reasons.

  1. To give back to the community. I learned so much from people's tutorials and StackOverflow that I wanted to contribute and help others.

  2. To provide a more structured learning experience. People struggle to find the course that guides them from start to finish, based off of real life experience, and my courses provide that.

The only "ads" I have here are for my own courses, and maybe an affiliate link, but that's it. They fund the website resources and provide more motivation for me to produce better content.

Any bit of interest helps. Even sharing with your friends, suggesting my courses to your developer or designer, or subscribing to my YT channel, or joining our Discord. Thanks and I'll see you around!

There's a newsletter!

Sign up to the newsletter for the occasional updates on courses, products, tutorials, and sales.