Add CSS Classes and Unique IDs in Divi 5

By Interactive OnlinePublished Updated Editorial draft

Quick Answer

In Divi 5, open an element’s Advanced → Attributes group to add a class or ID. Choose the correct Target Element, then set the attribute name and value. Use a class for reusable hooks and an ID for one unique element in the rendered document. Inspect the front-end HTML after saving, especially when templates, loops or duplicated modules can repeat the same ID.

A class name does not create styling by itself. It gives CSS or a script a hook. An ID can also identify a fragment destination, so changing it may affect incoming links.

Choose a reusable class or a unique ID

MDN defines class as a space-separated list of classes. For a simple reusable card hook, an illustrative value is ioc-service-card. Enter the name without the selector’s leading period.

MDN’s ID reference requires uniqueness within the document. An illustrative section destination might be service-inquiry, without a leading hash in the attribute value. Choose simple, descriptive identifiers that can be used in selectors without awkward escaping.

A shared header or footer can already contain an ID used in the page body. Check the complete rendered document, rather than only the selected module. For repeated cards or loop items, use a class unless a genuinely unique per-item identifier is implemented.

Add the attribute to the intended element

The October 25, 2025 publisher tutorial and current Custom Attributes help describe this workflow:

  1. Select the intended module or container in a development copy.
  2. Open Advanced → Attributes and choose Add Attribute.
  3. Select the Target Element, such as the wrapper or an exposed inner image or button.
  4. Set the name to class or id, then enter the value.
  5. Use an admin label to explain the hook, save, and inspect the front end.

Keep existing useful classes when adding another. A replacement of the whole class value can remove hooks that other styling or behavior depends on.

Verify the target and dependency

If the stylesheet expects a class on a wrapper, attaching it to the inner image creates a different selector relationship. Inspect where the attribute actually appears and compare that with the intended CSS or script.

Test a fragment link from another page as well as from the same page. Confirm the destination is visible beneath any sticky header and keyboard focus remains understandable. Check selectors at narrower widths and relevant interaction states.

Review migrated and shared instances

The documentation describes migration of legacy ID and class fields into Attributes. Verify the actual instances after a migration rather than assuming every third-party module, preset and template behaves identically.

Record why each custom hook exists and the stylesheet or interaction that uses it. Our broader attribute guide covers other attribute types. Ongoing development can help replace fragile selectors while keeping the existing layout editable.

Key Takeaways

  • Use reusable classes and unique document IDs.
  • Choose the actual wrapper or inner target deliberately.
  • Keep existing hooks when adding a new class.
  • Verify rendered duplicates, selectors and fragment destinations.

Frequently Asked Questions

Do I type a dot before a class value?

No. A class attribute contains the class name. The dot belongs in a CSS class selector.

Can every repeated card use the same ID?

No. IDs must be unique within the rendered document. A shared class is usually the appropriate repeated hook.

Why is the attribute present but the styling absent?

Check the targeted HTML element, selector relationship, stylesheet loading and conflicting rules. The attribute alone supplies no style declaration.

Archives