<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[A Beginner's Guide to Flexbox]]></title><description><![CDATA[A Beginner's Guide to Flexbox]]></description><link>https://beginnerflexbox.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 18 Jun 2026 19:14:16 GMT</lastBuildDate><atom:link href="https://beginnerflexbox.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[A Beginner's Guide to Flexbox]]></title><description><![CDATA[Flexbox is a powerful and flexible CSS layout system that allows you to create responsive and dynamic layouts with ease.

What is Flexbox?
Flexbox allows you to control the layout of items inside a container, making it ideal for building responsive d...]]></description><link>https://beginnerflexbox.hashnode.dev/a-beginners-guide-to-flexbox</link><guid isPermaLink="true">https://beginnerflexbox.hashnode.dev/a-beginners-guide-to-flexbox</guid><category><![CDATA[CSS]]></category><category><![CDATA[flexbox]]></category><category><![CDATA[HTML5]]></category><dc:creator><![CDATA[Oshini Nawarathna]]></dc:creator><pubDate>Fri, 22 Nov 2024 03:40:54 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1732189168333/d242b014-4aeb-482d-92cb-bd92e08d983a.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Flexbox is a powerful and flexible CSS layout system that allows you to create responsive and dynamic layouts with ease.</p>
<hr />
<h3 id="heading-what-is-flexbox">What is Flexbox?</h3>
<p>Flexbox allows you to control the layout of items inside a container, making it ideal for building responsive designs. To enable Flexbox, set the container's <code>display</code> property to <code>flex</code></p>
<pre><code class="lang-css">
<span class="hljs-selector-class">.flex-container</span> {
  <span class="hljs-attribute">display</span>: flex;
}
</code></pre>
<hr />
<h3 id="heading-basic-flexbox-properties">Basic Flexbox Properties</h3>
<p>1. <strong>Flex Direction</strong></p>
<p>The <code>flex-direction</code> property determines the direction of the items inside the flex container. Options are:</p>
<ul>
<li><p><code>row</code> (default)</p>
</li>
<li><p><code>column</code></p>
<pre><code class="lang-css">  <span class="hljs-selector-class">.flex-container</span> {
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">flex-direction</span>: column;
  }
  <span class="hljs-selector-class">.flex-item</span> {
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">20px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#add8e6</span>;
    }
</code></pre>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1732189783663/d5e52d93-4bc4-45e1-b5e3-3dab8004c619.png" alt /></p>
<p>2. <strong>Justify Content</strong></p>
<p>This property controls how items are spaced along the main axis (horizontal by default). Options:</p>
<ul>
<li><code>flex-start</code>, <code>center</code>, <code>space-between</code>, <code>space-around</code></li>
</ul>
<pre><code class="lang-css"><span class="hljs-selector-class">.flex-container</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">justify-content</span>: center;
}
<span class="hljs-selector-class">.flex-item</span> {
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#add8e6</span>;
  }
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1732189861568/86479e6d-c27d-4bd6-97e6-a3b6ca519e07.png" alt /></p>
<p>3. <strong>Align Items</strong></p>
<p>Aligns items along the cross axis (vertical by default). Options:</p>
<ul>
<li><code>flex-start</code>, <code>center</code>, <code>stretch</code></li>
</ul>
<pre><code class="lang-css">
<span class="hljs-selector-class">.flex-container</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">align-items</span>: center;
}
<span class="hljs-selector-class">.flex-item</span> {
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#add8e6</span>;
}
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1732189934637/eeff1caa-a714-4f6a-b69f-66afca0400cb.png" alt /></p>
<p>4. <strong>Flex Wrap</strong></p>
<p>By default, items will stay in one line. To allow items to wrap to the next line:</p>
<pre><code class="lang-css">
<span class="hljs-selector-class">.flex-container</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">flex-wrap</span>: wrap;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">2px</span>;
}
<span class="hljs-selector-class">.flex-item</span> {
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#add8e6</span>;
  }
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1732190084132/29dfb24d-27db-4f47-9031-fc4435c873cd.png" alt /></p>
<hr />
<h3 id="heading-example-simple-flexbox-layout">Example: Simple Flexbox Layout</h3>
<pre><code class="lang-html">
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex-container"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex-item"</span>&gt;</span>Item 1<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex-item"</span>&gt;</span>Item 2<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex-item"</span>&gt;</span>Item 3<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<pre><code class="lang-css">
<span class="hljs-selector-class">.flex-container</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">justify-content</span>: space-between;
}

<span class="hljs-selector-class">.flex-item</span> {
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">background-color</span>: lightblue;
}
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1732189061146/b2acb9c8-84b4-44c1-86bc-6a59363db452.png" alt /></p>
<ul>
<li><p><strong>Flexbox Layout</strong>: The code creates a Flexbox layout with three items inside a flex container.</p>
</li>
<li><p><code>display: flex</code>: The container uses <code>display: flex</code> to enable Flexbox, making its child elements behave as flex items.</p>
</li>
<li><p><code>justify-content: space-between</code>: This property spaces the items evenly along the horizontal axis, with no space at the start or end.</p>
</li>
</ul>
<hr />
<p>Flexbox is a simple yet powerful tool to create flexible layouts. By mastering properties like <code>flex-direction</code>, <code>justify-content</code>, and <code>align-items</code>, you can build responsive designs quickly.</p>
<p><strong>Happy Coding!</strong> 😊</p>
]]></content:encoded></item></channel></rss>