CSS techniques

Button hover effects in Divi 5 (without fighting Divi)

Add shine, fill, glow and animated border hover effects to Divi buttons with a few lines of CSS. Steps for Divi 5’s Free-Form CSS and Divi 4, plus the setting that stops them working.

To add a custom button hover effect in Divi 5, open the Button module’s Advanced › Custom CSS › Free-Form CSS and paste CSS that starts with the selector keyword. Divi swaps selector for that module, so the effect applies to this one button. Leave the module’s Use Custom Styles For Button option off, or Divi’s own button styles can override the effect.

Divi’s Button module handles colours, borders and simple hover changes on its own. Effects like a light sweeping across the button, a fill sliding in or a glowing animated border need a little CSS. This guide shows how to add them in Divi 5, with a Divi 4 method too.

Key takeaways

  • Divi 5: paste CSS beginning with selector into Advanced › Custom CSS › Free-Form CSS on the Button module.
  • Divi 4: add a CSS class to the module and paste the CSS into Divi › Theme Options › General › Custom CSS.
  • Keep “Use Custom Styles For Button” off so Divi’s button styles don’t fight the effect.
  • Run the effect on :focus-visible too, and switch motion off for people who prefer reduced motion.

Which hover effects need CSS?

Divi’s built-in hover options change properties such as colour, border and shadow. Effects that use a pseudo-element, a sliding layer or a keyframe animation need custom CSS. These are the ones Refract’s button hover effects generator writes for Divi:

EffectWhat happens on hover
Shine sweepA soft band of light slides across the button
Fill slideA second colour slides in from one side
Animated gradient borderA gradient border rotates around the button
Glow pulseA soft glow breathes around the edge
3D pressThe button presses down onto a hard shadow
Underline growA line grows under the label
Gradient shiftThe background gradient slides across
GlassA frosted, translucent button for use over images
NeonA bright outline and glow
LiftThe button rises with a deeper shadow

Add a hover effect in Divi 5

  1. Open the settings for the Button module.
  2. In the Design tab, check that Use Custom Styles For Button is off.
  3. Go to Advanced › Custom CSS and choose the Free-Form CSS tab.
  4. Paste the code and save the page.

This is the shine sweep as the generator writes it for Divi 5, shortened slightly here (the generator also sets the font size, weight and alignment):

selector.et_pb_button,
selector .et_pb_button {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background: #2f4bff;
  color: #ffffff;
  border: 0;
  border-radius: 12px;
  padding: 13px 24px;
}

selector.et_pb_button::before,
selector .et_pb_button::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(255, 255, 255, .45) 50%, transparent 70%);
  transform: translateX(-120%);
  transition: transform 0.5s cubic-bezier(.2,.8,.2,1);
  pointer-events: none;
}

selector.et_pb_button:hover::before,
selector .et_pb_button:hover::before,
selector.et_pb_button:focus-visible::before,
selector .et_pb_button:focus-visible::before {
  transform: translateX(120%);
}

@media (prefers-reduced-motion: reduce) {
  selector.et_pb_button::before,
  selector .et_pb_button::before {
    transition: none;
  }
}

Each rule lists two selectors, selector.et_pb_button and selector .et_pb_button, so it reaches the clickable button whether Divi applies selector to the button itself or to the module around it. The shine uses ::before, which leaves Divi’s ::after button icon free to work as normal.

Divi’s help centre describes Free-Form CSS and the selector keyword in its guide to where to add custom CSS in Divi 5.

Add a hover effect in Divi 4

Divi 4’s module CSS boxes only accept declarations, not full rules with :hover and ::before, so for these effects use a class instead:

  1. Open the Button module and go to Advanced › CSS ID & Classes › CSS Class. Type rf-button.
  2. Paste the CSS into Divi › Theme Options › General › Custom CSS. The rules start with .rf-button.et_pb_button.
  3. Save, then exit the Visual Builder to check the effect on the live page.

Why isn’t the hover effect working?

ProblemFix
Divi’s own hover colour or border appears insteadTurn off Use Custom Styles For Button, or untick Include colours in the generator and set colours in Divi
Nothing changes in the Visual BuilderSave and view the live page; some effects only show outside the builder
The effect applies to every buttonYou pasted the Divi 4 CSS without adding the class, or used the class on several modules
The button icon has disappearedUse an effect that draws on ::before, as the generator does for Divi
Old styles stay after changesClear Divi’s static CSS and your caching plugin, then hard refresh

Keep the effect accessible

  • Keyboard users never hover, so pair :hover with :focus-visible. Every effect from the generator does this.
  • Reduced motion: some people get dizzy from movement. Wrap animations in a prefers-reduced-motion check so they switch off when requested.
  • Touch screens have no hover, so the effect is a bonus. Make sure the button reads clearly as a button without it.
  • Contrast: if the effect changes the background, check the label still passes on both colours with the contrast checker.

Tip: Effects that animate transform and opacity stay smooth because the browser can hand them to the graphics hardware. Avoid hover effects that animate width, height or padding, which force the page to re-lay out on every frame.

Make your own

Open the button hover effects generator, hover over the ten effects, then set your button colour, text colour, radius and speed. Choose Divi 5 or Divi 4 under Paste into and copy code written for the Button module, with the steps underneath. For a softer depth effect without movement, the box shadow generator builds layered shadows you can add on hover.

Sources: Elegant Themes: where to add custom CSS in Divi 5.