Skip to main content
Create new
Introduction
Reactivity
Props
Logic
Events
Bindings
Lifecycle
Stores
Motion
Transitions
Animations
Easing
SVG
Actions
Classes
Component composition
Context API
Special elements
Module context
Debugging
7GUIs
Miscellaneous
App.svelte
<script>
function action(node) {
node.classList.add('green'); // class is added dynamically
}
</script>

<p use:action>text</p>

<style>
p:global(.green) {
/* this will apply to all <p> elements belonging to this
component with a class of red, even if class="red" does
not appear in the markup. This is useful when the class
of the element is dynamically applied, for instance
when updating the element's classList property directly. */
color: green;
}
</style>
loading Svelte compiler...
/* Select a component to see its compiled code */
result = svelte.compile(source, {
generate: ,
});
/* Select a component to see its compiled code */