Add custom classes and IDs to Shopify forms for advanced styling and JavaScript targeting. This essential snippet gives you complete control over contact forms, product forms, and other Shopify form elements, enabling custom designs that match your store's branding.
Add custom classes/IDs to any Shopify form for precise styling
Easily target forms with JavaScript using custom IDs
Works with contact forms, product forms, and more
Seamlessly works with any Shopify theme
{% comment %} Add Class or ID to Form Adds custom classes/IDs to Shopify forms for styling Provided by XeeZone - www.xeezone.com/free-shopify-code-snippets-by-xeezone {% endcomment %} {% form 'contact', id: 'custom-contact-form', class: 'custom-form-class' %} {% endform %} {% form 'product', product, id: 'product-form', class: 'product-form-class' %} {% endform %}
Find your contact form (usually in templates/contact.liquid
) and product form (typically in sections/product-template.liquid
)
Replace existing {% form %}
tags with the enhanced versions from the snippet
Change the class and ID names to match your preferred naming convention
Create corresponding CSS rules in your theme's stylesheet using your new classes/IDs
Update any JavaScript selectors to use your new form IDs for functionality
Pro Tip: Use BEM (Block Element Modifier) naming convention for your classes (e.g., .contact-form__input--error
) to maintain scalable CSS architecture.