Introduction: Making Our Recipe Page Look Great

Welcome back! So far, you have built the basic structure for your recipe detail page and learned how to display recipe information using TypeScript and Angular. Now, it’s time to make your page more visually appealing and easier to use. In this lesson, you will learn how to style your recipe detail view using Angular’s component-specific style files.

In Angular, each component can have its own style file that controls the appearance of its template. This allows you to change colors, fonts, spacing, and layout for just that component, making your page easier to read and more enjoyable for users.

By the end of this lesson, you will know how to use a component’s style file in Angular to style your recipe detail page.

Quick Recall: Our Current Recipe Detail Page

Before we start styling, let’s quickly review what we have so far. In previous lessons, you created an Angular component for your recipe detail page and used TypeScript to display the recipe’s title, rating, ingredients, and steps.

Here’s a simplified example of what your Angular template might look like (you do not need to write this again, just remember):

Right now, this page probably looks very plain. All the elements are there, but there’s no color, spacing, or special styling. This is where Angular’s component styles come in!

How Angular Handles Component Styles

In Angular, each component can have its own style file, such as recipe.component.css. When you create a component, Angular automatically links this style file to the component’s template. This means any styles you add to recipe.component.css will affect only the RecipeComponent and not the rest of your app.

You do not need to manually link the style file — Angular takes care of this for you. Just add your style rules to recipe.component.css, and they will be applied to the template of your recipe detail page.

Understanding the Provided Recipe Styles

Let’s look at the style rules you will use to make your recipe page look great. We’ll go through each part step by step, showing how each rule appears in recipe.component.css and how it affects your Angular template.

Step 1: Styling the Container

This rule adds space inside the main container, so the content doesn’t touch the edges. In your Angular template, this means everything inside <div class="recipe-container"> will have some breathing room.

Step 2: Styling the Title

This rule makes the recipe title larger and adds a little space below it. In your template, the <h1>{{ recipe.title }}</h1> will stand out and look more like a page heading.

Step 3: Styling the Rating

This rule makes the rating text a gray color and adds space below it. In your template, the <div class="rating">{{ recipe.rating }}</div> will appear less prominent, helping the title stand out more.

Step 4: Styling Lists

These rules add space to the left of your ingredients and steps lists, and space below each item. In your template, the <ul> and <ol> elements, along with their <li> children, will be easier to read and better organized.

Step 5: Styling the Action Button
  • The .actions rule moves the button to the right and adds space above it. In your template, the <div class="actions"> will align its content to the right.
  • The .start-btn rule makes the button green, adds padding, rounds the corners, and makes the text bold and white. The <a class="start-btn">Start Cooking</a> will look like a real button.
  • The .start-btn:hover rule changes the button color when you move your mouse over it, making it interactive.
What Happens When You Use These Styles

When you add these style rules to your recipe.component.css file, your recipe detail page will look much more organized and pleasant. The title will stand out, the lists will be easy to read, and the button will look inviting and clickable — all within your Angular component.

Summary and What’s Next

In this lesson, you learned how to use a component-specific style file in Angular to style your recipe detail page. You saw how each style rule changes the look and feel of your component, making it more user-friendly and visually appealing.

Next, you will get a chance to practice applying and tweaking these styles yourself. You’ll see how small changes in your component’s style file can make a big difference in how your app looks. When you’re ready, move on to the practice exercises to try it out!

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal