How to add a custom class to an element
Learn how to manually add a custom CSS class to an element using an override in Framer.
This article explains how to modify an element’s className by creating an override. This approach is useful when you need to apply a custom class for styling or targeting purposes.
Create an override
To add a custom class, you’ll need to use an override that modifies the element’s className property. Overrides let you extend or adjust an element’s behavior without changing its core structure.
Write the override code
Use the override to append a custom class to the existing className. Always include a leading space so the new class is separated correctly.
Once applied, the element’s rendered HTML will include the additional class, similar to the example below:
After adding the override:
Publish your project in Framer.
Open your site in a browser.
Use the browser’s web inspector to select the element.
Confirm that the custom class appears in the element’s
classattribute.
Important notes
This method works best for small, targeted adjustments.
Extensive manual modifications can limit the level of support Framer can provide if issues arise.
How do I add a custom class to an element in Framer?
To add a custom class to an element in Framer, create an override that modifies the className property of the element. This method allows you to append your custom class to the element’s existing className.
Can you provide an example of adding a custom class using an override?
Yes. Here is an example override that appends the class 'test' to an element’s existing className: import type { ComponentType } from "react"; export function withClass(Component): ComponentType { return (props) => { props.className += " test"; // Remember to add a space return <Component {...props} />; }; }
Are there any important considerations when manually adding classes in Framer?
This approach is ideal for minor adjustments. Keep in mind that delving too deeply into manual modifications may limit the support Framer can provide.
Updated