There's No Difference: Translating Figma Components and Frames to HTML/CSS Code
Andre Liem
Innovative Business Development Leader | IT Solution Developer | Tech-Savvy Networker
As I play around with Figma and work on improving the right side of my brain with designer projects, I can't help to think about how all of these fancy, beautiful layouts get translated to code? The reason for my question are two-fold. One, I'm a dev dude who tries to stay focus on the end-deliverables. Two, Figma took away dev mode from its free version so I had to gain a little bit more experience in order to understand how to do the translations correctly. Here's what I learned through a general example.
As you know with Figma, you create elements on a canvas using components or frames. You will usually use the former more often because they are ideal for creating consistent and repeatable UI elements, such as buttons, icons, or cards. However, there could be times when frames are better for unique elements, layout-specific elements, complex/nested structures, responsive elements, and prototyping purposes.
You can also create transformation in Figma for these elements. For instance, using hugging, it will allow for your elements to act responsively to the environment or content within it. Hugging ensures that designs remain consistent and well-structured, even when content is updated or modified.
Now, back to my concern: how to translate the above mentions to code and are there any coding difference between a component or a frame? It's good to know that there really is no difference. Both components and frames in Figma represent visual elements that can be translated into HTML elements with corresponding CSS styles. When you design a component or frame in Figma and apply various properties such as size, position, background color, typography, etc., those properties can be translated into equivalent CSS properties regardless of whether the element is a component or a frame.
So, taking an example of a custom button that you define as either a component or frame with hugging, the code translation is below:
HTML
<button class="custom-button">Click Me</button>
CSS
.custom-button {
width: auto;
min-width: fit-content;
领英推荐
height: auto;
min-height: fit-content;
background-color: #007bff;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 4px;
font-size: 16px;
}
Ok, this makes sense. So then, why the difference?
The main differences between components and frames in Figma lie in their behavior and usage within the design tool itself. The real advantage of using components and frames in Figma is that they help you create a well-structured, organized, and efficient design based on their specific purposes. They allow you to work with reusable elements, maintain consistency, and iterate quickly. These benefits are realized within the design phase and contribute to a more streamlined and effective design workflow.
Therefore...
As a dev dude designing who now has to work on coding, all I would have to do is look at the overall structure and styles defined in Figma, regardless of whether elements are components or frames, and implement them using appropriate HTML elements and CSS styles. Well, that's a relief!
Absolutely agree with your point on adaptability in web design! As Heraclitus might say, change is the only constant. Embracing this in design leads to innovation and growth ?? #DesignThinking
數位行銷DM × 人力資源HR?專案管理 | 社群媒體經營 | 廣告投放與策略規劃 | GMO Product Marketing Executive | Project Management | Content Marketing Specialist | Social Media Marketing | Digital Marketing | Public Relations | Ad Operations
7 个月A few hours ago,I recently posted about current No Code tools and automation apps. Feel free to share your thoughts and suggestions ?? https://www.dhirubhai.net/feed/update/urn:li:activity:7186397352264413184/