1. 3
    Style Astro Pages with Many Different Options
    9m 4s

Style Astro Pages with Many Different Options

InstructorLazar Nikolov

Share this video with your friends

Send Tweet

You'll learn the various styling approaches available to you in Astro.

By default, all styles are scoped to the file you are in so you won't need to worry too much about specificity and clashing styles in your Astro projects. We'll explore a page that is using general selectors like h1 to style the header of that page. You can force a style in the global scope by the is:global directive or the :global() function on a specific selector.

Next, you'll learn about conditional styles and how to set JavaScript variables to pass to your styles for more dynamic controls. You can specify class:list={[{red: isRed}]} on an element which will conditionally apply the red class based on the isRed variable you have set in your JavaScript.

Likewise, you can pass variables down to your <style> tags by adding the define:vars directive to the tag. This works great for setting variables for more flexibility in your styles.

Other styling options are available, you can import stylesheets or add tailwind to your Astro project.