Webflow sync, pageviews & more.
NEW

How can I add :before and :after effects in Webflow?

TL;DR
  • Assign a unique class to your element in Webflow and add custom CSS with :before or :after pseudo-elements in the Page or Site Settings under the "Head" section.
  • Publish your site to see the effect, as pseudo-elements won’t appear in the Designer.

To use :before and :after pseudo-elements in Webflow, you'll need to use custom code, as Webflow’s Designer doesn’t natively support styling these pseudo-elements through its UI.

1. Add a Custom Class to the Target Element

  • Select the element (such as a div, button, or heading) you want to add the :before or :after effect to.
  • In the Selector field, assign a unique class (e.g., custom-element).

2. Inject Custom CSS Using the Page or Site Settings

  • Go to the Page Settings or Project Settings > Custom Code tab.
  • Paste your CSS into the “Inside <style> tag” section under the “Head” area.

Example CSS snippet:

<style>.custom-element::before {  content: "";  display: block;  width: 100px;  height: 2px;  background: black;  margin-bottom: 10px;}</style>

Key Notes:

  • Use either ::before or ::after depending on where you want the effect to appear.
  • You must define **content** for the pseudo-element to render. Even if it's blank, it needs to be there.
  • Style it from scratch since Webflow’s UI won’t show or preview it.

3. Publish Your Site to See the Changes

  • Changes will not display inside the Webflow Designer.
  • Click Publish and view the live site to see your pseudo-elements.

4. Optional: Target by Combo Classes or IDs

  • You can write more specific selectors if needed, such as .custom-element.large::after, or #myDiv::before.

Summary

To use :before and :after effects in Webflow, assign a class to your target element and add the necessary custom CSS with pseudo-elements in your site or page settings. These effects only appear on the published site, not in the Designer.

Rate this answer

Other Webflow Questions