Conditional classes (class:name) in Svelte
📖 Scenario: You are building a simple to-do list app. Each task can be marked as done or not done. You want to show done tasks with a different style.
🎯 Goal: Create a Svelte component that shows a list of tasks. Use conditional classes with class:done to style tasks that are done.
📋 What You'll Learn
Create a list of tasks with exact names and done status
Create a variable to track the minimum number of done tasks to highlight
Use a
for loop to display tasksUse
class:done to conditionally add a CSS class based on task status💡 Why This Matters
🌍 Real World
Conditional classes are used in real apps to change styles dynamically, like marking completed tasks or highlighting active menu items.
💼 Career
Knowing how to use conditional classes in Svelte is important for building interactive user interfaces that respond to user actions.
Progress0 / 4 steps