Component file (.svelte) anatomy
📖 Scenario: You are building a simple Svelte component to display a greeting message on a webpage. This will help you understand the basic structure of a Svelte component file.
🎯 Goal: Create a Svelte component file with the correct sections: a script block for JavaScript, a style block for CSS, and markup for HTML content. The component will show a greeting message styled with a color.
📋 What You'll Learn
Create a
<script> block with a variable greeting set to 'Hello, Svelte!'Add a
<style> block that sets the text color of a class .greeting to blueWrite HTML markup that uses a
<h1> element with class greeting to display the greeting variableEnsure the component file has all three sections properly placed
💡 Why This Matters
🌍 Real World
Svelte components are the building blocks of modern web apps. Understanding their structure helps you create interactive and styled UI parts.
💼 Career
Knowing how to organize Svelte files is essential for frontend developer roles using Svelte. It improves code readability and maintainability.
Progress0 / 4 steps