Create a responsive card with auto layout and constraints
This article is available for both the previous Figma UI and the new Figma UI. Use the toggle at the bottom left of the page to select your current UI. Get to know UI3: Figma’s redesign →
Project overview
- Product: Figma design
- Topics: auto layout, constraints, components, shape tools, frames
- Difficulty: Intermediate
- Length: 20 minutes
In this project, we’ll be creating a responsive card design for a podcast app. If you follow along step-by-step, your final prototype will look like this:
To create this design, we’ll do the following:
- Create a play button
- Create the album art
- Create two text layers for metadata
- Add auto layout to album art and metadata
- Apply minimum and maximum dimensions
- Turn the card design into a component
Before you begin, have an image ready on your computer as we’re going to use an image as our album art.
Create a play button
Let’s start by creating the play button’s background first:
- Create a 40 W x 40 H frame.
- Change the fill to
132745
. - Change the corner radius to
100
. - Rename it to “play-button”.
- Click the plus sign in the Effects section to add a drop shadow to the frame.
- Click Effect settings to open the Drop shadow panel.
- Change the Y position to
0
, the Blur to12
, and the opacity to16%
.
Next, let’s add a play icon to the play-button frame.
- From the Shape tools in the toolbar, select Polygon.
- Click and drag inside the play-button frame to create a 16 W x 16 H triangle.
- Hover over the object’s corner until the rotate icon appears.
- Hold Shift and rotate the triangle 90 degree clockwise.
- Change the fill to
FFFFFF
. - Align it to the center of the play-button frame.
You’ll notice a space between the triangle shape and the bounding box. This allows the bounding box to remain a consistent shape or size, and is a helpful tool to achieve an optical alignment.
To test this theory, let’s do a quick experiment:
- Duplicate the play-button frame.
- Select the triangle.
- Right-click and select Flatten.
- Align the triangle with the Align horizontal centers settings from the right sidebar.
Now, compare the two buttons. What do you notice? Even though the flatten triangle is technically centered, it doesn’t look centered due to the uneven distribution of the triangle’s area.
We can turn our play button into a component so it can be reused in multiple designs.
- Select the play-button frame.
- Click Create component from the toolbar bar.
Create the album art frame
- Select Frame from the toolbar or press F to create a 360 W x 240 H frame.
- Rename the frame to “album-art”.
- Change the corner radius to
4
. - Open the Color picker in the Fill section.
- Select Image from the fill options.
- Select Choose image to add an image from your computer.
- Select the album-art frame.
- Open the Actions menu and select Make an image.
- Enter a prompt in the text field. Try to include as much context as possible.
- Click Make it or press Return / Enter.
Add play-button instance to the frame
- Select the play-button component.
- While holding OptionAlt (Windows), click and drag a play-button instance into the album-art frame.
- Hold Option (MacOS) or Alt (Windows) and use the arrow key to align the instance to the bottom-right corner of the album-art frame so that it is 16px to the right and bottom edge of the frame.
Add gradient fill to the album-art frame
You may notice that the play button is blended in with the image (especially when you use a darker image). We want to increase the visibility of the play button against the image. To do that, we can add a gradient fill on top of the image.
- Select the album-art frame.
- Click the plus icon in the Fill section to add another layer fill.
- Update the fill opacity from
20%
to100%
. - Click the layer fill and select Gradient from the color picker panel.
- Select the left color stop in the panel and update its opacity to
0%
. - Select the right color stop in the panel and update its opacity to
60%
. - Hold Shift and drag the top white handle to adjust the size of the gradient.
Apply constraints to the play button
When you resize the album-art frame, you’ll notice that the play button is not responsive to its parent frame.
We can fix this by applying constraints to the play button.
- Select the play-button instance.
- Select Constraints to open the Constraints menu.
- Change the horizontal constraint to Right and the vertical constraint to Bottom.
Now when you resize the album-art frame, the play button will remain at the bottom-right corner of its parent frame. Nice!
Create two text layers for metadata
Next, we’ll create two text layers for the podcast title and the podcast creators.
To create a text layer for the podcast title:
- Select Text from the toolbar or press T.
- Click on canvas to create a text layer.
- Enter the podcast title. In our example, we’ll use “Tasty Bites: Exploring Culinary Delights” for our title.
- In the text properties panel, update the typeface to
Lato
, font weight toBold
and font size to16
. - Update the fill to
132745
. - Press Command R (Mac) or Control R (Windows) to rename the layer to “title”.
Let’s also create a text layer for the podcast creator.
- Duplicate the title layer to create a new text layer for the podcast creators.
- Double-click to edit the new text layer. In our example, the podcast creators will be “FoodieFiends”.
- In the text properties panel, update the font weight to
Medium
and font size to12
. - Press Command R (Mac) or Control R (Windows) to rename the layer to “creator”.
Add auto layout to text layers
Now that our text layers are created, let’s wrap them in an auto layout frame.
- Hold Shift and select both the title and creator layers.
- Press Shift A to add auto layout.
- Rename the new frame to “metadata”.
- Change the Gap between vertical items settings to
4
.
Sometimes when we resize the metadata frame’s width, the text layers is not resizing with their parent frame. That is because the text layers are set to “hug content”, meaning they will only resize if the width of the text changes.
Let’s update the settings:
- Select the metadata frame.
- Press Enter to select both text layers.
- In the right sidebar, update the horizontal resizing to “Fill container”.
Now, try resizing the metadata frame’s width again. This time, the text layers resize with the parent frame. Great!
You’ll notice that the text is pushed to multiple lines when the metadata frame’s width is shorter than the length of the text. In our design, we want to keep our text layer to one line and truncate the extra text.
- Select both the title and creator layers.
- Click Type settings in the Text section.
- Click Truncate text to enable text truncation.
- Set Max lines to
1
.
Add auto layout to the album art and metadata
- Select both album-art and metadata frames.
- Press Shift A to add auto layout.
- Click the plus in the Fill section.
- Update the Gap between vertical items setting to
12
. - Hold Command (Mac) or Ctrl (Wins) and click on the Horizontal padding field to enable All padding field.
- Enter
12
in the field. - Rename the frame to “card”.
- Change the corner radius to
8
.
The card design looks great! But when you resize the card frame, you’ll notice that its child layers are not very responsive. Let’s update the resizing options to fix the issue.
- Select the album-art frame.
- Set both Horizontal resizing and Vertical resizing to “Fill container”.
- Select the metadata frame.
- Set Horizontal resizing to “Fill container”, and Vertical resizing to “Fixed height”.
You may be wondering why the vertical resizing options are set differently on the two frames. That is because we want to keep the height of the metadata frame to two lines, and only the album art frame should stretch to fill the height of the card frame. If you set both the vertical resizing of both frames to fill container, they will both stretch to fill the card frame which is not something we want to achieve.
Try resizing the card again to see how response everything is!
Apply minimum and maximum dimensions
Applying a minimum and maximum width and height to the card will help us avoid funky designs like this:
- Select the card frame.
- Select the Width field and choose Add min width.
- Set the minimum width to
200
. - Select the Width field again and choose Add max width.
- Set the maximum width to
400
. - Repeat the steps in the Height field, and set the minimum height to
240
and maximum height to320
.
Now if you resize the card frame, it will stop resizing when it reaches its minimum or maximum dimensions.
Turn the card into a component
Let’s turn the card design into a component so it can be reused in our designs.
- Select the card frame.
- Click Create component.
What's next?
Our card component is done! Try creating some instances, updating the content, and adding some responsive designs. Have fun!
If you’re interested to learn how to create the podcast card design or the loading animation, check out the following mini projects:
- Product: Figma design
- Topics: auto layout, constraints, components, shape tools, frames
- Difficulty: Intermediate
- Length: 20 minutes
In this project, we’ll be creating a responsive card design for a podcast app. If you follow along step-by-step, your final prototype will look like this:
To create this design, we’ll do the following:
- Create a play button
- Create the album art
- Create two text layers for metadata
- Add auto layout to album art and metadata
- Apply minimum and maximum dimensions
- Turn the card design into a component
Before you begin, have an image ready on your computer as we’re going to use an image as our album art.
Create a play button
Let’s start by creating the play button’s background first:
- Create a 40 W x 40 H frame.
- Change the fill to
132745
. - Change the corner radius to
100
. - Rename it to “play-button”.
- Click the plus sign in the Effects section to add a drop shadow to the frame.
- Click Effect settings to open the Drop shadow panel.
- Change the Blur to
12
, the Y position to0
and the opacity to16%
.
Next, let’s add a play icon to the play-button frame.
- From the Shape tools in the toolbar, select Polygon.
- Click and drag inside the play-button frame to create a 16 W x 16 H triangle.
- Hover over the object’s corner until the rotate icon appears.
- Hold Shift and rotate the triangle 90 degree clockwise.
- Change the fill to
FFFFFF
. - Align it to the center of the play-button frame.
You’ll notice a space between the triangle shape and the bounding box. This allows the bounding box to remain a consistent shape or size, and is a helpful tool to achieve an optical alignment.
To test this theory, let’s do a quick experiment:
- Duplicate the play-button frame.
- Select the triangle.
- Right-click and select Flatten.
- Align the triangle with the Align horizontal centers settings from the right sidebar.
Now, compare the two buttons. What do you notice? Even though the flatten triangle is technically centered, it doesn’t look centered due to the uneven distribution of the triangle’s area.
We can turn our play button into a component so it can be reused in multiple designs.
- Select the play-button frame.
- Click Create component from the toolbar bar.
Create the album art frame
- Select Frame from the toolbar or press F to create a 360 W x 240 H frame.
- Rename the frame to “album-art”.
- Change the corner radius to
4
. - Open the Color picker in the Fill section.
- Select Image from the fill options.
- Select Choose image to add an image from your computer.
Add play-button instance to the frame
- Select the play-button component.
- While holding OptionAlt (Windows), click and drag a play-button instance into the album-art frame.
- Hold Option (MacOS) or Alt (Windows) and use the arrow key to align the instance to the bottom-right corner of the album-art frame so that it is 16px to the right and bottom edge of the frame.
Add gradient fill to the album-art frame
You may notice that the play button is blended in with the image (especially when you use a darker image). We want to increase the visibility of the play button against the image. To do that, we can add a gradient fill on top of the image.
- Select the album-art frame.
- Click the plus icon in the Fill section to add another layer fill.
- Update the fill opacity from
20%
to100%
. - Click the layer fill and select Gradient from the color picker panel.
- Select the left color stop in the panel and update its opacity to
0%
. - Select the right color stop in the panel and update its opacity to
60%
. - Hold Shift and drag the top white handle to adjust the size of the gradient.
Apply constraints to the play button
When you resize the album-art frame, you’ll notice that the play button is not responsive to its parent frame.
We can fix this by applying constraints to the play button.
- Select the play-button instance.
- From the Constraints panel, change the horizontal constraint to Right and the vertical constraint to Bottom.
Now when you resize the album-art frame, the play button will remain at the bottom-right corner of its parent frame. Nice!
Create two text layers for metadata
Next, we’ll create two text layers for the podcast title and the podcast creators.
To create a text layer for the podcast title:
- Select Text from the toolbar or press T.
- Click on canvas to create a text layer.
- Enter the podcast title. In our example, we’ll use “Tasty Bites: Exploring Culinary Delights” for our title.
- In the text properties panel, update the typeface to
Lato
, font weight toBold
and font size to16
. - Update the fill to
132745
. - Press Command R (Mac) or Control R (Windows) to rename the layer to “title”.
Let’s also create a text layer for the podcast creator.
- Duplicate the title layer to create a new text layer for the podcast creators.
- Double-click to edit the new text layer. In our example, the podcast creators will be “FoodieFiends”.
- In the text properties panel, update the font weight to
Medium
and font size to12
. - Press Command R (Mac) or Control R (Windows) to rename the layer to “creator”.
Add auto layout to text layers
Now that our text layers are created, let’s wrap them in an auto layout frame.
- Hold Shift and select both the title and creator layers.
- Press Shift A to add auto layout.
- Rename the new frame to “metadata”.
- Change the Gap between vertical items settings to
4
.
Sometimes when we resize the metadata frame’s width, the text layers is not resizing with their parent frame. That is because the text layers are set to “hug content”, meaning they will only resize if the width of the text changes.
Let’s update the settings:
- Select the metadata frame.
- Press Enter to select both text layers.
- In the right sidebar, update the horizontal resizing to “Fill container”.
Now, try resizing the metadata frame’s width again. This time, the text layers resize with the parent frame. Great!
You’ll notice that the text is pushed to multiple lines when the metadata frame’s width is shorter than the length of the text. In our design, we want to keep our text layer to one line and truncate the extra text.
- Select both the title and creator layers.
- Click Type settings in the Text section.
- Click Truncate text to enable text truncation.
- Set Max lines to
1
.
Add auto layout to the album art and metadata
- Select both album-art and metadata frames.
- Press Shift A to add auto layout.
- Click the plus in the Fill section.
- Update the Gap between vertical items setting to
12
. - Hold Command (Mac) or Ctrl (Wins) and click on the Horizontal padding field to enable All padding field.
- Enter
12
in the field. - Rename the frame to “card”.
- Change the corner radius to
8
.
The card design looks great! But when you resize the card frame, you’ll notice that its child layers are not very responsive. Let’s update the resizing options to fix the issue.
- Select the album-art frame.
- Set both Horizontal resizing and Vertical resizing to “Fill container”.
- Select the metadata frame.
- Set Horizontal resizing to “Fill container”, and Vertical resizing to “Fixed height”.
You may be wondering why the vertical resizing options are set differently on the two frames. That is because we want to keep the height of the metadata frame to two lines, and only the album art frame should stretch to fill the height of the card frame. If you set both the vertical resizing of both frames to fill container, they will both stretch to fill the card frame which is not something we want to achieve.
Try resizing the card again to see how response everything is!
Apply minimum and maximum dimensions
Applying a minimum and maximum width and height to the card will help us avoid funky designs like this:
- Select the card frame.
- Select the Width field and choose Add min width.
- Set the minimum width to
200
. - Select the Width field again and choose Add max width.
- Set the maximum width to
400
. - Repeat the steps in the Height field, and set the minimum height to
240
and maximum height to320
.
Now if you resize the card frame, it will stop resizing when it reaches its minimum or maximum dimensions.
Turn the card into a component
Let’s turn the card design into a component so it can be reused in our designs.
- Select the card frame.
- Click Create component.
What's next?
Our card component is done! Try creating some instances, updating the content, and adding some responsive designs. Have fun!
If you’re interested to learn how to create the podcast card design or the loading animation, check out the following mini projects: