Monday, September 18, 2023
HomeCSSThe CSS behind Figma

The CSS behind Figma

While discovering just how to construct a Figma plugin, I came across a couple of intriguing uses of Flexbox and also Grid in Figma. When I discovered them, I simply obtained sidetracked and also could not withstand excavating extra.

Flexbox and also Grid have actually been offering us internet programmers with great deals of brand-new abilities to construct brand-new formats, and also what I will certainly reveal you in this short article is simply that.

To relocate along with this short article, you do not require to have a thorough understanding of Flexbox or Grid, and also I will certainly attempt to discuss most instances from scratch.

Allow’s obtain uncovering.


The objective of this review is to demonstrate how effective flexbox and also grid are and also to highlight those intriguing use-cases for them. There could be a couple of little bits that are concentrated on refined UI information which I such as quite.

Making Use Of CSS Grid

On the ideal side of Figma, we have the default “Style” tab. When picking an aspect on the canvas, we can see its x-axis, y-axis, size, and also elevation worths. This additionally can be various relying on the component being a message, team, structure, and also extra.

What I discovered intriguing right here is making use of CSS grid for every row in the style tab. I dig that so, a lot.

Think about the complying with number.

Notification just how we have lots of lines. Those are for the 28 columns, yes! You review that right. Any type of row in the style tab is improved top of that grid.

Each column has a size of 8px

 raw_components-- _ singleRow  {
   screen:  grid;
   grid-template-columns:   repeat( 28, 8px);
   grid-template-rows:  32px;

Additionally, when regulating the information of a decline darkness, as an example, the very same grid is being made use of.

For me, this is a best usage for CSS grid, although from the very first look you could believe that those are little formats, yet once again, it’s a really legitimate use CSS grid.

Positioning switches

In this use, each positioning switch is taking 4 columns (32px) of the grid. Notification just how the symbol itself is well focused as well.

 raw_components-- _ singleRow  {
   screen:  grid;
   grid-template-columns:   repeat( 28, 8px);
   grid-template-rows:  32px;

 raw_components-- _ iconButton  {
   grid-column-end:  period 4;

Aspect setting

In this instance, we see just how the inputs for the x-axis and also y-axis are split, in addition to the newish “Outright setting” switch.

Automobile format

The little bit that I discovered really intriguing is the Automobile Design controls.

We have a 28-column * 2 rows grid this time around to fit for the controls that aid us in straightening the youngster products within an Automobile Design container.

 stack_panel_v4-- doubleRow  {
   screen:  grid;
   grid-template-columns:   repeat( 28, 8px);
   grid-template-rows:   repeat( 2, 32px);

Cool. Allow’s explore the information!

On the grid degree, each component is placed making use of grid-column or grid-row or both.

The positioning dots you see are constructed from an SVG pattern. What a great information, and also use!

And Also not just that yet there is a 3 * 3 grid which contains 9 grid products. I think that those are right here to act as a clickable location for every positioning.

 alignment_view_v4-- tooltipGrid  {
   screen:  grid;
   grid-template-rows:   repeat( 3, 1fr);
   grid-template-columns:   repeat( 3, 1fr);

Following, is the indication container where we have the symbol that demonstrates how the aspects within an Automobile Design container are straightened.

To make points less complicated to recognize, I split that entire square right into 4 components:

  • Base histories
  • SVG dots
  • The 3 * 3 grid where we have clickable locations
  • Indication container (heaven symbol)

We will certainly concentrate on the indication container in the meantime. Allow’s take a look at the base markup and also CSS.

<< <<<<<<
  <<  In the above markup, we have both the indication container, and also the positioning symbol. I suched as that the symbol itself is developed  and also straightened with flexbox. alignment_view_v4-- indicatorContainer { setting
    :  outright ; leading:  1px; right:  1px;
     base:   1px; left:  1px; screen:  flex
    ; flex-direction :  column; justify-content:  facility; align-items: 
 Keeping That, we'll have 2 Flexbox wrappers, when for the  indicatorContainer component and also the various other for the symbol itself.

Below is the designing for heaven symbol. We have a flex container with column as an instructions, after that 3 products that stand for heaven lines in their various dimensions.

 alignment_view_v4-- indicatorGroup  {
   screen:  flex;
   flex-direction:  column;
   align-items:  facility;
   justify-content:  space-between;
   size:  20px;
   elevation:  20px;
  } alignment_view_v4-- indication { elevation
  :  4px; border-radius
  :  1px;}
 alignment_view_v4-- indication: nth-child( 1 )

{ size:


 alignment_view_v4-- indication: nth-child( 2 )  {
   size:  16px;
  } alignment_view_v4-- indication: nth-child( 3 ) { size
  :  7px;} 
   What impresses me right here is that when we transform the positioning for an Automobile Design component, both the  indicatorContainer and also  indicatorGroup
   will certainly show that. Below is an instance where Automobile Design is readied to  leading left positioning
   alignment_view_v4-- indicatorContainer { justify-content: 

;  align-items
  :  flex-start;}
   alignment_view_v4-- indicatorGroup { align-items: 

; } 
   Making use of flexbox For the layer panel rows In the number over, we have a major structure called "Indication up_001", and also within it, there are 3 embedded products. The even more the nesting, the extra spacing we have actually from the delegated make it clear that there is nesting. Upon examining the rows, right here is what I discovered: 
 Each row is a flex moms and dad, therefore I highlighted the 

 flex  tag alongside the HTML moms and dad.
   See it at work in the complying with number:  Cool, yet the inquiry is: just how the spacing functions? I truthfully anticipated it prior to examining it and also had not been shocked. The spacing takes place by including  spacer elements
 Each spacer part has a size of 

 16px , and also all areas have a 
   margin-right: 8px with the exception of the very first one. With even more nesting in position, the rows will certainly appear like this. Since the aesthetic side is clear, allow's have a look at the markup and also designs.



< <
  < We have 2 flexbox moms and dads, one for the entire row and also the various other for the spacer elements (The group Figma called them indents, and also I such as that name). object_row {

:   flex
  ; elevation:  32px


object_row– indents



: flex;


: 100%;

} object_row-- layerIcon { size:



} object_row-- rowText  { size:  calc( 100% - 16px
); flex-shrink: 1;} object_row-- rowActions
{ size : 0;} With the above, the nesting will certainly occur by including a brand-new spacer component. Think about the complying with markup. We have 2 spacers which indicates that this row is the very first one in its team.<<<

<< <<<<<<<<<
< Isn't that simply intriguing, and also cool down? Seeing my preferred style device utilizing my preferred CSS function is simply. outstanding. Various other Flexbox use-cases Flexbox is being made use of greatly for the little elements. Allow's check out a few of them. Stroke information For shades, Flexbox is being made use of for regulating the shade worth and also the opacity. As well as on concerns to the very same context, when the customer floats over the dropdown food selection, it will certainly broaden the message fully readily available area by utilizing flex-grow: 1 File shades In this instance, it's much better to utilize Flexbox so we can obtain the advantage of the covering. Or else, making use of CSS grid will not supply us with the very same outcome.
Restrictions part We have several Flexbox containers right here. The very first one is for the leading, center, and also lower rows. The 2nd one is for the center product, which is a Flexbox container itself. Verdict That's it for this expedition. I appreciated checking out such one-of-a-kind and also enjoyable use for both Flexbox and also Grid. It's motivating to see that in a device we'll utilize, and also for me, it motivated me to check out much more utilize instances for the CSS devices we have actually. If you enjoy that kind of short articles, I released a deep-dive right into my expedition on constructing the Facebook Carrier conversation bubble Thanks for analysis.


Most Popular

Recent Comments