CSS to Figma Auto Layout
CSS to Figma Auto Layout: Flexbox और Grid की mapping गाइड
CSS to Figma Auto Layout mapping कैसे होती है: flex-direction, gap, padding, alignment, flex-grow, wrap, grid और max-width, साथ में साफ़ import के tips।
EUREKA! · · 10 मिनट का लेख

अगर आप front-end code लिखते हैं, तो Figma का Auto Layout जाना-पहचाना लगता है: एक direction, एक gap, padding, alignment, और children जो hug या fill करते हैं। ऐसे में यह मान लेना आसान है कि CSS to Figma Auto Layout एक-से-एक translation है — लेकिन ऐसा नहीं है। Flexbox और Grid कहीं ज़्यादा समृद्ध हैं, browser margins, percentages और intrinsic sizes को resolve करता है जिन्हें Auto Layout model नहीं करता, और एक ही visual result बिल्कुल अलग-अलग CSS से बन सकता है।
यह गाइड बताती है कि HTML to Frames CSS layouts को Auto Layout पर कैसे map करता है, हर result को browser से verify क्यों किया जाता है, सीमाएँ कहाँ हैं, और ऐसी CSS कैसे लिखें जो साफ़ import हो।
तरीका: पहले geometry, फिर inference
एक सीधा-सादा converter display: flex पढ़कर properties copy कर देता है। यह जल्दी टूट जाता है: gap: 0 वाला flex container जिसके children पर margins हैं, एक block element जो सिर्फ़ दिखने में vertical stack है, या ऐसा grid जो दो साफ़ rows में render होता है।
HTML to Frames इस बात से काम करता है कि browser ने असल में क्या render किया:
- Pixel-exact बनाना. पेज पहले Figma में absolute positions के साथ बनता है, जो browser की नापी हुई geometry से ली जाती हैं।
- अंदर से बाहर चलना. सबसे गहरे frames से शुरू करके plugin positions और sizes से vertical और horizontal stacks, wrapping rows, gaps, padding और alignment निकालता है।
- Responsive मतलब जोड़ना. बीच में रखा content Center बनता है, max-width boxes बीच में ही रहते हैं, बराबर cards और
flex-growFill बनते हैं, और "logo … menu … icons" वाली bar में बीच का gap item Fill बनता है। - Verify करना. Auto Layout लगाया जाता है, फिर हर child की position original से मिलाई जाती है, 2 px की छूट के साथ।
- सुरक्षित fallback. अगर result टिकता नहीं, तो एक आसान plan आज़माया जाता है। वह भी fail हो, तो frame समझदार constraints (Stretch, Scale, Center, Min, Max) के साथ absolute positions पर रहता है।
क्योंकि inference render हुई geometry से शुरू होता है, इसलिए block elements का stack भी flex column की तरह ही vertical Auto Layout बन जाता है। CSS का mechanism उतना मायने नहीं रखता जितना result। बड़ी तस्वीर के लिए Auto Layout explained पढ़ें।
CSS to Figma Auto Layout mapping table: कौन सी property किस setting में बदलती है
आम CSS patterns आम तौर पर ऐसे map होते हैं। इसे अपेक्षित result समझें, वादा नहीं; आख़िरी फ़ैसला verification का होता है।
| CSS | Figma Auto Layout result | ध्यान दें |
|---|---|---|
flex-direction: column | Vertical Auto Layout | सामान्य block flow की stacking भी यहीं map होती है |
flex-direction: row | Horizontal Auto Layout | |
row-reverse, column-reverse | Render हुए क्रम में stack | Layers दिखने वाले क्रम में रहती हैं |
gap: 24px | Item spacing 24 | असली दूरी नापकर |
| Siblings के बीच बराबर margins | Item spacing | दूरियाँ consistent हों तो निकाला जाता है |
padding: 32px 24px | Padding ऊपर/नीचे 32, बाएँ/दाएँ 24 | Children की offset से नापा जाता है |
justify-content: flex-start | Primary axis: start | |
justify-content: center | Primary axis: center | |
justify-content: flex-end | Primary axis: end | |
justify-content: space-between | Space between, या gap item Fill बनता है | Header bars अक्सर logo, Fill, icons बनती हैं |
align-items: center | Counter axis: center | |
align-items: stretch | Counter axis पर children Fill | जब children सच में stretch हों |
flex: 1 / flex-grow: 1 | Primary axis पर Fill container | बराबर cards बराबर Fill items बनते हैं |
Child पर fixed width | Fixed width | |
| Content के हिसाब से size वाला child | Hug contents | |
flex-wrap: wrap | Wrapping rows | Auto Layout का wrap mode |
बराबर columns वाला display: grid | Wrapping rows या nested stacks | जो verify हो उस पर निर्भर |
Spans वाला grid-template-columns | Nested horizontal/vertical stacks | Spans overlap करें तो absolute |
max-width + margin: 0 auto | Full-width frame के अंदर बीच में box | Resize पर content box बीच में रहता है |
position: absolute | अपने frame में absolute, constraints के साथ | Overlap stack में नहीं बैठता |
position: fixed / sticky | Present mode में fixed या sticky व्यवहार | Prototypes में headers काम करते रहते हैं |
z-index | Layer order | Browser की stacking से मेल |
transform: rotate() / scale() | Rotation और scale लागू | Skew और 3D अभी supported नहीं |
Flexbox विस्तार से
Direction और order
flex-direction तय करता है कि container horizontal stack बनेगा या vertical। क्योंकि inference render हुई positions से होता है, इसलिए reversed directions और order से layers बस दिखने वाले क्रम में बनती हैं। Browser में जो दिखता है, layers panel में वही मिलता है।
Gap और padding
gap सबसे साफ़ input है: children के बीच एक ही, consistent दूरी, जो सीधे Auto Layout की item spacing में बदल जाती है। Siblings के बीच margins तब काम करते हैं जब वे consistent हों। अगर नहीं हैं — मान लीजिए 16, 24, 16 — तो plugin इसे एक gap के रूप में नहीं दिखा सकता, और verification या तो कोई दूसरा plan चुनेगा या positions को absolute रखेगा।
Padding इस बात से नापी जाती है कि children container के अंदर असल में कहाँ बैठे हैं, इसलिए padding, border की चौड़ाई और अंदरूनी margins — सब result में जुड़ते हैं।
Justify और align
justify-content primary axis के alignment में और align-items counter axis के alignment में बदलता है। दिलचस्प case है space-between। "logo … menu … icons" जैसे header में plugin बीच के gap item को Fill बना देता है, ताकि resize करने पर logo बाएँ रहे, icons दाएँ रहें और बीच का हिस्सा खिंचे। यही वह responsive मतलब है जिसकी आप उम्मीद करेंगे — न कि कोई fixed spacing value जो सिर्फ़ एक width पर काम करे।
flex-grow और Fill
flex-grow या flex: 1 वाले children Fill container बनते हैं। बराबर cards की rows बराबर Fill items बन जाती हैं, इसलिए parent frame resize करने पर cards एक साथ resize होते हैं, बिल्कुल browser की तरह।
Wrapping
flex-wrap: wrap Auto Layout के wrap mode में बदलता है और wrapping rows बनाता है। Flexbox से बनी tag lists, logo walls और card grids के लिए यह सबसे स्वाभाविक fit है।
CSS Grid विस्तार से
Figma का Auto Layout एक stack model है, two-dimensional grid नहीं। इसलिए grid layouts को उस सबसे नज़दीकी structure में map किया जाता है जो verify हो जाए:
- Uniform grids (बराबर columns, बराबर gaps) आम तौर पर wrapping rows बनते हैं।
- Asymmetric grids (sidebar और main column, या 2:1 का बँटवारा) आम तौर पर nested stacks बनते हैं: vertical stacks का एक horizontal stack, या इसका उल्टा।
- Span और overlap करने वाले cells, जो stacks में नहीं टूटते, constraints के साथ absolute positions पर रहते हैं।
हर हाल में दिखने वाला result tolerance के अंदर browser से मेल खाता है। फ़र्क बस इतना है कि Figma में frame का कितना हिस्सा आप लचीले ढंग से resize कर पाते हैं।
Absolute positioning, centring और auto margins
position: absolute
Absolute position वाला badge, कोई decorative blob या overlay किसी stack में नहीं बैठता, क्योंकि वह अपने siblings पर overlap करता है। ऐसे elements absolute positions पर रहते हैं, और plugin उन्हें constraints देता है ताकि parent resize होने पर भी वे ठीक व्यवहार करें: ऊपर-दाएँ लगा badge ऊपर-दाएँ ही रहता है, पूरा ढकने वाला overlay खिंच जाता है।
max-width और margin: auto
Classic content container, max-width: 1200px; margin: 0 auto, full-width frame के अंदर एक बीच में रखा box बनता है। यहीं Site width की भूमिका आती है: plugin import के समय पेज की असली design width नापता है। Full-bleed डिज़ाइन 1920 पर content box को बीच में रखकर आते हैं, सच में boxed sites अपनी box width पर, और fluid sites 1440 पर। नापी गई value आपके container के logic को बरकरार रखती है।
Flex के अंदर auto margins
किसी flex child पर margin-left: auto उसे आख़िर तक धकेल देता है — nav bars में यह आम pattern है। space-between की तरह यह भी geometry से निकाला जाता है, आम तौर पर एक Fill gap item के रूप में, जो धकेले गए element को दूर वाले किनारे पर रखता है।
Auto Layout verification क्यों ज़रूरी है
Verification के बिना converters के पास दो बुरे विकल्प होते हैं: हर जगह Auto Layout लगा दें और मान लें कि कुछ frames खिसकेंगे, overlap करेंगे या सिकुड़ जाएँगे; या Auto Layout से बचें और आपको जमी हुई absolute layers थमा दें।
HTML to Frames Auto Layout लगाता है, फिर हर child की position 2 px के अंदर जाँचता है। कोई frame fail हो, तो आसान plan आज़माया जाता है; वह भी fail हो, तो frame absolute रहता है। डिज़ाइन कभी नहीं टूटता। आप भरोसा कर सकते हैं कि Figma में जो दिख रहा है वह browser से मेल खाता है, और जो Auto Layout मिला है वह सच में टिकता है।
Results screen कुल Auto Layout का हिस्सा दिखाती है, और जो frames absolute रहे उनके लिए वजह बताती है (diagnostics)। इससे "यह Auto Layout क्यों नहीं बना?" वाला सवाल ऐसी चीज़ बन जाता है जिस पर आप अपनी CSS में काम कर सकते हैं।
असली sites पर हमारे tests में लगभग 86 से 97 प्रतिशत frames पर Auto Layout निकला — जैसे एक product site पर 93 प्रतिशत और Linear व Stripe पर 88 प्रतिशत। आपके numbers इस पर निर्भर करेंगे कि CSS कैसे लिखी गई है।
किन सीमाओं का पता होना चाहिए
- Two-dimensional grid का concept Auto Layout में है ही नहीं; grids wrapping rows या nested stacks बनते हैं, और complex spans absolute रह सकते हैं।
- Siblings के बीच inconsistent spacing को एक gap के रूप में नहीं दिखाया जा सकता।
- Overlap (negative margins, absolute children) वाले elements absolute ही रहते हैं।
- Skew और 3D transforms,
path()clip-paths, multi-layer masks और Display-P3 colors अभी convert नहीं होते। - iframes, WebGL canvas और बिना poster वाले videos जैसा embedded content अपने box के screenshot image के रूप में आता है।
- एक बार में एक width. हर screen अपनी width पर layout होती है। हर breakpoint को अलग frame के रूप में पाने के लिए responsive set (Desktop, Tablet, Mobile) इस्तेमाल करें।
Tips: ऐसी CSS लिखें जो साफ़ import हो
इन आदतों से आपके layouts ज़्यादा बार Auto Layout में map होते हैं — और वैसे भी ये अच्छी CSS practice हैं।
- Sibling margins की जगह
gapइस्तेमाल करें। एक consistent value सीधे item spacing बन जाती है। - एक container के अंदर spacing consistent रखें। मिली-जुली spacing से fallback होता है।
- One-dimensional layouts के लिए flexbox चुनें। Navs, toolbars, button groups और card rows सीधे map होते हैं।
- Card grids के लिए बराबर tracks वाला grid इस्तेमाल करें। Uniform columns साफ़ wrapping rows बनते हैं।
- Asymmetric layouts को साफ़ containers में लपेटें। अपनी flex row में रखा sidebar और content area साफ़ nested stacks बनाता है।
- जिन elements को खिंचना है उन पर
flex: 1लगाएँ। इससे Fill का संकेत मिलता है। - Content को
max-widthऔरmargin: 0 autoसे बीच में रखें। यह ऐसा box बनता है जो बीच में ही रहता है। position: absoluteसिर्फ़ असली overlays के लिए रखें। आम layout के लिए इसका इस्तेमाल न करें।- Layout के लिए negative margins से बचें। इनसे overlap बनता है जिसे stack नहीं किया जा सकता।
- Colors को custom properties से नाम दें। Styles & variables (Pro) के साथ
--brand-primaryएकbrand/primaryvariable बन जाता है। - असली text इस्तेमाल करें। Images के अंदर का text editable text layers नहीं बन सकता।
अपनी CSS की mapping ख़ुद देखें
आपकी CSS कैसे map होती है, यह समझने का सबसे तेज़ तरीका है उसे import करके देखना। HTML to Figma flow से code paste करें या folder upload करें, Chrome extension से localhost build capture करें, या किसी AI tool से उसे MCP के ज़रिए भेजें। फिर results screen खोलें, Auto Layout का हिस्सा देखें, और जो frames absolute रहे उनके diagnostics पढ़ें।
Reference screenshot (Pro) चालू करें, ताकि original पेज की एक hidden, locked layer जुड़ जाए और आप import और browser render के बीच toggle कर सकें। जब ज़्यादा विस्तृत layer structure चाहिए, तो Detailed layers (Pro) चालू करें।
पेज frames में कैसे बदलते हैं, इस पर और जानने के लिए HTML to frame conversion के बारे में पढ़ें, और importer जो कुछ support करता है उसके लिए features देखें। हर import option की पूरी जानकारी docs में है।
अक्सर पूछे जाने वाले सवाल
- क्या HTML to Frames Auto Layout बनाने के लिए मेरी CSS पढ़ता है?
- यह CSS properties copy नहीं करता, बल्कि browser की render की हुई geometry से काम करता है। पहले पेज pixel-exact बनाया जाता है, फिर अंदर से बाहर की ओर stacks, gaps, padding और alignment निकाले जाते हैं। हर child की position 2 px के अंदर verify होती है, इसलिए result वही दिखता है जो browser ने बनाया था — चाहे layout flexbox से आया हो, grid से या सादे block flow से।
- जब Figma में grid वाला Auto Layout है ही नहीं, तो CSS Grid कैसे convert होता है?
- Grid को उस सबसे नज़दीकी structure में बदला जाता है जो verify हो जाए। बराबर columns वाले uniform grids आम तौर पर wrapping rows बनते हैं, asymmetric layouts nested horizontal और vertical stacks बनते हैं, और complex spans या overlap वाले cells constraints के साथ absolute positions पर रहते हैं। दोनों ही हालात में दिखने वाला result browser जैसा रहता है।
- जब कोई frame Auto Layout नहीं बन पाता, तो क्या होता है?
- पहले एक आसान layout plan आज़माया जाता है। अगर वह भी verification में fail हो जाए, तो frame absolute positions पर रहता है और उसे Stretch, Scale, Center, Min या Max जैसे समझदार constraints मिलते हैं, ताकि resize करने पर भी वह ठीक व्यवहार करे। Results screen बताती है कि हर ऐसा frame absolute क्यों रहा, जिससे आप अपनी CSS सुधार सकते हैं।
- क्या flex-grow Figma में Fill container बन जाता है?
- हाँ, आम तौर पर यही होता है। flex-grow या flex: 1 से बढ़ने वाले children Fill container बनते हैं, और बराबर cards की rows बराबर Fill items बन जाती हैं। जिन header bars में logo, menu और icons दूर-दूर फैले हों, वहाँ बीच का gap item Fill बनता है, ताकि frame resize करने पर बाहरी elements किनारों से चिपके रहें।
- आम तौर पर किसी पेज का कितना हिस्सा Auto Layout में आता है?
- असली sites पर हमारे tests में लगभग 86 से 97 प्रतिशत frames पर Auto Layout निकला — जैसे एक product site पर 93 प्रतिशत और Linear व Stripe पर 88 प्रतिशत। Result इस पर निर्भर करता है कि CSS कैसे लिखी गई है; consistent gaps, flexbox और साफ़ containers से यह हिस्सा बढ़ता है।
Web pages को दोबारा हाथ से बनाना अब बंद।
Link paste कीजिए और कुछ ही सेकंड में असली, editable, responsive Figma layers पाइए। शुरुआत मुफ़्त है — हर महीने 10 imports।
