☰
ELEMENTOR / PRACTICE

Custom Attributes in Elementor: Analytics, JavaScript, and Accessibility

Custom Attributes in Elementor: Analytics, JavaScript, and Accessibility

Custom attributes in Elementor let you add your own HTML parameters to elements without editing templates or writing separate code. They are commonly used for analytics, JavaScript click handling, integrations, and improved accessibility.

They are a practical alternative to creating a large number of unique IDs and classes. For example, you can assign the data-cta attribute with different values to similar buttons and then pass those values to Google Tag Manager or a custom script.

Where to Add Custom Attributes in Elementor

Open the required page or template in Elementor and select the widget, container, or other element to which you want to add an attribute. In the settings panel, open the Advanced tab, find the Custom Attributes section, and enter the parameters in the appropriate field.

Enter each attribute on a new line. The required format is: name|value. The vertical bar separates the attribute name from its value.

  • data-cta|consultation
  • data-plan|pro
  • aria-label|Open menu
  • rel|nofollow

Which Attributes Are Used Most Often

The safest and most flexible option for custom requirements is the data-* attribute. These attributes are intended to store additional data in HTML and do not change an element's appearance. You can create the name after data- for a specific task, but it is best to use a clear and consistent naming scheme.

Standard HTML attributes can also be added, but their behavior depends on the element type. For example, rel is meaningful for links, not for a regular container.

  • data-cta|consultation — the category or type of target action.
  • data-plan|pro — the plan, package, or offer option.
  • data-location|hero — the element's position on the page.
  • aria-label|Open menu — an accessible name for an element without visible text.
  • rel|nofollow — an additional link attribute when required by SEO or technical rules.

How to Use Attributes for Analytics

When a website has several identical buttons, the button text or a class alone may not be enough for accurate analysis. Add clear data attributes to each button to describe its purpose and location.

For example, a consultation button in the hero section can use data-cta|consultation and data-location|hero. The same action at the bottom of the page can have a different data-location value. In Google Tag Manager, you can configure a click trigger and pass these values as event parameters.

Use a consistent style for names and values: write them in Latin characters, avoid unnecessary spaces, and apply hyphens or underscores consistently. This simplifies report filtering and future JavaScript development.

  • Do not use personal data, email addresses, or other confidential information for analytics.
  • Do not create different names for the same action, such as consultation, consult, and request for one type of lead.
  • Check not only whether the click was recorded, but also whether the correct values were passed to the analytics system.
  • For critical conversions, do not rely on a single attribute alone. Also verify the event itself and its source.
data-cta|consultation
data-location|hero
data-plan|pro

Custom Attributes for JavaScript and Integrations

JavaScript can find elements by their data attributes and perform the required action: open a modal window, switch a plan, launch a calculator, or send data to a third-party service. This is more reliable than tying functionality to button text, which an editor may change.

CSS selectors such as [data-cta="consultation"] can be used to select elements. This means the script does not depend on a specific ID, but it should still be tested after template changes and when updating Elementor or other plugins.

Do not add secret keys, tokens, or passwords to attributes. The HTML delivered to the browser is accessible to the user, so custom attributes are not a way to protect data.

  • Use attributes to describe an element's role, not to store a large amount of data.
  • If a script expects a specific value, do not change it manually without checking the related code.
  • After adding attributes, test the functionality on desktop, smartphones, and different element states.
const buttons = document.querySelectorAll('[data-cta="consultation"]');

buttons.forEach((button) => {
  button.addEventListener('click', () => {
    console.log(button.dataset.location);
  });
});

Accessibility: When to Use aria-label

ARIA attributes help assistive technologies understand an element's purpose. However, aria-label does not need to be added to every button. If a button has clear visible text such as “Book a consultation,” that text is usually sufficient as its accessible name.

aria-label is appropriate for an unlabeled icon, a mobile menu button, a modal close button, or another element whose purpose cannot be understood from its visible content.

The value should briefly describe the action, not the element's appearance. “Icon” explains nothing, while “Open menu” or “Close window” is clear.

  • Do not unnecessarily duplicate visible text, as this can create redundant or conflicting names for screen readers.
  • Do not use aria-label as a replacement for clear text on every element.
  • Check that the attribute is applied to the interactive HTML element, not only to an outer container.
  • For icon buttons, also provide keyboard accessibility and a clearly visible focus state.
aria-label|Open menu

Checking Attributes and Common Mistakes

After saving the page, open it in a browser and inspect the HTML using the developer tools. Make sure the attribute was added to the correct element, the name is spelled correctly, and the value was not truncated or affected by accidental spaces.

Also check the behavior on the published page, not only in the Elementor editor. Caching, HTML optimization, or additional plugins can affect the final markup or script behavior.

  • Do not confuse Elementor's name|value format with standard HTML syntax such as name="value".
  • Do not add spaces around the vertical bar if your script or integration is sensitive to values.
  • Do not use the same ID for multiple elements. Use data attributes or classes for grouping instead.
  • Do not add rel|nofollow to elements that are not links.
  • Check attributes after copying a widget, importing a template, or making bulk edits.

Frequently asked questions

Can I add multiple custom attributes to one element in Elementor?

Yes. Enter each attribute on a new line using the name|value format. For example: data-cta|consultation and data-location|hero.

How is a data attribute different from a class or ID?

A class is generally used for styling or grouping elements, an ID must be unique, and a data attribute is useful for describing data and passing values to GTM or JavaScript.

Do I need to add aria-label to a button with text?

Usually not, provided the visible text clearly and unambiguously describes the action. aria-label is mainly needed for elements without a clear text label.

Why does an attribute not work in Google Tag Manager?

Check whether the attribute was added to the element that users actually click, whether the name and value are written correctly, and whether the GTM trigger looks for the parameter in the correct event object.

Conclusion

Custom attributes in Elementor help separate a page's visual design from its technical logic. You can use data-* attributes to mark CTAs for analytics and scripts, while ARIA attributes clarify the purpose of elements for users of assistive technologies.

Add only the attributes you genuinely need, use a consistent naming system, and check the final markup in a browser. This keeps the page structure clear and integrations more reliable.

← All Elementor materials