Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
description: >- custom classes, IDs, and data attributes allow you to target elements with custom code, animation libraries, and external scripts. icon: code
Custom classes and attributes
While Design tokens handle styling in Webstudio, custom classes, IDs, and data attributes serve a different purpose: they allow external code to target specific elements.
{% embed url="https://www.youtube.com/watch?v=_1QSWHOtk08" %}
When to use what
| Feature | Purpose | Output in HTML |
|---|---|---|
| Design tokens | Apply and manage styles | Converted to optimized classes (atomic CSS) |
| Custom classes | Target elements with custom code | Yes, exactly as specified |
| Custom IDs | Unique element targeting, anchor links | Yes, exactly as specified |
| Data attributes | Pass data to JavaScript, custom functionality | Yes, exactly as specified |
{% hint style="info" %} Important: Design tokens do NOT output their names as classes in HTML. The token name is an internal reference – the actual CSS output is optimized for performance. Use custom classes when you need a specific class name in the HTML. {% endhint %}
Adding custom classes
- Select an instance in the canvas
- Open the Settings panel (right side)
- Find the Class field
- Enter your class name(s), separated by spaces

Custom classes, IDs, and data attributes in the Settings panel
Multiple classes can be added: card featured animate-on-scroll
Use cases for custom classes
- Animation libraries: GSAP, AOS, or other libraries that target elements by class
- Third-party scripts: Analytics, heatmaps, or widgets that need class selectors
- Custom CSS: When adding CSS via HTML Embed or external stylesheets
- JavaScript targeting:
document.querySelectorAll('.my-class')
Adding custom IDs
- Select an instance
- Open Settings
- Find the ID field
- Enter a unique identifier (no spaces, no
#)
Use cases for custom IDs
- Anchor links: Link to
#section-nameto scroll to that section - JavaScript targeting:
document.getElementById('my-element') - Form labels: Connect labels to inputs with matching IDs
- Table of contents: Auto-generate TOC based on heading IDs
{% hint style="warning" %} IDs must be unique on a page. Using the same ID multiple times can cause unexpected behavior. {% endhint %}
Adding data attributes
Data attributes let you attach custom data to elements:
- Select an instance
- Open Settings
- Scroll to custom properties or use the + to add properties
- Add attributes like
data-speed="0.5"ordata-section="hero"
Use cases for Data attributes
- Animation parameters:
data-speed,data-delay,data-direction - Configuration: Pass settings to JavaScript components
- State tracking:
data-active="true",data-expanded="false" - Analytics:
data-track="cta-button",data-category="signup"
Tokens vs classes: technical details
Design tokens in Webstudio use atomic CSS by default, which:
- Generates optimized, single-purpose classes
- Reduces CSS file size by up to 90%
- Improves caching and performance
This means a Token named "card" might output as multiple atomic classes like a1 b2 c3 rather than a single .card class.
If you need the exact class name in HTML (for external scripts), use the custom Class field in Settings – not Tokens.
Example: Integrating with GSAP
To animate elements with GSAP:
- Add a custom class to target elements:
gsap-fade-in - Add an HTML Embed with your GSAP script:
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
<script>
gsap.from(".gsap-fade-in", {
opacity: 0,
y: 50,
duration: 1,
stagger: 0.2,
});
</script>
Example: Scroll spy navigation
Create a scroll spy that highlights the current section:
- Add IDs to each section:
about,services,contact - Add
data-nav-itemto corresponding nav links - Use JavaScript to detect scroll position and toggle active states
Related
- Design tokens – For styling elements
- HTML Embed – For adding custom scripts
- Expression editor – For dynamic attribute values