🎨Custom classes & attributes
custom classes, IDs, and data attributes allow you to target elements with custom code, animation libraries, and external scripts.
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.
When to use what
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
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

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 sectionJavaScript targeting:
document.getElementById('my-element')Form labels: Connect labels to inputs with matching IDs
Table of contents: Auto-generate TOC based on heading IDs
IDs must be unique on a page. Using the same ID multiple times can cause unexpected behavior.
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-directionConfiguration: 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-inAdd an HTML Embed with your GSAP script:
Example: Scroll spy navigation
Create a scroll spy that highlights the current section:
Add IDs to each section:
about,services,contactAdd
data-nav-itemto corresponding nav linksUse 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
Last updated
Was this helpful?
