<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ responsive design - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ responsive design - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Thu, 14 May 2026 15:00:26 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/responsive-design/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Media Queries vs Container Queries – Which Should You Use and When? ]]>
                </title>
                <description>
                    <![CDATA[ As the web evolves, new tools and ideas are released with the goal of making our lives as web developers easier. This means we have to choose whether to stick with the old ways or discard them entirely for the shiny new stuff. But does this always de... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/media-queries-vs-container-queries/</link>
                <guid isPermaLink="false">66c5a3401078112e60c1e703</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ responsive design ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ophy Boamah ]]>
                </dc:creator>
                <pubDate>Fri, 28 Jun 2024 20:21:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/06/titleimage.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>As the web evolves, new tools and ideas are released with the goal of making our lives as web developers easier. This means we have to choose whether to stick with the old ways or discard them entirely for the shiny new stuff. But does this always demand an either-or solution?</p>
<p>When in situations like these, the ideal approach is to understand both concepts – compare and contrast their strengths and weaknesses and then decide their most appropriate applications. This is exactly what this article will do with CSS media queries and container queries.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><a class="post-section-overview" href="#heading-responsive-and-intrinsic-web-design">Responsive and Intrinsic Web Design</a></li>
<li><a class="post-section-overview" href="#heading-what-are-media-queries">What are media queries?</a></li>
<li><a class="post-section-overview" href="#heading-what-are-container-queries">What are container queries?</a></li>
<li><a class="post-section-overview" href="#heading-how-do-media-queries-and-container-queries-compare">Real-life comparison and key differences</a></li>
<li><a class="post-section-overview" href="#heading-which-should-you-use-and-when">Which should you use and when?</a></li>
<li><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></li>
</ul>
<h2 id="heading-responsive-and-intrinsic-web-design">Responsive and Intrinsic Web Design</h2>
<p>Before 2010, web developers could get away with creating websites that worked mainly on desktop. This was until Ethan Marcotte introduced the concept of Responsive Web Design (RWD). It's <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Responsive_Design">defined by MDN</a> as <em>a way to design for a multi-device web</em>. This lead to the adoption of media queries as a component of RWD. </p>
<p>But lately there's been a shift towards what Jen Simmons defined as Intrinsic Web Design – the need for creating context-aware components. And container queries are making this possible.</p>
<h2 id="heading-what-are-media-queries">What Are Media Queries?</h2>
<p>Media queries are rules for applying specified styles to an element if certain conditions are met. They’re popularly used to ensure that websites are responsive on various devices by querying the viewport width. </p>
<p>Media queries are characterized by an @media rule followed by a condition in parentheses and an expression within brackets that will be applied if the indicated condition is met. So, if we wanted to change the background color of a div based on the viewport width of a device, this is how we might do that:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Mobile */</span>
<span class="hljs-keyword">@media</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">480px</span>) {
  <span class="hljs-selector-class">.mysite</span> {
    <span class="hljs-attribute">background-color</span>: red;
  }
}
</code></pre>
<p>In the sample code above, we’re asking for the </p><div> with class of mysite to be given a background-color of red if the viewport reaches a maximum width of 480px.<p></p>
<p><strong>Tip</strong>: Max-width is used to assume a desktop-first design and targeting smaller as we go down. If it were a mobile-first design, we'd use min-width to target bigger screens as we go up.</p>
<h2 id="heading-what-are-container-queries">What Are Container Queries?</h2>
<p>Container queries are rules for applying specified styles to an element based on the size of that element’s parent container. They're an answer to a long-standing question by web developers who wanted the ability to respond to changes within an individual container on the page rather than the whole viewport.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.header</span> {
   <span class="hljs-attribute">container</span>: mysite / inline-size;
}

<span class="hljs-keyword">@container</span> mysite (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">600px</span>) {
   <span class="hljs-selector-class">.maincard</span> {
       <span class="hljs-attribute">grid-template-column</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
    }
   <span class="hljs-selector-class">.item</span> {
       <span class="hljs-attribute">background-color</span>: green;
    }
}
</code></pre>
<p>As you can see in the code above, we first define a container whose children we want to make changes to. In our case, we’d like to make changes to the element with class of item, within the header container. You can do this by giving the container a name (optional) and type. </p>
<p>Next, using the @container rule, we check for condition(s) and apply some styles if met. For a minimum width of 600px, we want green as the background-color and two grid columns.</p>
<p><strong>Tip</strong>: You don't define a container to make changes directly to that container – but to it's children. This means that if we wanted to make changes to the header container itself, we would have to nest it within another container: for instance container A and query A to affect it's child – header.</p>
<h2 id="heading-how-do-media-queries-and-container-queries-compare">How Do Media Queries and Container Queries Compare?</h2>
<p>Now, with an understanding of how both work, let's see them in real-life. The CodePen below shows four elements in a layout. The first two are styled with container queries while the bottom two are styled with media queries. You can resize the viewport to see how the elements respond.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/06/mqvscq-demo.png" alt="Image" width="600" height="400" loading="lazy">
<em>Media and container queries CodePen demo: project inspired by Miriam Suzanne.</em></p>
<p></p><p>
  <span>See the Pen <a href="https://codepen.io/ophyboamah/pen/YzbaROw">
  MQ vs CQ (from MS)</a> by Ophy Boamah (<a href="https://codepen.io/ophyboamah">@ophyboamah</a>)
  on <a href="https://codepen.io">CodePen</a>.</span>
</p><p></p>


<h3 id="heading-key-differences-between-media-queries-and-container-queries">Key Differences Between Media Queries and Container Queries</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/06/comparetable.png" alt="Image" width="600" height="400" loading="lazy">
<em>Summary of main differences, explained in detail below</em></p>
<h3 id="heading-viewport-based-vs-container-based">Viewport-based vs. Container-based</h3>
<p>Media queries apply styles based on the size of the viewport (the entire browser window). This means that the layout changes according to the overall screen size, making it suitable for adjusting designs for different devices like mobile phones, tablets, and desktops. </p>
<p>Container queries, on the other hand, apply styles based on the size of the container element in which they are placed. This allows individual components to adapt their appearance based on their own size rather than the viewport size, making them highly flexible and reusable across different parts of a web page.</p>
<h3 id="heading-modularity-and-flexibility">Modularity and Flexibility</h3>
<p>Since media queries depend on the viewport size, they can be less effective for creating truly modular components. Adjusting styles for one part of a page may unintentionally affect others, especially in complex layouts. Plus, they may fall short in scenarios where components need to adapt independently within a larger layout. This can lead to less maintainable CSS. </p>
<p>In contrast, container queries promote modularity and flexibility by allowing styles to be defined based on the container's size. This means you can create components that are self-contained, adaptable, and that can be reused in various parts of a website without unexpected changes, enhancing their reusability. </p>
<p>This results in more adaptive designs where components can adjust their own layout and appearance, which is useful in modern, component-based design systems.</p>
<h3 id="heading-complexity-and-maintenance">Complexity and Maintenance</h3>
<p>In large projects, managing numerous media queries can become cumbersome. As the number of breakpoints and special cases grows, the CSS can become complex and harder to maintain. Over time, this can lead to a bloated and difficult-to-manage codebase. </p>
<p>Container queries can simplify the maintenance of CSS in large projects. By keeping styles component-specific and context-aware, the CSS remains more organized and modular. This reduces the complexity of managing global breakpoints and makes it easier to maintain, leading to a more organized codebase.</p>
<h2 id="heading-which-should-you-use-and-when">Which Should You Use and When?</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/06/finalsection.png" alt="Image" width="600" height="400" loading="lazy">
<em>Media query vs container query (image credit: <i><a target="_blank" href="http://web.dev/">web.dev</a></i>)</em></p>
<p>Everything we discussed in the previous sections is meant to help you make an informed decision. Having seen how these two concepts compare and contrast, now consider the following factors:</p>
<h3 id="heading-understanding-and-comfort">Understanding and Comfort</h3>
<p>How well do you understand each concept? Container queries are relatively new but if you spend time studying and experimenting with them, just like media queries, the learning curve isn’t intimidating. So use in production the one you understand and are more comfortable with, to make your life easier.</p>
<h3 id="heading-project-requirements-and-complexity">Project Requirements and Complexity</h3>
<p>What’s the design approach you’re using and how complex is your project? Because sometimes the design approach for your project will determine which of these will best suit your needs. Also, the more complex, the harder it’ll get to maintain your code and you want to use something you can manage.</p>
<h3 id="heading-future-trends-and-collaboration">Future Trends and Collaboration</h3>
<p>The future of responsive design is looking more and more intrinsic. We’re gradually making a shift towards component responsiveness based on changes to their individual content, and container queries shine best here. </p>
<p>But media queries don't seem to be going anywhere anytime soon, so you can use them together to achieve perfect responsiveness across many different devices.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>The potential for container queries to allow creating reusable components in CSS is exciting – but it may not be ready to fully replace media queries for making web pages responsive just yet. </p>
<p>For now, our best bet is using them together, and where each makes the most sense. And you can be sure to make the right call by experimenting further to internalize the pros and cons of each.</p>
<p>Here are some helpful resources:</p>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/learn-css-media-queries-by-building-projects/">freeCodeCamp on Media Queries</a></li>
<li><a target="_blank" href="https://ishadeed.com/article/css-container-query-guide/">Ahmad Shadeed on Container Queries</a></li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=2rlWBZ17Wes">How to Use Media Queries and Container Queries</a></li>
</ul>
</div> ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use Breakpoints for Responsive Web Design ]]>
                </title>
                <description>
                    <![CDATA[ Breakpoints are fundamental to the concept of responsive web design. They enable websites to adapt seamlessly across different devices and screen sizes.  Breakpoints mark the points at which a website's layout and content should change to ensure opti... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/breakpoints-for-responsive-web-design/</link>
                <guid isPermaLink="false">66c4c3b8e486f65d4125b7f9</guid>
                
                    <category>
                        <![CDATA[ responsive design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Design ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Joan Ayebola ]]>
                </dc:creator>
                <pubDate>Mon, 24 Jun 2024 18:03:30 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/06/Ivory-and-Blue-Lavender-Aesthetic-Photo-Collage-Presentation--13-.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Breakpoints are fundamental to the concept of responsive web design. They enable websites to adapt seamlessly across different devices and screen sizes. </p>
<p>Breakpoints mark the points at which a website's layout and content should change to ensure optimal user experience on devices ranging from smartphones and tablets to desktop computers. </p>
<p>It's really important for today's web designers to know how breakpoints work and use them smartly. This helps them create websites that work well on all kinds of devices and are easy for people to use.</p>
<p>In this article, we'll explore breakpoints in detail: why they matter, how to use them effectively, and their role in making websites adjust smoothly to different screen sizes.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ol>
<li><a class="post-section-overview" href="#heading-what-is-responsive-web-design-rwd">What is Responsive Web Design?</a></li>
<li><a class="post-section-overview" href="#heading-why-are-breakpoints-important-in-rwd">Why are Breakpoints Important in RWD?</a></li>
<li><a class="post-section-overview" href="#heading-common-breakpoint-ranges-for-responsive-design-2024">Common Breakpoint Ranges for Responsive Design (2024)</a></li>
<li><a class="post-section-overview" href="#heading-factors-to-consider-when-choosing-the-right-breakpoints-for-your-project">Factors to Consider When Choosing the Right Breakpoints for Your Project</a></li>
<li><a class="post-section-overview" href="#heading-basic-structure-of-a-media-query">Basic Structure of a Media Query</a></li>
<li><a class="post-section-overview" href="#heading-advanced-breakpoint-techniques">Advanced Breakpoint Techniques</a></li>
<li><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></li>
</ol>
<h2 id="heading-what-is-responsive-web-design-rwd">What is Responsive Web Design (RWD)?</h2>
<p>Responsive Web Design (RWD) is an approach to web design that ensures web pages render well on a variety of devices and window or screen sizes. </p>
<p>It involves using fluid grids, flexible images, and CSS media queries to automatically adapt the layout and content of a website to the device's screen size and orientation. </p>
<p>The goal of responsive web design is to provide an optimal viewing and interaction experience, ensuring easy reading and navigation with minimal resizing, panning, and scrolling across a wide range of devices, from desktop computers to mobile phones.</p>
<h2 id="heading-why-are-breakpoints-important-in-rwd">Why are Breakpoints Important in RWD?</h2>
<p>Breakpoints are important in Responsive Web Design (RWD) because they define specific points where a website's layout and content should adapt to different screen sizes and devices. </p>
<p>Here’s why they are crucial:</p>
<h3 id="heading-device-compatibility">Device Compatibility</h3>
<p>Breakpoints enable websites to adjust their design and layout to ensure compatibility with various devices like smartphones, tablets, laptops, and desktops. This adaptability ensures that users have a consistent and optimized experience regardless of the device they use.</p>
<h3 id="heading-optimal-user-experience">Optimal User Experience</h3>
<p>Designers can use breakpoints to tailor the presentation of content, navigation, and functionality based on screen size. This customization enhances user experience by ensuring content is readable, accessible, and easy to interact with across devices.</p>
<h3 id="heading-fluidity-in-design">Fluidity in Design</h3>
<p>Instead of creating fixed-width designs that may not scale well, breakpoints allow for fluid grids and flexible elements. This approach ensures that the design remains visually appealing and functional, regardless of the screen dimensions.</p>
<h3 id="heading-content-prioritization">Content Prioritization</h3>
<p>With breakpoints, designers can prioritize and reorganize content based on device capabilities and user needs. This ensures that essential information remains accessible and prominent, enhancing usability and engagement.</p>
<h3 id="heading-performance-optimization">Performance Optimization</h3>
<p>Breakpoints make websites load faster and work better on different devices by adjusting how they look and work based on each device's size and type. This is crucial for retaining user interest and reducing bounce rates, particularly on mobile devices with slower internet connections.</p>
<h3 id="heading-seo-friendliness">SEO Friendliness</h3>
<p>Responsive websites with well-implemented breakpoints provide a seamless user experience across devices. Search engines value responsive design because it improves accessibility and usability, potentially leading to better search engine rankings.</p>
<h2 id="heading-common-breakpoint-ranges-for-responsive-design-2024">Common Breakpoint Ranges for Responsive Design (2024)</h2>
<p>In 2024, responsive web design commonly employs a mobile-first approach, ensuring websites are designed to function and look good on smaller screens before scaling up. </p>
<p>Here are the typical breakpoint ranges used for different screen sizes:</p>
<p><strong>Extra Small Screens (Mobile):</strong></p>
<ul>
<li>Range: Up to 576px viewport width</li>
<li>Description: Targets smartphones and small mobile devices in portrait mode.</li>
</ul>
<p><strong>Small Screens (Tablets):</strong></p>
<ul>
<li>Range: 577px to 768px viewport width</li>
<li>Description: Includes larger smartphones and smaller tablets in portrait mode.</li>
</ul>
<p><strong>Medium Screens (Large Tablets):</strong></p>
<ul>
<li>Range: 769px to 1024px viewport width</li>
<li>Description: Targets larger tablets and smaller desktop screens in landscape mode.</li>
</ul>
<p><strong>Large Screens (Desktops):</strong></p>
<ul>
<li>Range: 1025px to 1440px viewport width</li>
<li>Description: Targets standard desktop screens and larger laptops.</li>
</ul>
<p><strong>Extra Large Screens (Large Desktops):</strong></p>
<ul>
<li>Range: 1441px and above viewport width</li>
<li>Description: Includes large desktop monitors and wide-screen displays.</li>
</ul>
<h3 id="heading-example-css-media-queries">Example CSS Media Queries:</h3>
<pre><code class="lang-css"><span class="hljs-comment">/* Example of CSS media queries for common breakpoint ranges */</span>

<span class="hljs-comment">/* Extra Small Screens (Mobile) */</span>
<span class="hljs-keyword">@media</span> <span class="hljs-keyword">only</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">576px</span>) {
  <span class="hljs-comment">/* CSS rules specific for extra small screens */</span>
  <span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>; <span class="hljs-comment">/* Adjust layout for full-width on small screens */</span>
  }
}

<span class="hljs-comment">/* Small Screens (Tablets) */</span>
<span class="hljs-keyword">@media</span> <span class="hljs-keyword">only</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">577px</span>) <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">768px</span>) {
  <span class="hljs-comment">/* CSS rules specific for small screens */</span>
  <span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">80%</span>; <span class="hljs-comment">/* Adjust layout for smaller container width on tablets */</span>
  }
}

<span class="hljs-comment">/* Medium Screens (Large Tablets) */</span>
<span class="hljs-keyword">@media</span> <span class="hljs-keyword">only</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">769px</span>) <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">1024px</span>) {
  <span class="hljs-comment">/* CSS rules specific for medium screens */</span>
  <span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">70%</span>; <span class="hljs-comment">/* Adjust layout for moderate container width on large tablets */</span>
  }
}

<span class="hljs-comment">/* Large Screens (Desktops) */</span>
<span class="hljs-keyword">@media</span> <span class="hljs-keyword">only</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">1025px</span>) <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">1440px</span>) {
  <span class="hljs-comment">/* CSS rules specific for large screens */</span>
  <span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">60%</span>; <span class="hljs-comment">/* Adjust layout for narrower container width on desktops */</span>
  }
}

<span class="hljs-comment">/* Extra Large Screens (Large Desktops) */</span>
<span class="hljs-keyword">@media</span> <span class="hljs-keyword">only</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">1441px</span>) {
  <span class="hljs-comment">/* CSS rules specific for extra large screens */</span>
  <span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">50%</span>; <span class="hljs-comment">/* Adjust layout for even narrower container width on large desktops */</span>
  }
}
</code></pre>
<p>In this example:</p>
<ul>
<li>Each media query targets a specific range of viewport widths to adjust the layout and styling of the <code>.container</code> element accordingly.</li>
<li>The percentages used for <code>width</code> in the examples demonstrate how designers can progressively adjust content presentation to optimize user experience across various devices and screen sizes.</li>
</ul>
<h2 id="heading-factors-to-consider-when-choosing-the-right-breakpoints-for-your-project">Factors to Consider When Choosing the Right Breakpoints for Your Project</h2>
<p>Choosing the right breakpoints for your project involves considering several factors:</p>
<h3 id="heading-target-audience-and-devices">Target Audience and Devices</h3>
<p>Understand the devices your target audience uses. This includes screen sizes of smartphones, tablets, laptops, and desktops. Prioritize breakpoints that align with these devices to ensure a seamless user experience.</p>
<h3 id="heading-content-complexity">Content Complexity</h3>
<p>Evaluate how your content responds to different screen sizes. Complex layouts may require additional breakpoints to maintain readability and usability across devices.</p>
<h3 id="heading-design-requirements">Design Requirements</h3>
<p>Your design specifications play an important role. Consider breakpoints that accommodate specific design elements such as navigation menus, images, forms, and grids. Ensure that these elements adapt well to different screen sizes.</p>
<h3 id="heading-analyzing-device-usage-statistics">Analyzing Device Usage Statistics</h3>
<p>Use analytics to determine the most common screen sizes among your audience. Focus on breakpoints that optimize user experience on these prevalent devices.</p>
<h2 id="heading-basic-structure-of-a-media-query">Basic Structure of a Media Query</h2>
<p>Implementing breakpoints with media queries is essential for creating responsive web designs that adapt to different screen sizes and devices. </p>
<p>A media query allows you to apply CSS styles based on certain conditions, such as screen width, height, device orientation, etc. The basic syntax of a media query is:</p>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> media-type <span class="hljs-keyword">and</span> (media-feature) {
  <span class="hljs-comment">/* CSS styles */</span>
}
</code></pre>
<p>Where:</p>
<ul>
<li><code>media-type</code> specifies the type of media, typically <code>screen</code> for devices with screens.</li>
<li><code>media-feature</code> defines the condition, such as <code>width</code>, <code>min-width</code>, <code>max-width</code>, <code>orientation</code>, and so on.</li>
</ul>
<p>Now let's talk about how you can structure and use media queries effectively.</p>
<h3 id="heading-using-min-width-and-max-width-for-breakpoints">Using min-width and max-width for Breakpoints</h3>
<p>The most common approach to defining breakpoints is using <code>min-width</code> and <code>max-width</code> media features.</p>
<p><strong><code>min-width</code></strong>: Specifies the minimum width at which the styles should apply. It targets screens wider than the specified width.</p>
<p>Example:</p>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">768px</span>) {
  <span class="hljs-comment">/* Styles for screens wider than 768px */</span>
}
</code></pre>
<p><strong><code>max-width</code></strong>: Specifies the maximum width at which the styles should apply. It targets screens narrower than the specified width.</p>
<p>Example:</p>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">1024px</span>) {
  <span class="hljs-comment">/* Styles for screens narrower than or equal to 1024px */</span>
}
</code></pre>
<h3 id="heading-media-queries-for-different-breakpoint-ranges">Media Queries for Different Breakpoint Ranges</h3>
<p>To create a responsive design that adapts to various devices, you typically define multiple breakpoints to cover different screen sizes:</p>
<h4 id="heading-small-screens-mobile-phones">Small Screens (Mobile Phones):</h4>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">576px</span>) {
  <span class="hljs-comment">/* Styles for small screens */</span>
}
</code></pre>
<h4 id="heading-medium-screens-tablets">Medium Screens (Tablets):</h4>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">577px</span>) <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">992px</span>) {
  <span class="hljs-comment">/* Styles for medium screens */</span>
}
</code></pre>
<h4 id="heading-large-screens-desktops-and-laptops">Large Screens (Desktops and Laptops):</h4>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">993px</span>) {
  <span class="hljs-comment">/* Styles for large screens */</span>
}
</code></pre>
<h4 id="heading-extra-large-screens-large-desktops-and-monitors">Extra Large Screens (Large Desktops and Monitors):</h4>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">1200px</span>) {
  <span class="hljs-comment">/* Styles for extra large screens */</span>
}
</code></pre>
<h3 id="heading-example-comprehensive-media-queries">Example: Comprehensive Media Queries</h3>
<p>Here’s an example of how you might implement media queries for a responsive layout:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Default styles for all screens */</span>
<span class="hljs-selector-tag">body</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">16px</span>;
}

<span class="hljs-comment">/* Small screens (phones) */</span>
<span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">576px</span>) {
  <span class="hljs-selector-tag">body</span> {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">14px</span>;
  }
}

<span class="hljs-comment">/* Medium screens (tablets) */</span>
<span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">577px</span>) <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">992px</span>) {
  <span class="hljs-selector-tag">body</span> {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">16px</span>;
  }
}

<span class="hljs-comment">/* Large screens (desktops and laptops) */</span>
<span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">993px</span>) {
  <span class="hljs-selector-tag">body</span> {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">18px</span>;
  }
}

<span class="hljs-comment">/* Extra large screens (large desktops and monitors) */</span>
<span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">1200px</span>) {
  <span class="hljs-selector-tag">body</span> {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">20px</span>;
  }
}
</code></pre>
<p>In this example:</p>
<ul>
<li>Font sizes adjust based on the screen size to ensure readability and optimal user experience.</li>
<li>Each media query targets specific ranges of screen widths using <code>min-width</code> and <code>max-width</code>.</li>
<li>Adjustments in font size are used here for demonstration purposes, but you can apply any CSS styles needed for your design.</li>
</ul>
<h2 id="heading-advanced-breakpoint-techniques">Advanced Breakpoint Techniques</h2>
<p>Implementing advanced breakpoint techniques enhances the responsiveness and adaptability of your web designs. </p>
<p>Here are several techniques you can use:</p>
<h3 id="heading-1-container-queries-adapting-to-content-width">1. Container Queries (Adapting to Content Width)</h3>
<p><strong>Container queries</strong> allow elements to respond not to the viewport size but to their own container's dimensions. This is particularly useful when you want elements to adapt based on their parent container's width rather than the overall screen width.</p>
<p>Example using a hypothetical container query syntax (not currently natively supported, but evolving in standards like CSS Houdini):</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-comment">/* Apply styles based on container width */</span>
}

<span class="hljs-keyword">@container</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">600px</span>) {
  <span class="hljs-selector-class">.container</span> {
    <span class="hljs-comment">/* Adjust styles for containers wider than 600px */</span>
  }
}
</code></pre>
<p>Container queries are highly anticipated as they provide more granular control over responsive design within individual components or sections.</p>
<h3 id="heading-2-flexible-units-ems-rems-for-responsive-layouts">2. Flexible Units (ems, rems) for Responsive Layouts</h3>
<p><strong>Flexible units</strong> like <code>em</code> (relative to the font-size of the element) and <code>rem</code> (relative to the font-size of the root element) are essential for creating scalable and responsive layouts.</p>
<h4 id="heading-using-em-and-rem">Using em and rem:</h4>
<ul>
<li><code>em</code> units scale relative to their parent element's font size. This can be useful for creating modular designs where elements resize proportionally.</li>
<li><code>rem</code> units are relative to the root element (<code>html</code>), providing a consistent base for scaling across the entire document.</li>
</ul>
<pre><code class="lang-css"><span class="hljs-comment">/* Example using rem for scalable font sizes */</span>
<span class="hljs-selector-tag">body</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">16px</span>; <span class="hljs-comment">/* Base font size */</span>
}

<span class="hljs-selector-tag">h1</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">2rem</span>; <span class="hljs-comment">/* 32px on 16px base */</span>
}

<span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1.5rem</span>; <span class="hljs-comment">/* 24px on 16px base */</span>
}

<span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">768px</span>) {
  <span class="hljs-selector-tag">body</span> {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">14px</span>; <span class="hljs-comment">/* Adjust base font size for smaller screens */</span>
  }
}
</code></pre>
<h3 id="heading-3-using-css-grid-and-flexbox-for-responsive-design">3. Using CSS Grid and Flexbox for Responsive Design</h3>
<p><strong>CSS Grid</strong> and <strong>Flexbox</strong> are powerful layout tools that offer flexible and responsive design options.</p>
<p><strong>CSS Grid</strong>: Ideal for two-dimensional layouts, allowing precise control over rows and columns. Grids can adapt to different screen sizes with media queries or grid-auto-flow properties.</p>
<p>Example of responsive grid layout:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(auto-fit, minmax(<span class="hljs-number">250px</span>, <span class="hljs-number">1</span>fr));
  <span class="hljs-attribute">grid-gap</span>: <span class="hljs-number">20px</span>;
}

<span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">768px</span>) {
  <span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr;
  }
}
</code></pre>
<p><strong>Flexbox</strong>: Best for simpler one-dimensional layouts or aligning items within a container. It’s great for navigation bars, sidebars, and elements within a grid cell.</p>
<p>Example of responsive Flexbox layout:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">justify-content</span>: space-between;
}

<span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">768px</span>) {
  <span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">flex-direction</span>: column;
  }
}
</code></pre>
<ul>
<li><strong>Container Queries</strong> are evolving and promise more precise control over responsive design elements based on their container's size.</li>
<li><strong>Flexible Units</strong> (<code>em</code>, <code>rem</code>) allow scalable and accessible typography and layout proportions across various screen sizes.</li>
<li><strong>CSS Grid</strong> and <strong>Flexbox</strong> provide robust layout options for creating responsive designs that adapt to different devices and viewport sizes.</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In conclusion, breakpoints play a pivotal role in crafting a responsive web design that adapts seamlessly across different devices and screen sizes. </p>
<p>The flexibility offered by media queries, utilizing <code>min-width</code> and <code>max-width</code> to define breakpoints, allows for precise control over how content and layouts respond to varying viewport dimensions. </p>
<p>Advanced techniques like container queries (as they evolve), flexible units (<code>em</code>, <code>rem</code>), and leveraging CSS Grid and Flexbox further enhance the adaptability and scalability of designs.</p>
<p>In essence, breakpoints are not just technical specifications but critical decisions that impact user interaction and satisfaction. </p>
<p>Connect with me on <a target="_blank" href="https://www.linkedin.com/in/joanayebola">LinkedIn</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ The CSS Flexbox Handbook – Complete Guide with Practical Examples ]]>
                </title>
                <description>
                    <![CDATA[ Flexbox is a useful tool for creating beautiful and responsive layouts for web pages. In this guide, you will learn everything you need to know to start using CSS Flexbox like a pro. We'll also go through loads of practice examples. This is a perfect... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/the-css-flexbox-handbook/</link>
                <guid isPermaLink="false">66d45de94a7504b7409c3359</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ flexbox ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Front-end Development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ handbook ]]>
                    </category>
                
                    <category>
                        <![CDATA[ responsive design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Benjamin Semah ]]>
                </dc:creator>
                <pubDate>Wed, 18 Oct 2023 17:25:54 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/10/The-CSS-Flexbox-Handbook-Cover.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Flexbox is a useful tool for creating beautiful and responsive layouts for web pages. In this guide, you will learn everything you need to know to start using CSS Flexbox like a pro. We'll also go through loads of practice examples.</p>
<p>This is a perfect resource for you if you are a beginner web developer. It'll also be useful if you're an experienced developer who wants to brush up on your responsive web design skills.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><p><a class="post-section-overview" href="#heading-what-is-flexbox">What is Flexbox?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-are-the-benefits-of-using-flexbox">What are the benefits of using Flexbox?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-main-axis-and-the-cross-axis">The main axis and the cross axis</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-flex-containers-and-flex-items">Flex Containers and Flex Items</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-understanding-flex-and-inline-flex">Understanding <code>Flex</code> and <code>Inline-flex</code></a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-display-flex">display: flex</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-display-inline-flex">display: inline-flex</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-flex-container-properties">The Flex Container Properties</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-flex-direction-property">The <code>flex-direction</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-flex-wrap-property">The <code>flex-wrap</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-flex-flow-shorthand-property">The <code>flex-flow</code> Shorthand Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-justify-content-property">The <code>justify-content</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-align-items-property">The <code>align-items</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-align-content-property">The <code>align-content</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-place-content-property">The <code>place-content</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#the-flex-items-properties">The Flex Items Properties</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-order-property">The <code>order</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-align-self-property">The <code>align-self</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-flex-grow-property">The <code>flex-grow</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-flex-shrink-property">The <code>flex-shrink</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-flex-basis-property">The <code>flex-basis</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-flex-shorthand-property">The <code>flex</code> Shorthand Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-flexbox-gaps">Flexbox Gaps</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-center-an-element-with-flexbox">How to Center an Element With Flexbox</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-practice-with-flexbox-games">Practice with Flexbox Games</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-are-there-bugs-in-css-flexbox">Are There Bugs in CSS Fexbox?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></p>
</li>
</ul>
<h2 id="heading-what-is-flexbox">What is Flexbox?</h2>
<p>Flexbox is short for "Flexible Box Layout". It's a CSS layout model that simplifies creating complex layouts. It provides a flexible way to align elements and distribute space within a container element.</p>
<p>The Flexbox layout model is bidirectional. This means you can either arrange your elements in rows, columns, or both. More on that later.</p>
<h3 id="heading-what-are-the-benefits-of-using-flexbox">What are the benefits of using Flexbox?</h3>
<p>Before Flexbox, it was hard to create complex layouts and responsive web pages. You needed a combination of CSS floats and position properties. This required many workarounds and hacks.</p>
<p>But with Flexbox, you can now do the following with less difficulty and fewer lines of code:</p>
<ul>
<li><p>Align and center elements using properties like <code>justify-content</code> and <code>align-items</code>.</p>
</li>
<li><p>Develop responsive layouts without writing lots of media queries.</p>
</li>
<li><p>Reorder elements without changing the HTML structure</p>
</li>
<li><p>Create same-height columns without any extra HTML elements or background images.</p>
</li>
</ul>
<p>Now you know what Flexbox is, along with some of the things you can do with it. Let's see how you can use it.</p>
<h3 id="heading-the-main-axis-and-the-cross-axis">The main axis and the cross-axis</h3>
<p>The first thing you need to understand about Flexbox is the concept of axes. Every flex container (an element with a <code>display</code> property set to <code>flex</code> or <code>inline-flex</code>) has a main axis and a cross axis.</p>
<p>The main axis is either horizontal or vertical depending on the value of the <code>flex-direction</code>. No worries if you are not familiar with <code>flex-direction</code>. You are about to learn it.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/44.-main---cross-axis.png" alt="The main axis and the cross axis when the " width="600" height="400" loading="lazy"></p>
<p><em>The cross axis and main axis when the</em> <code>flex-direction</code> is <code>row</code></p>
<p>In this example, the main axis is horizontal and the cross axis is vertical.</p>
<p>The following is an example where the the main axis is vertical and the cross axis, is horizontal.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/45.-cross---main-axis.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The main axis and cross axis when the</em> <code>flex-direction</code> is <code>column</code></p>
<h2 id="heading-flex-containers-and-flex-items">Flex Containers and Flex Items</h2>
<p>To use all of Flexbox's properties, you need to set the <code>display</code> property for an element to <code>flex</code> or <code>inline-flex</code>.</p>
<p>This turns the element into a flex container, and the children of that element become flex items.</p>
<p>Here's an example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">section</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Flex 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>&gt;</span>Flex 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>&gt;</span>    
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This paragraph is not a flex item<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {  
  <span class="hljs-attribute">display</span>: flex;
}
</code></pre>
<p>The <code>.container</code> element is now a flex container. The three div elements are direct children of the <code>.container</code> element, which makes them flex items.</p>
<p>But the paragraph element inside the third div is not a flex item. This is because it's not a direct child of the <code>.container</code> element.</p>
<h2 id="heading-understanding-flex-and-inline-flex">Understanding <code>flex</code> and <code>inline-flex</code></h2>
<p>You can use both <code>flex</code> and <code>inline-flex</code> to make an element a flex container. The difference is in how they interact with surrounding elements.</p>
<h3 id="heading-display-flex"><code>display: flex</code></h3>
<p>This makes the flex container behave like a block-level element. The flex-container takes up the entire available width of its parent element. It starts on a new line, and the element that comes after it also starts on a new line.</p>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Button One<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>

/* Flex Container */
<span class="hljs-tag">&lt;<span class="hljs-name">section</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"red"</span>&gt;</span><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">id</span>=<span class="hljs-string">"gold"</span>&gt;</span><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">id</span>=<span class="hljs-string">"green"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Button Two<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">display</span>: flex;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/46.-display-flex.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Flex containers behave like block elements when you use</em> <code>display: flex</code></p>
<p>The <code>.container</code> element takes up the entire available width of the body (its parent element).</p>
<h3 id="heading-display-inline-flex"><code>display: inline-flex</code></h3>
<p>This makes the flex-container behave like an inline-level element. This allows other inline elements (like buttons) to flow alongside it. Using the previous example, this is how the elements will be arranged when you change <code>display</code> from <code>flex</code> to <code>inline-flex</code>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/47.-display-inline-flex.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Flex containers behave like</em> <code>inline-elements</code> when you use <code>display: inline-flex</code></p>
<p>The flex container does not take up the entire width of its parent. It uses only as much horizontal space as necessary for its content.</p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-ug2zkz?file=style.css"><strong>Practice using flex and inline-flex</strong></a> <strong>on StackBlitz</strong></p>
<h2 id="heading-the-flex-container-properties">The Flex Container Properties</h2>
<p>The flex container properties allow you to control the layout and alignment of the flex items within a flex container.</p>
<p><strong>NOTE:</strong> You apply these properties on the flex container, and not on its items.</p>
<p>The following are the flex container properties:</p>
<ul>
<li><p><code>flex-direction</code></p>
</li>
<li><p><code>flex-wrap</code></p>
</li>
<li><p><code>flex-flow</code></p>
</li>
<li><p><code>justify-content</code></p>
</li>
<li><p><code>align-items</code></p>
</li>
<li><p><code>align-content</code></p>
</li>
<li><p><code>place-content</code></p>
</li>
</ul>
<h3 id="heading-the-flex-direction-property">The <code>flex-direction</code> Property</h3>
<p>The <code>flex-direction</code> property defines the direction for displaying the flex items. It is what sets the flex container's main axis. This property can take any of these four values:</p>
<ul>
<li><p><code>row</code> (default value)</p>
</li>
<li><p><code>column</code></p>
</li>
<li><p><code>row-reverse</code></p>
</li>
<li><p><code>column-reverse</code></p>
</li>
</ul>
<p>Now, let's look at some examples to see how it all works.</p>
<p>In the following code snippet, we have a <code>names-container</code> with four names:</p>
<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">"names-container"</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"jill"</span>&gt;</span>1. JILL<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"john"</span>&gt;</span>2. JOHN<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"jane"</span>&gt;</span>3. JANE<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"jack"</span>&gt;</span>4. JACK<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>Let's see the different ways you can arrange the names using the <code>flex-direction</code> property.</p>
<h4 id="heading-flex-direction-row"><code>flex-direction: row</code></h4>
<p>This displays the flex-items horizontally from left to right.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-direction</span>: row;  
    <span class="hljs-comment">/* Other styles here... */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/1.-flex-direction-row.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>flex-direction: row</code></p>
<h4 id="heading-flex-direction-column"><code>flex-direction: column</code></h4>
<p>This displays the flex-items vertically from top to bottom.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/2.-flex-direction-column.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>flex-direction: column</code></p>
<h4 id="heading-flex-direction-row-reverse"><code>flex-direction: row-reverse</code></h4>
<p>This is the opposite of the row value. It displays the flex items from right to left.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/3.-flex-direction-row-reverse.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>flex-direction: row-reverse</code></p>
<h4 id="heading-flex-direction-column-reverse"><code>flex-direction: column-reverse</code></h4>
<p>This is the opposite of the column value. It displays the flex items from the bottom to the top.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/4.-flex-direction-column-reverse.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>flex-direction: column-reverse</code></p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-aaerav?file=style.css"><strong>Practice using flex-direction</strong></a> <strong>on StackBlitz</strong></p>
<h4 id="heading-a-note-on-the-reverse-values-and-accessibility">A note on the reverse values and accessibility:</h4>
<p>There's something you need to keep in mind when you use <code>row-reverse</code> and <code>column-reverse</code>. As you've already seen, both affect the visual order of elements on the screen.</p>
<p>But the order in your HTML remains unchanged. And that is the order that screen readers and keyboard navigation controls use.</p>
<p>In the example, when you use <code>row-reverse</code>, you see Jack's name first on the screen, followed by Jane, John, and Jill.</p>
<p>But for someone using a screen reader, they will hear the names as they appear in the HTML and not as they appear on screen. In this case, they will first hear Jill's name, followed by John, Jane, and Jack.</p>
<h3 id="heading-the-flex-wrap-property">The <code>flex-wrap</code> Property</h3>
<p>Sometimes, the space within the flex container will not be enough for the flex items.</p>
<p>In such cases, you use the <code>flex-wrap</code> property to choose whether to let the flex-items overflow or begin on a new line.</p>
<p>The <code>flex-wrap</code> property accepts any of the following values:</p>
<ul>
<li><p><code>nowrap</code> (default value)</p>
</li>
<li><p><code>wrap</code></p>
</li>
<li><p><code>wrap-reverse</code></p>
</li>
</ul>
<p>To see <code>flex-wrap</code> in action, let's add four more names to our <code>names-container</code>:</p>
<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">"names-container"</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"jill"</span>&gt;</span>1. JILL<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"john"</span>&gt;</span>2. JOHN<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"jane"</span>&gt;</span>3. JANE<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"jack"</span>&gt;</span>4. JACK<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"sara"</span>&gt;</span>5. SARA<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"seth"</span>&gt;</span>6. SETH<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"seal"</span>&gt;</span>7. SEAL<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<h4 id="heading-flex-wrap-nowrap"><code>flex-wrap: nowrap</code></h4>
<p>This keeps all the flex items on a single line either in a row or column. It allows the flex items to overflow if there's not enough room in the flex container. See the example below:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-direction</span>: row;  
    <span class="hljs-attribute">flex-wrap</span>: nowrap;  
    <span class="hljs-comment">/* Other styles here... */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/5.-flex-wrap-nowrap.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Flex items overflows because</em> <code>flex-wrap</code> is set to <code>nowrap</code></p>
<p>In this example, three names overflow out of the container because there is not enough space for them.</p>
<h4 id="heading-flex-wrap-wrap"><code>flex-wrap: wrap</code></h4>
<p>This will wrap or push the flex items to the next line if there's not enough room for them.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/6.-flex-wrap-wrap.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Flex items wrap or moves to the next line when</em> <code>flex-wrap</code> is set to <code>wrap</code></p>
<h4 id="heading-flex-wrap-wrap-reverse"><code>flex-wrap: wrap-reverse</code></h4>
<p>This is the opposite of <code>wrap</code>. It moves the overflow items to the next line but in a reverse direction.</p>
<p>For example, using <code>wrap-reverse</code> on the names container moves overflow items to the next top line instead of the next line below.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/7.-flex-wrap-wrap-reverse.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>flex-wrap: wrap-reverse</code></p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-cbmfgr?file=style.css"><strong>Practice using flex-wrap</strong></a> <strong>on StackBlitz.</strong></p>
<h3 id="heading-the-flex-flow-shorthand-property">The <code>flex-flow</code> Shorthand Property</h3>
<p>The <code>flex-flow</code> property is a shorthand for the <code>flex-direction</code> and <code>flex-wrap</code> properties. This means that when you use <code>flex-flow</code>, you can apply both properties with only a single line of code.</p>
<p>See the example below using the names container. You can give the container <code>flex-direction</code> and <code>flex-wrap</code> properties.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-direction</span>: column;  
    <span class="hljs-attribute">flex-wrap</span>: wrap;
}
</code></pre>
<p>Or you can use the <code>flex-flow</code> shorthand to get the same result.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-flow</span>: column wrap;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/8.-flex-flow.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>flex-flow: column wrap</code></p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-xuv4bx?file=style.css"><strong>Practice using flex-flow</strong></a> <strong>on StackBlitz.</strong></p>
<h3 id="heading-the-justify-content-property">The <code>justify-content</code> Property</h3>
<p>This <code>justify-content</code> property handles the alignment of flex items on the main axis of the flex container.</p>
<p>You can use it to take care of how space is distributed on the main axis. This property takes any of the following values:</p>
<ul>
<li><p><code>flex-start</code> (default value)</p>
</li>
<li><p><code>flex-end</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>space-between</code></p>
</li>
<li><p><code>space-around</code></p>
</li>
<li><p><code>space-evenly</code></p>
</li>
</ul>
<h4 id="heading-justify-content-flex-start"><code>justify-content: flex-start</code></h4>
<p>This places the items at the start of the flex-direction. If the main axis is horizontal with a <code>flex-direction</code> of <code>row</code> (like the example below), it aligns the items to the left. And if it's vertical (with a <code>flex-direction</code> of <code>column</code>), it aligns the items to the top.</p>
<p>Using the names container example, this is how <code>justify-content: flex-start</code> would look like:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">justify-content</span>: flex-start;  
    <span class="hljs-comment">/* Other styles here... */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/9.-justify-content-flex-start.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>justify-content: flex-start</code></p>
<h4 id="heading-justify-content-flex-end"><code>justify-content: flex-end</code></h4>
<p>This will place the flex items at the end of the flex-direction of the main axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/10.-justify-content-flex-end.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>justify-content: flex-end</code></p>
<h4 id="heading-justify-content-center"><code>justify-content: center</code></h4>
<p>This places the flex items at the center of the flex container's main axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/11.-justify-content-center-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>justify-content: center</code></p>
<h4 id="heading-justify-content-space-between"><code>justify-content: space-between</code></h4>
<p>This will place the first flex item at the start of the main axis. And also place the last item at the end of the main axis. Then space on the main axis is distributed equally among the the elements.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/12.-justify-content-space-between.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>justify-content: space-between</code></p>
<h4 id="heading-justify-content-space-evenly"><code>justify-content: space-evenly</code></h4>
<p>This distributes space equally among the flex items. This means the space before and after each item is the same.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/13.-justify-content-space-evenly.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>justify-content: space-evenly</code></p>
<h4 id="heading-justify-content-space-around"><code>justify-content: space-around</code></h4>
<p>This also distributes space equally between the flex items. The key difference here is that the space before the first item and after the last item is half the space between the flex items.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/14.-justify-content-space-around.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>justify-content: space-around</code></p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-zpcbxv?file=style.css"><strong>Practice using justify-content</strong></a> <strong>on StackBlitz.</strong></p>
<h3 id="heading-the-align-items-property">The <code>align-items</code> Property</h3>
<p>The <code>align-items</code> property handles the alignment of flex items on the cross-axis of the flex container. It can take any of the following values:</p>
<ul>
<li><p><code>stretch</code> (default value)</p>
</li>
<li><p><code>flex-start</code></p>
</li>
<li><p><code>flex-end</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>baseline</code></p>
</li>
</ul>
<h4 id="heading-align-items-stretch"><code>align-items: stretch</code></h4>
<p>This stretches the flex items to fill up the space within the flex-container.</p>
<p>See the example below using a new names container with name cards of different sizes:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">align-items</span>: stretch;  
    <span class="hljs-comment">/* Other styles here... */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/15.-align-items-stretch.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-items: stretch</code></p>
<h4 id="heading-align-items-flex-start"><code>align-items: flex-start</code></h4>
<p>This will place the flex items at the start of the cross-axis of the flex container. If the cross-axis is vertical like in the example below, <code>align-items: flex-start</code> will place the items at the top.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">align-items</span>: flex-start;  
    <span class="hljs-comment">/* Other styles here... */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/16.-align-items-flex-start.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-items: flex-start</code></p>
<h4 id="heading-align-items-flex-end"><code>align-items: flex-end</code></h4>
<p>This will place the flex items at the end of the cross-axis of the flex container. If the cross-axis is vertical like in the example below, <code>align-items: flex-end</code> will place the items at the bottom.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">align-items</span>: flex-end;  
    <span class="hljs-comment">/* Other styles here... */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/17.-align-items-flex-end.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-items: flex-end</code></p>
<h4 id="heading-align-items-center"><code>align-items: center</code></h4>
<p>This aligns flex items at the center of the cross-axis of the flex container.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">align-items</span>: center;  
    <span class="hljs-comment">/* Other styles here... */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/18.-align-items-center.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-items: center</code></p>
<h4 id="heading-align-items-baseline"><code>align-items: baseline</code></h4>
<p>When you use the <code>baseline</code> value, flex items are arranged such that their baselines are aligned. See the example below:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">align-items</span>: baseline;  
    <span class="hljs-comment">/* Other styles here... */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/Untitled-design-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The baseline is indicated with the dotted white line</em></p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-jydywf?file=style.css"><strong>Practice using align-items</strong></a> <strong>on StackBlitz.</strong></p>
<h3 id="heading-the-align-content-property">The <code>align-content</code> Property</h3>
<p>When you have a flex container with wrap (or more than one flex line), you may need to align the lines to distribute the space as you want. That is when you use <code>align-content</code>. This property can take any of the following values:</p>
<ul>
<li><p><code>stretch</code> (default value)</p>
</li>
<li><p><code>flex-start</code></p>
</li>
<li><p><code>flex-end</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>space-between</code></p>
</li>
<li><p><code>space-evenly</code></p>
</li>
<li><p><code>space-around</code></p>
</li>
</ul>
<p>In the example below, there are 11 names in the names container. And the names container element has a <code>flex-wrap</code> value of <code>wrap</code>. This means you can apply the <code>align-content</code> property to change the alignment of the flex lines.</p>
<h4 id="heading-align-content-stretch"><code>align-content: stretch</code></h4>
<p>This stretches the flex lines to fill up the space within the flex container's cross-axis.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-wrap</span>: wrap;  
    <span class="hljs-attribute">align-items</span>: stretch;  
    <span class="hljs-comment">/* Other styles here... */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/20.-align-content-stretch.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-content: stretch</code></p>
<h4 id="heading-align-content-flex-start"><code>align-content: flex-start</code></h4>
<p>This places the flex lines at the start of the container's cross-axis. For example, if the cross axis is vertical like that of the names container, it will place the flex lines at the top.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/21.-align-content-flex-start.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-content: flex-start</code></p>
<h4 id="heading-align-content-flex-end"><code>align-content: flex-end</code></h4>
<p>This places the flex lines at the end of the container's cross-axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/22.-align-content-flex-end.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-content: flex-end</code></p>
<h4 id="heading-align-content-center"><code>align-content: center</code></h4>
<p>This places the flex lines at the center of the container's cross-axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/23.-align-content-center.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-content: center</code></p>
<h4 id="heading-align-content-space-between"><code>align-content: space-between</code></h4>
<p>This will place the first flex line at the start of the cross-axis. It also places the last flex line at the end of the cross axis. Then space on the cross-axis is distributed equally between the the lines.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/24.-align-content-space-between.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-content: space-between</code></p>
<h4 id="heading-align-content-space-evenly"><code>align-content: space-evenly</code></h4>
<p>This distributes space equally between the flex lines. This means the space before and after each line is the same.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/25.-align-content-space-evenly.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-content: space-evenly</code></p>
<h4 id="heading-align-content-space-around"><code>align-content: space-around</code></h4>
<p>This also distributes space equally between the flex lines. The key difference here is the space before the first line and after the last line is half the space between the flex lines.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/26.-align-content-space-around.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-content: space-around</code></p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-fukvgd?file=style.css"><strong>Practice using align-content</strong></a> <strong>on StackBlitz.</strong></p>
<h3 id="heading-the-place-content-property">The <code>place-content</code> Property</h3>
<p>If you need to use both the <code>justify-content</code> and <code>align-content</code> properties, you use the <code>place-content</code> shorthand property.</p>
<p>It can take one or two values. When you give it a single value, the browser will apply the same value for both <code>justify-content</code> and <code>align-content</code>.</p>
<p>And when you give 2 values for <code>place-content</code>, the first value will be for <code>align-content</code> and the second for <code>justify-content</code>.</p>
<p>Let's look at an example:</p>
<p>Instead of writing this:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-wrap</span>: wrap;  
    <span class="hljs-attribute">align-content</span>: flex-end;  
    <span class="hljs-attribute">justify-content</span>: flex-start;  
    <span class="hljs-comment">/* Other content */</span>
}
</code></pre>
<p>You can instead write the following and it will have the same effect:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-wrap</span>: wrap;  
    <span class="hljs-attribute">place-content</span>: flex-end flex-start;  
    <span class="hljs-comment">/* Other content */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/43.-place-content.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of using the</em> <code>place-content</code> shorthand</p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-ytdywl?file=style.css"><strong>Practice using place-content</strong></a> <strong>on StackBlitz.</strong></p>
<h2 id="heading-the-flex-item-properties">The Flex Item Properties</h2>
<p>Every direct child of a flex container is a flex item. So far, you've learned the properties of the flex containers.</p>
<p>Flexbox also has properties that you can apply to individual flex items. They include the following:</p>
<ul>
<li><p><code>order</code></p>
</li>
<li><p><code>align-self</code></p>
</li>
<li><p><code>flex-grow</code></p>
</li>
<li><p><code>flex-shrink</code></p>
</li>
<li><p><code>flex-basis</code></p>
</li>
<li><p><code>flex</code></p>
</li>
</ul>
<h3 id="heading-the-order-property">The <code>order</code> property</h3>
<p>The <code>order</code> property determines the order of appearance for the flex items.</p>
<p>The value you give to this property must be a number. A flex item with a lower number will appear before one with a higher number.</p>
<p>In the HTML code, the order for the four names is as follows:</p>
<ol>
<li><p>Jill</p>
</li>
<li><p>John</p>
</li>
<li><p>Jane</p>
</li>
<li><p>Jack</p>
</li>
</ol>
<pre><code class="lang-css">&lt;<span class="hljs-selector-tag">div</span> <span class="hljs-selector-tag">class</span>="<span class="hljs-selector-tag">names-container</span>"&gt;
    &lt;<span class="hljs-selector-tag">p</span> <span class="hljs-selector-tag">id</span>="<span class="hljs-selector-tag">jill</span>"&gt;1. <span class="hljs-selector-tag">JILL</span>&lt;/<span class="hljs-selector-tag">p</span>&gt;
    &lt;<span class="hljs-selector-tag">p</span> <span class="hljs-selector-tag">id</span>="<span class="hljs-selector-tag">john</span>"&gt;2. <span class="hljs-selector-tag">JOHN</span>&lt;/<span class="hljs-selector-tag">p</span>&gt;
    &lt;<span class="hljs-selector-tag">p</span> <span class="hljs-selector-tag">id</span>="<span class="hljs-selector-tag">jane</span>"&gt;3. <span class="hljs-selector-tag">JANE</span>&lt;/<span class="hljs-selector-tag">p</span>&gt;
    &lt;<span class="hljs-selector-tag">p</span> <span class="hljs-selector-tag">id</span>="<span class="hljs-selector-tag">jack</span>"&gt;4. <span class="hljs-selector-tag">JACK</span>&lt;/<span class="hljs-selector-tag">p</span>&gt;
&lt;/<span class="hljs-selector-tag">div</span>&gt;
</code></pre>
<p>You can change the order of appearance on the screen using the <code>order</code> property. See the example below.</p>
<p>Here's how they appear with no <code>order</code> properties:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/27.-no-order-property.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Name cards before add the</em> <code>order</code> property</p>
<p>Now, see how they appear when you add the following order properties:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;
}

<span class="hljs-selector-id">#jill</span> {  
    <span class="hljs-attribute">order</span>: <span class="hljs-number">2</span>;  
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#fe4f46</span>;
}

<span class="hljs-selector-id">#john</span> {  
    <span class="hljs-attribute">order</span>: <span class="hljs-number">4</span>;  
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#fcd65c</span>;
}

<span class="hljs-selector-id">#jane</span> {  
    <span class="hljs-attribute">order</span>: <span class="hljs-number">1</span>;  
    <span class="hljs-attribute">background-color</span>: 
    <span class="hljs-number">#00bab4</span>;
}

<span class="hljs-selector-id">#jack</span> {  
    <span class="hljs-attribute">order</span>: <span class="hljs-number">3</span>;  
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#003f54</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/28.-with-order-property.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The</em> <code>order</code> property changes the order of appearance</p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-c5mf8q?file=style.css"><strong>Practice using the order property</strong></a> <strong>on StackBlitz.</strong></p>
<p><strong>Word of caution:</strong> Even though the order of appearance changes on screen, the order in the HTML remains unchanged. And it's the order in the HTML that screen readers use. Where possible, it's best practice to change the order in the HTML rather than doing it with Flexbox.</p>
<h3 id="heading-the-align-self-property">The <code>align-self</code> property</h3>
<p>You can use the <code>align-self</code> property to give a flex item a different alignment from the other items.</p>
<p>It works the same way as the <code>align-items</code> property. The difference is that whereas <code>align-items</code> applies to all flex items, the <code>align-self</code> property is applied to only specific items.</p>
<p>Example:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">align-items</span>: center;  
    <span class="hljs-comment">/* Other styles */</span>    
}

<span class="hljs-selector-id">#jill</span> {
    <span class="hljs-attribute">align-self</span>: flex-start;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/37.-align-self.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-self</code> with a <code>flex-start</code> value</p>
<p>In the example, the <code>align-items</code> property for the names container has a value of <code>center</code>. This aligns all the names at the center.</p>
<p>But using the <code>align-self</code> property, you are able to align Jill's name card to the top with a value of <code>flex-start</code>.</p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-e9ctpu?file=style.css"><strong>Practice using the align-self property</strong></a> <strong>on StackBlitz.</strong></p>
<h3 id="heading-the-flex-grow-property">The <code>flex-grow</code> property</h3>
<p>When you set a container's display to <code>flex</code>, often there will be some extra space after the items are arranged. See the example below:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">justify-content</span>: 
    flex-start;  
     <span class="hljs-comment">/* Other styles */</span>
 }
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/29.-flex-grow-extra-space.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The flex container has more than enough space for the flex items</em></p>
<p>The browser treats the extra as a value of <code>1</code>. This means when you give a <code>flex-grow</code> value of <code>0.5</code> to only one of the flex items, the browser will add half of the remaining space to the item's size.</p>
<pre><code class="lang-css"><span class="hljs-selector-id">#jill</span> {
    <span class="hljs-attribute">flex-grow</span>: <span class="hljs-number">0.5</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/30.-flex-grow-0.5.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The</em> <code>flex-grow</code> property makes the Jill's larger than its initial size</p>
<p>And if you add a <code>flex-grow</code> value of <code>1</code> to <strong>only one of the flex items</strong>, the browser will add all the extra space to that item.</p>
<p><strong>NOTE:</strong> If only one item in the container has a <code>flex-grow</code> value, then any value of 1 or more will make it take up all the extra space.</p>
<p>For example, the two code snippets below will have the same effect on Jill's card:</p>
<pre><code class="lang-css"><span class="hljs-selector-id">#jill</span> {  
    <span class="hljs-attribute">flex-grow</span>: <span class="hljs-number">1</span>;
}
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-id">#jill</span> {  
    <span class="hljs-attribute">flex-grow</span>: <span class="hljs-number">99</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/31.-flex-grow-1-or-more.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>When only one card has a</em> <code>flex-grow</code> of <code>1</code> or more</p>
<p>What happens when you add <code>flex-grow</code> values to more than one element?</p>
<p>The browser will share the extra space proportionately for them.</p>
<p>For example, when you give Jane a <code>flex-grow</code> of <code>3</code> and Jack a <code>flex-grow</code> of <code>1</code>, the browser will share the extra space with a <code>3:1</code> ratio.</p>
<p>This means the total value of the extra space becomes <code>4</code> (3+1). <code>Jane</code> will then get <code>3/4</code> of the extra space. And <code>Jack</code> will get <code>1/4</code> of it.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/32.-flex-grow-jane-jack.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The extra space is shared proportionately betwee</em> <code>Jane</code> and <code>Jack</code></p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-m6h8af?file=style.css"><strong>Practice using the flex-grow property</strong></a> <strong>on StackBlitz.</strong></p>
<h3 id="heading-the-flex-shrink-property">The <code>flex-shrink</code> property</h3>
<p>The <code>flex-shrink</code> property is the opposite of <code>flex-grow</code>.</p>
<p>You use <code>flex-grow</code> when you want to increase the flex item's size if there's extra space. But, you use <code>flex-shrink</code> when you want to decrease the flex-item's size if there's not enough space in the flex container.</p>
<p>See the example below:</p>
<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">"numbers-container"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"one"</span>&gt;</span>1<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"two"</span>&gt;</span>2<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"three"</span>&gt;</span>3<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"four"</span>&gt;</span>4<span class="hljs-tag">&lt;/<span class="hljs-name">p</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">.numbers-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">justify-content</span>: flex-start;  
    <span class="hljs-comment">/* Other styles */</span>
}

<span class="hljs-selector-id">#one</span> {  
    <span class="hljs-attribute">flex-shrink</span>: <span class="hljs-number">2</span>;  
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#fe4f46</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/33.-flex-shrink-value-2.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The first card shrinks to make room for the others</em></p>
<p>In the example, each of the four numbers has a width of 150px (that's a total of 600px). But the <code>numbers-container</code> has a width of 400px which is not enough.</p>
<p>The cards have to shrink to fit in the available space. But Number <code>1</code> which with a <code>flex-shrink</code> value of 2 shrinks to become twice as small as the other numbers.</p>
<h4 id="heading-what-if-you-dont-want-a-flex-item-to-shrink">What if you don't want a flex item to shrink?</h4>
<p>To prevent a flex item from shrinking, give it a <code>flex-shrink</code> value of <code>0</code>.</p>
<p>For example, when you give Number <code>1</code> a <code>flex-shrink</code> of <code>0</code>, it will maintain the width of 150px. And the other flex items will shrink to fit in the remaining space.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/34.-flex-shrink-vallue-0.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The first card does not shrink because it has a</em> <code>flex-shrink</code> value of <code>0</code></p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-q9zndc?file=style.css"><strong>Practice using the flex-shrink property</strong></a> <strong>on StackBlitz.</strong></p>
<h3 id="heading-the-flex-basis-property">The <code>flex-basis</code> property</h3>
<p>You can use the <code>flex-basis</code> property to set the default length of a specific flex item. This is either the width or height of the item depending on the <code>flex-direction</code>.</p>
<p>If the <code>flex-direction</code> is <code>row</code> or <code>row-reverse</code>, the value for <code>flex-basis</code> becomes the initial width of the item.</p>
<p>And if <code>flex-direction</code> is <code>column</code> or <code>column-reverse</code>, then the value for <code>flex-basis</code> becomes the initial height of the item.</p>
<p>Example:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-direction</span>: column;  
    <span class="hljs-comment">/* Other styles */</span>
}

<span class="hljs-selector-tag">div</span> {  
    <span class="hljs-attribute">height</span>: <span class="hljs-number">20px</span>;
}

<span class="hljs-selector-id">#jane</span> {  
    <span class="hljs-attribute">flex-basis</span>: <span class="hljs-number">60px</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/35.-flex-basis-height.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>flex-basis</code> setting the height of an item</p>
<p>In the example, the height for the divs is set at 20px. But Jane gets a <code>flex-basis</code> value of 60px. And that overrides the 20px given to all the divs.</p>
<p><strong>Note:</strong> The flex-basis of 60px becomes the height for Jane because the <code>flex direction</code> is <code>column</code>. This means the main axis is vertical.</p>
<p>Here is another example. This time, the <code>flex-direction</code> is <code>row</code>. This means the <code>flex-basis</code> will set the width of the item.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-direction</span>: row;  
    <span class="hljs-comment">/* Other styles */</span>
}

<span class="hljs-selector-tag">div</span> {  
    <span class="hljs-attribute">width</span>: <span class="hljs-number">70px</span>;
}

<span class="hljs-selector-id">#jane</span> {  
    <span class="hljs-attribute">flex-basis</span>: <span class="hljs-number">140px</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/36.-flex-basis-width.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>flex-basis</code> setting the width of an item</p>
<p>While all the other divs have a width of 70px, Jane has a width of 140px set by the <code>flex-basis</code>.</p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-maihzd?file=style.css"><strong>Practice using the flex-basis property</strong></a> <strong>on StackBlitz.</strong></p>
<h3 id="heading-the-flex-shorthand-property">The <code>flex</code> Shorthand Property</h3>
<p>You can use <code>flex</code> as a shorthand for the <code>flex-grow</code>, <code>flex-shrink</code>, and <code>flex-basis</code> properties.</p>
<p>For example, instead of writing the following:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.flex-item</span> {  
    <span class="hljs-attribute">flex-grow</span>: <span class="hljs-number">2</span>;  
    <span class="hljs-attribute">flex-shrink</span>: <span class="hljs-number">0</span>;  
    <span class="hljs-attribute">flex-basis</span>: <span class="hljs-number">50px</span>;
}
</code></pre>
<p>You can use the shorthand like so and it will have the same effect:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.flex-item</span> {  
    <span class="hljs-attribute">flex</span>: <span class="hljs-number">2</span> <span class="hljs-number">0</span> <span class="hljs-number">50px</span>;
}
</code></pre>
<p>The <code>flex</code> property can take up to three values. The order of the values is important. The browser assigns the first value for <code>flex-grow</code>, the second for <code>flex-shrink</code>, and the third for <code>flex-basis</code>.</p>
<p>The default values for <code>flex</code> are <code>1 0 auto</code>.</p>
<p>This means if you give <code>flex</code> a single value of 2, the browser uses 2 for <code>flex-grow</code>. And then it sets <code>flex-shrink</code> to 0 and <code>flex-basis</code> to auto.</p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-m19hov?file=style.css"><strong>Practice using the</strong> <code>flex</code> property</a> <strong>on StackBlitz.</strong></p>
<h2 id="heading-how-to-center-an-element-with-flexbox">How to Center an Element With Flexbox</h2>
<p>One of the headaches for many front-end developers is centering elements. Flexbox has a perfect solution for that.</p>
<p>There are two steps involved.</p>
<ol>
<li><p>Make the parent element a flex container by setting <code>display</code> to <code>flex</code>.</p>
</li>
<li><p>Give a value of <code>center</code> to both <code>justify-content</code> and <code>align-items</code>.</p>
</li>
</ol>
<p>That's it! Your element will be perfectly centered.</p>
<p>Example:</p>
<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">"name-container"</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>JOHN<span class="hljs-tag">&lt;/<span class="hljs-name">p</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">.name-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">justify-content</span>: center;  
    <span class="hljs-attribute">align-items</span>: center;  
    <span class="hljs-comment">/* Other Styles */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/38.-center-element-w--flexbox.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of centering an element with Flexbox</em></p>
<p>Whether you're trying to center text, images, or even an entire navigation bar, this will work just fine.</p>
<h2 id="heading-flexbox-gaps">Flexbox Gaps</h2>
<p>You can use the <code>gap</code> property to adjust the space between flex items.</p>
<p><strong>NOTE:</strong> You apply the gap property on the flex container and not the flex items.</p>
<p><code>gap</code> can take two values: the first value for gaps between the rows and the second value for gaps between the columns.</p>
<p>Example:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-wrap</span>: wrap;  
    <span class="hljs-attribute">gap</span>: <span class="hljs-number">50px</span> <span class="hljs-number">10px</span>; 
    <span class="hljs-comment">/* row-gap column-gap */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/39.-gap-two-values.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of giving two values for the gap property</em></p>
<p>If the gap you want between the rows and the columns is the same, you can use a single value. The browser will apply the same value to both rows and columns.</p>
<p>Example:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-wrap</span>: wrap;  
    <span class="hljs-attribute">gap</span>: <span class="hljs-number">10px</span>; 
    <span class="hljs-comment">/* Other Styles */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/40.-gap-single-value.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of using only one value for both rows and columns gap</em></p>
<p>You can also use the properties <code>row-gap</code> if you need to apply a specific gap value between only the rows. and <code>column-gap</code> if you need to add gaps between only the columns.</p>
<p>Example: Adding gaps between only the rows:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-wrap</span>: wrap;  
    <span class="hljs-attribute">row-gap</span>: <span class="hljs-number">20px</span>; 
    <span class="hljs-comment">/* Other Styles */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/41.-row-gap.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of using</em> <code>row-gap</code></p>
<p>Example: Adding gaps between only the columns:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-wrap</span>: wrap;  
    <span class="hljs-attribute">column-gap</span>: <span class="hljs-number">20px</span>; 
    <span class="hljs-comment">/* Other Styles */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/42.-column-gap.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of using</em> <code>column-gap</code></p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-v77toh?file=style.css"><strong>Practice using the gap property</strong></a> <strong>on StackBlitz.</strong></p>
<h2 id="heading-practice-with-flexbox-games">Practice with Flexbox Games</h2>
<p>Want to practice Flexbox in an interactive way? Check out the following games. They provide a hands-on experience for practicing Flexbox in a fun and engaging way.</p>
<ul>
<li><p><a target="_blank" href="https://flexboxfroggy.com/">Flexbox Froggy</a></p>
</li>
<li><p><a target="_blank" href="http://www.flexboxdefense.com/">Flexbox Defense</a></p>
</li>
<li><p><a target="_blank" href="https://mastery.games/flexboxzombies/">Flexbox Zombies</a></p>
</li>
</ul>
<h2 id="heading-are-there-bugs-in-css-flexbox">Are There Bugs in CSS Flexbox?</h2>
<p>While CSS Flexbox is a powerful layout tool, it's got a few bugs that may surprise you.</p>
<p>A common example is that <strong>some HTML elements cannot act as flex containers</strong>. These include the <code>&lt;button&gt;</code>, <code>&lt;fieldset&gt;</code>, and <code>&lt;summary&gt;</code> elements.</p>
<p>The workaround is to use an element like a <code>div</code> to wrap around the element's children. Then use Flexbox on the wrapper <code>div</code>.</p>
<p>If you are curious about other Flexbox bugs and workarounds, you can have a look at <a target="_blank" href="https://github.com/philipwalton/flexbugs">the Flexbugs repository</a> on GitHub.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this guide, you learned all the Flexbox properties, their values, and how to use them to create responsive layouts. You also learned about some games like Flexbox Froggy you can use for practice.</p>
<p>Thank you for reading, and happy coding! For more in-depth tutorials, feel free to <a target="_blank" href="https://www.youtube.com/@DevAfterHours">subscribe to my YouTube channel</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is a PWA? Progressive Web Apps for Beginners ]]>
                </title>
                <description>
                    <![CDATA[ These days, everything is made possible with the help of mobile phones and applications. Let's say you need to order food – you can do so instantly via the company's app. Maybe you need government services – the same thing applies. You can even get m... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-are-progressive-web-apps/</link>
                <guid isPermaLink="false">66b8dc0a34a5a4a0df79b3ee</guid>
                
                    <category>
                        <![CDATA[ progressive web app ]]>
                    </category>
                
                    <category>
                        <![CDATA[ PWA ]]>
                    </category>
                
                    <category>
                        <![CDATA[ responsive design ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Hillary Nyakundi ]]>
                </dc:creator>
                <pubDate>Tue, 27 Jun 2023 12:00:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/06/CoverImagePWA.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>These days, everything is made possible with the help of mobile phones and applications.</p>
<p>Let's say you need to order food – you can do so instantly via the company's app. Maybe you need government services – the same thing applies. You can even get medical emergency dial services via an app.</p>
<p>There's an app for everything – from banking to studying and from trading to shopping. Every business has an app, and even our governments have simplified their services into app form.</p>
<p>Hold on, building and maintaining an app is cumbersome, and it's quite expensive for small businesses, so how do they manage?</p>
<p>Well it's simple: with the help of advancements in technology there is an option that helps small businesses out. This option combines the features of an app with the technology used in web development to build affordable services for businesses – I'm talking about <strong>Progressive Web Apps</strong>.</p>
<p>Let's dive in and get a better understanding of what PWAs are all about.</p>
<h2 id="heading-what-is-a-progressive-web-app">What is a Progressive Web App?</h2>
<p>Progressive Web Applications (PWAs) are apps built with web technologies that we probably all know and love, like HTML, CSS, and JavaScript. But they have the feel and functionality of an actual native app. Wait a minute! Native Apps, what do we mean by this?</p>
<p>A <strong>Native App</strong> is a software application built in a specific programming language for a specific device platform, either IOS or Android.<br>PWAs are built with the capabilities like push notifications and the ability to work offline. They are also built on and enhanced with modern APIs which makes it easy to deliver improved capabilities along with reliability and the ability to install them on any device.</p>
<p>PWAs takes advantage of the huge web ecosystem this is inclusive of the plugins, and community and the relative ease of deploying and keeping a website contrary to a native application which is pretty difficult to develop. This means you can build a PWA quickly and easily.</p>
<p>With its popularity many companies have shifted into the product, I tend to believe that this is because of its ability to run on an android and iOS without much difference. Some good examples of top companies who have their products as PWAs include: <em>Twitter, Pintrest, Uber, Tiktok, Spotify, Jumia (a leading e-commerce site in Africa)</em> etc...</p>
<p>A common feature about this products is that they are all installable on your home screen, able to work offline from where you last left and offer a comparable experience and features to their native apps.</p>
<p>Just like when building a native mobile app there are some expectations that should be met to make a good product for consumer use, the same thing applies to PWAs. Let's discuss what makes a good PWA.</p>
<h2 id="heading-characteristics-of-pwas">Characteristics of PWAs</h2>
<p>Below is what should be considered when developing a PWA:</p>
<h3 id="heading-responsiveness">Responsiveness</h3>
<p>Different companies produce gadgets with different screen sizes, and as a developer it's your responsibility to ensure all the different users enjoy the product regardless the device they are using. So it's a good idea to make sure your app can be used on any screen size and it's content is available at any view-port size.</p>
<h3 id="heading-installable">Installable</h3>
<p>Research has shown that users tend to engage more with installed apps compared to visiting the official sites. Having a PWA as your product gives the users the look, feel and engagement of a normal app.</p>
<h3 id="heading-independent-connectivity">Independent Connectivity</h3>
<p>By keeping a user engaged to your app even while they are offline, provides a more consistent experience than dropping them back to a default offline page.</p>
<p>A good example to illustrate this will be that of a music app, your users should be able to access offline playback and listen to saved music even without internet connection. Another good example is twitter app, a user is able to go back a read through tweets which they might have missed.</p>
<h3 id="heading-discoverability">Discoverability</h3>
<p>Since most PWAs are converted websites, it is fair to make them discoverable on the search engines, this will help generate extra traffic to your app. This also acts as an advantage over native apps which can't be discovered over the search engines.</p>
<h3 id="heading-appearance">Appearance</h3>
<p>The appearance of the app should feel and look like that of a normal app, so be sure to include things like an app icon, this will help make it easily recognizable also things like splash screen will add the touch and feel of an app.</p>
<h3 id="heading-cross-platform">Cross Platform</h3>
<p>PWAs are developed as web app first, which means that they need to work on all browsers/systems and not just a selected few. Users should be able to use them in any browser before they decide to install them.</p>
<p>So folks! there you have it, the general info about PWAs. Along the way you might have noticed occasionally a comparison between PWAs and Native App and this might have confused you a bit, Well let's clear the airwaves by checking the comparison between the two to get a clear understanding.</p>
<h2 id="heading-differences-between-pwas-and-native-apps">Differences Between PWAs and Native Apps</h2>
<h3 id="heading-development-cost">Development Cost</h3>
<p>PWAs are cheaper to develop compared to Native AppsWhen you're developing a native app, you'll have to learn a certain programming language and then build a version of the app for each type of device, Android and iOS. On the other hand you can choose to hire a experienced professional to do the work for you which will even turn out to be more costly.</p>
<p>Down the road, you will also need resources to maintain and update the app, which means lots of money and time is required.</p>
<p>In the case of a PWA, you can have a single codebase for the different platforms. It's also time-saving since you will not need to develop it from scratch you can configure your current web site to fit.</p>
<p>And if you choose to hire developer it will only be one compared to native where you can hire up-to two depending on where you need your app.</p>
<h3 id="heading-discoverability-1">Discoverability</h3>
<p>Native apps cannot be indexed by the search engines, they can just be found through the App/Play store's website. You can make your app more discoverable on the App/Play store by using App Store Optimization(ASO), but that's another story.</p>
<p>Unlike native apps, PWAs work like websites so they can be indexed by search engines. This helps them rank better in search results.</p>
<h3 id="heading-safety">Safety</h3>
<p>Nowadays in order to run a website, it should be encrypted with a SSL certificate, this adds an extra layer of security. Now, as we already know PWAs are site converted into app which means they are more secure because they run on HTTPS. These are security protocols that allow safe exchange of data between client and server so that is doesn't get tampered with.</p>
<p>To secure your native apps, you need to implement various security measures, like multi-factor authentication and so on.</p>
<h3 id="heading-installation-and-download">Installation and Download</h3>
<p>Native apps need to be downloaded and installed from an app store. This requires some commitment from the user to do it from start to finish. Users have to pass and check multiple permissions before installing an app.</p>
<p>On the other hand, PWAs don't require any of those steps. From the browser you can bookmark it and add the app to your home screen with just a few taps.</p>
<h2 id="heading-benefits-of-pwas">Benefits of PWAs</h2>
<p>A lot of organizations both private and public are switching to PWAs not only because they are cheap to develop but also because they offer greater engagement.<br>Now let's look at a quick summary of the benefits of a PWA:</p>
<ul>
<li>They are responsive and work with many different screen sizes.</li>
<li>They can run on multiple platforms and any device with a modern web browser.</li>
<li>They function just like normal Native Apps.</li>
<li>The updates are independent, you don't need to visit the play store for an update.</li>
<li>They're built with common web technologies.</li>
<li>They're fast and lightweight.</li>
<li>They work offline unlike other sites.</li>
<li>They are discoverable via search engine.</li>
<li>They are easily installable.</li>
<li>Low maintenance cost.</li>
</ul>
<h2 id="heading-requirements-to-get-started-with-pwa-development">Requirements to Get Started with PWA Development</h2>
<p>It does not take much to get started building a PWA. You just need a few things and you are good to go.</p>
<p><strong>Tools</strong><br>The best known technology stack to develop PWAs is AngularJS. Speaking of Angular, <a target="_blank" href="https://allfront.io/blog/how-to-take-your-angular-apps-offline/">here</a> is a resourceful guide on how you can convert your already existing Angular app into PWA. Others stacks include ReactJS and Polymer.</p>
<p><strong>HTTPS</strong><br>You will need a server with a HTTPS connection. This makes sure your user's data is secure. It adds an extra layer of security to you site.</p>
<p><strong>Application Shell</strong><br>It provides a good first impression when your app loads. In simpler words this is what the user sees when they interact with your app for the first time.</p>
<p><strong>Service workers</strong><br>This is one of the key technologies behind PWAs. They help support your app work offline, and they perform advanced caching and run background tasks. Service workers can complete tasks even when your PWA is not running.Some other functions associated with Service Worker include:</p>
<ul>
<li>Sending push notification</li>
<li>Badging icons</li>
<li>Running background fetch tasks etc...</li>
</ul>
<p><strong>Manifest file</strong><br>This is a JSON file that is created with a <a target="_blank" href="https://app-manifest.firebaseapp.com/">Web App Manifest Generator</a>. This file contains the information that tells how your PWA should appear and function. It allows you to determine the name, description, icon, colors and other features of your PWA. Here's an example of a manifest file:</p>
<pre><code class="lang-json">{
<span class="hljs-attr">"short_name"</span>: <span class="hljs-string">"DevBlogger"</span>,  
<span class="hljs-attr">"name"</span>: <span class="hljs-string">"DevBlogger"</span>,  
<span class="hljs-attr">"description"</span>: <span class="hljs-string">"All dev stories under one roof"</span>,
<span class="hljs-attr">"theme_color"</span>: <span class="hljs-string">"#eb5252"</span>,  
<span class="hljs-attr">"background_color"</span>: <span class="hljs-string">"#000000"</span>,  
<span class="hljs-attr">"display"</span>: <span class="hljs-string">"fullscreen"</span>,  
<span class="hljs-attr">"Scope"</span>: <span class="hljs-string">"/"</span>,  <span class="hljs-attr">"orientation"</span>: <span class="hljs-string">"portrait"</span>,  
<span class="hljs-attr">"icons"</span>: [    
    {
        <span class="hljs-attr">"src"</span>: <span class="hljs-string">"images/android/android-launchericon-48-48.png"</span>,      
        <span class="hljs-attr">"type"</span>: <span class="hljs-string">"image/png"</span>,      
        <span class="hljs-attr">"sizes"</span>: <span class="hljs-string">"48x48"</span>
    },
    {      
        <span class="hljs-attr">"src"</span>: <span class="hljs-string">"images/android/android-launchericon-96-96.png"</span>,
        <span class="hljs-attr">"type"</span>: <span class="hljs-string">"image/png"</span>,      
        <span class="hljs-attr">"sizes"</span>: <span class="hljs-string">"96x96"</span>    
    },    
    {      
        <span class="hljs-attr">"src"</span>: <span class="hljs-string">"images/android/android-launchericon-192-192.png"</span>,
        <span class="hljs-attr">"type"</span>: <span class="hljs-string">"image/png"</span>,      
        <span class="hljs-attr">"sizes"</span>: <span class="hljs-string">"192x192"</span>    
    }  
   ],  
       <span class="hljs-attr">"start_url"</span>: <span class="hljs-string">"index.html?utm_source=homescreen"</span>
  }
</code></pre>
<ul>
<li><strong>Audit your App</strong><br>This is possible using the Google Lighthouse tool. Google Lighthouse is a open-source software that anyone can use on any webpage. Google is a big champion of PWAs and pushes them as the future of the web. You can use Lighthouse to help you see how fast, accessible, and SEO readiness your PWA is.</li>
</ul>
<h2 id="heading-how-to-build-a-pwa">How to Build a PWA</h2>
<p>By following the steps below, you can easily create a fully functional PWA that offers an mazing user experience across all devices.</p>
<h3 id="heading-step-1-plan-your-app">Step 1 - Plan your app</h3>
<p>Before diving into development, you should consider the goals of your PWA, what features you want to include, priorities and user experience. You can create first design concepts and wireframes for the app to visualize the structure and layout.<br>In most scenarios, this is often referred to as a ‘<a target="_blank" href="https://allfront.io/blog/project-discovery-phase-guide/">discovery phase</a>’. You get the opportunity to ideate and gather user and stakeholder feedback as well as considering the functionalities of your to be product.</p>
<h3 id="heading-step-2-designing-the-user-interface">Step 2 - Designing the User Interface</h3>
<p>After getting everything right from planning, you can now proceed to designing the UI of your app. During this stage consider things like responsiveness, compatibility with different platforms etc.. Be sure to capture all details that are crucial to the user including their interaction and engagement during usage.</p>
<h3 id="heading-step-3-developing-the-front-end">Step 3 - Developing the Front-End</h3>
<p>Using the web technologies that is HTML, CSS, JavaScript and frameworks like Angular. React or Vue.js develop a visually appealing interface for the users. And always remember they key principle in development using this stack implement a mobile first approach while ensuring responsiveness for larger screens too.</p>
<h3 id="heading-step-4-implementing-service-workers">Step 4 - Implementing Service Workers</h3>
<p>As mentioned previously, service workers are a key component of PWAs. They are JavaScript files that run in the background, enabling offline functionality, push notifications, and caching. To make sure your PWA works to its fullest potential, you’ll need to register and implement a service worker. The way on how you can do this massively depends on which framework you are using.</p>
<h3 id="heading-step-5-adding-push-notifications">Step 5 - Adding Push Notifications</h3>
<p>Leverage the Push API and service workers to implement push notifications. Obtain the necessary user consent and use a push notification service to send notifications to users.</p>
<h3 id="heading-step-6-optimizing-performance">Step 6 - Optimizing Performance</h3>
<p>Optimization is a very important step in development in general. This is how you provide a seamless experience to your users. by ensuring you reduce loading times. by leveraging techniques such as code splitting and caching we should be able to achieve a fast and efficient operation for our PWA.</p>
<h3 id="heading-step-7-testing-and-debugging">Step 7 - Testing and Debugging</h3>
<p>Test your PWA on different devices, browsers and network condition to be sure that it meets the objective. Also be sure to gather user feedback and make necessary improvements when necessary.</p>
<h2 id="heading-resources-to-get-started-with-pwa-development">Resources to Get Started with PWA Development</h2>
<p>If you want to learn and move with the trend, finding resources to help you might be a bit tedious, to help you get started here are some of the best resources listed for you:<br><strong>Online Tutorials and Guides</strong></p>
<ul>
<li><a target="_blank" href="https://developers.google.com/web/progressive-web-apps">Google Developers - Progressive Web Apps</a></li>
<li><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps">MDN Web Docs - Progressive Web Apps</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/learn/front-end-development-libraries/">freeCodeCamp - Frontend Technologies</a></li>
<li><a target="_blank" href="https://web.dev/learn/pwa/">Learn PWA</a></li>
</ul>
<p><strong>Documentation and Reference Materials</strong></p>
<ul>
<li><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API">Service Workers API Documentation</a></li>
<li><a target="_blank" href="https://learn.microsoft.com/microsoft-edge/progressive-web-apps-chromium/?WT.mc_id=%3Fwt.mc_id%3Dstudentamb_223976">Progressive Web Apps (PWAs)</a></li>
</ul>
<p><strong>PWA Development Tools</strong></p>
<ul>
<li><a target="_blank" href="https://developers.google.com/web/tools/workbox">Workbox - Offline Caching and Service Worker Library</a></li>
<li><a target="_blank" href="https://www.pwabuilder.com/">PWA Builder - PWA Generation Platform</a></li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Keeping in mind that PWAs are new to the industry and haven't yet been fully utilized, they can be a great addition to add to your toolkit.</p>
<p>With the latest technologies and the right tools getting started with PWAs can ultimately increase sales and monetary gain for your product either as an individual or organization. With it's many features including they are fast, able to work offline, and also they perform like normal native apps. This offers your users a great experience and keeps them satisfied.</p>
<p>If you have read this far I really appreciate it.</p>
<p>Enjoy Coding ❤.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build Responsive Websites – Best Practices for Developers ]]>
                </title>
                <description>
                    <![CDATA[ By Fakorede Damilola The way we interact with the web has changed dramatically, and it will keep changing. In the past, most people used desktop computers to access the internet. But today, people are using a wide variety of devices, including laptop... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/responsive-design-best-practices/</link>
                <guid isPermaLink="false">66d45ee2f855545810e93454</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ responsive design ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 30 May 2023 20:04:07 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/05/responsive-g619d39e59_1280.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Fakorede Damilola</p>
<p>The way we interact with the web has changed dramatically, and it will keep changing.</p>
<p>In the past, most people used desktop computers to access the internet. But today, people are using a wide variety of devices, including laptops, tablets, and smartphones. This has resulted in a growing demand for responsive web design.</p>
<p>Responsive web design is a design approach that ensures that a website looks good and functions properly on all devices. This is done by using fluid layouts and media queries to adapt the website to different screen sizes.</p>
<p>There are many benefits to using responsive web design. First‌, it provides a better user experience for everyone. When a website is responsive, users can access it from any device without having to zoom in or scroll horizontally. This makes it easier to read content and navigate the website.</p>
<p>Gone are the days when you build a website that looks good on your laptop and don't consider other users' devices.</p>
<p>So you can say responsive web design is the approach that suggests that design and development should respond to the user's behavior and environment based on screen size, platform, and orientation. </p>
<p>In this tutorial, I will be explaining some of the most vital details that you should remember when building your responsive website </p>
<h2 id="heading-5-principles-to-apply-when-building-responsive-websites">5 Principles to Apply When Building Responsive Websites</h2>
<p>There are a number of principles you should consider when building your next website in order to make it responsive. And here are five of them that I think are particularly important. </p>
<p>I won't be going into a lot of detail on each of these. This is more of an overview to keep in the back of your mind when you're building.</p>
<h3 id="heading-use-media-queries">Use Media Queries</h3>
<p>One of the most fundemental ways to create a responsive website is by using <strong>media queries</strong>. Media queries help you to define different breakpoints for your website.</p>
<p>A breakpoint in a responsive design is the “point” at which a website's content and design will adapt in a certain way to provide the best possible user experience. These breakpoints help you specify different CSS properties to use based on the size of the user's screen.</p>
<p>Common examples of breakpoints include 480px, 768px, 1024px, and 1280px.
But you cannot define breakpoints for all the different screens. So developers work by defining two (mobile-desktop) to three (mobile-tablet-desktop) different breakpoints. Then along with other properties we will talk about below, you can define your various styles for each breakpoint.</p>
<p>Below is a typically example of how you can use a media query when building a website. I'm assuming you want to build a <strong>main layout</strong> and an <strong>aside layout</strong>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/MacBook-Air---1.png" alt="MacBook-Air---1" width="600" height="400" loading="lazy"></p>
<p>The code should look something like this:</p>
<pre><code class="lang-html">     .wrapper{
            width:100%;
            display:flex;
        }
        .main {
            width:80%;
            height:100px;
            background:blue;
            display:flex;
            justify-content: center;
            align-items: center;

        }
        .aside{
            height:100px;
            background:red;
            width:20%;
            display:flex;
            justify-content: center;
            align-items: center;
        }
    <span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"wrapper"</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">main</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"main"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>MAIN<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">main</span>&gt;</span> 
    <span class="hljs-tag">&lt;<span class="hljs-name">aside</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"aside"</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>ASIDE<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span> 
    <span class="hljs-tag">&lt;/<span class="hljs-name">aside</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>


<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
</code></pre>
<p>But you have to consider the fact that some users might try to view the website on a smartphone, which has a much smaller screen than your desktop system.</p>
<p>To make this look good even on devices with smaller screens, you can use media queries to either completely remove the aside bar or you can bring it below the main content area. </p>
<p>It depends on you and what you think your users might want to see or the type of information on the aside. This is just to help you think about the options – remember you are a problem solver and there is rarely one way to solve a problem. So pick what works best for you.</p>
<p>For the smaller screen, in this example we will be putting the aside bar below the main area with media query. </p>
<p>When building a website, there is a question you should ask before you start coding. <strong>Are you building for mobile first or desktop?</strong> This question is quite important as it will determine how you structure your CSS. </p>
<p>I personally like to go mobile first, simply because I know most people will view my website on smartphones, so I want to perfect that first. I realize that this debate has been going on for a while, but it depends on you and your site's needs.</p>
<p>Using media queries, we'd do this to change the layout of the code so that it looks good on both smart phones and desktop:</p>
<pre><code class="lang-html"> <span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">

    <span class="hljs-selector-class">.wrapper</span> &gt; <span class="hljs-selector-tag">div</span> {
        <span class="hljs-attribute">display</span>:flex;
            <span class="hljs-attribute">justify-content</span>: center;
            <span class="hljs-attribute">align-items</span>: center;
    } 


        <span class="hljs-selector-class">.main</span> {
            <span class="hljs-attribute">width</span>:<span class="hljs-number">100%</span>;
            <span class="hljs-attribute">height</span>:<span class="hljs-number">100px</span>;
            <span class="hljs-attribute">background</span>:blue;

        }
        <span class="hljs-selector-class">.aside</span>{
            <span class="hljs-attribute">height</span>:<span class="hljs-number">100px</span>;
            <span class="hljs-attribute">background</span>:red;
            <span class="hljs-attribute">width</span>:<span class="hljs-number">100%</span>;
        }
        <span class="hljs-keyword">@media</span> (<span class="hljs-attribute">min-width:</span><span class="hljs-number">600px</span>) {
                   <span class="hljs-selector-class">.wrapper</span>{
            <span class="hljs-attribute">width</span>:<span class="hljs-number">100%</span>;
            <span class="hljs-attribute">display</span>:flex;
                   }
                   <span class="hljs-selector-class">.main</span> {
            <span class="hljs-attribute">width</span>:<span class="hljs-number">80%</span>;

        }
        <span class="hljs-selector-class">.aside</span>{
            <span class="hljs-attribute">width</span>:<span class="hljs-number">20%</span>;
        }
        }
    </span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"wrapper"</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"main"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>MAIN<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <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">"aside"</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>ASIDE<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span> 
    <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>


<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
</code></pre>
<p>There are a few things to take note of here (but again, this isn't meant to be an in-depth tutorial on media queries so we won't go into too much detail). </p>
<p>When working with media queries, you can define the <strong>min-width</strong> or <strong>max-width</strong>. </p>
<p>The code written inside the container of min-width are those we want to apply for that width and above – in this case, for the <strong>wrapper</strong>, you applied the display flex only when the width of the user screen is <strong>600px or above</strong> 
. 
Other styles like the <strong>main width</strong> and the <strong>aside width</strong> also have their indivdual size adjusted when the screen get to a size of 600px and above. That is, the styles you have defined outside this media query will keep working until it sees a screen of 600px and above.</p>
<p>At 600px, it overrides these styles, which it does in the media query block, and then makes the necessary changes.</p>
<p>You can learn more about media queries and practice your skills by building projects <a target="_blank" href="https://www.freecodecamp.org/news/learn-css-media-queries-by-building-projects/">in this tutorial</a>.</p>
<h3 id="heading-use-flexible-layouts">Use Flexible Layouts</h3>
<p>The layout is one of the most fundemental part of a website. This is the structure of your website, and you can lay things out in different ways, depending on what you need.</p>
<p>Since this is one of the most crucial part of your website, you want to create your layout in a way that it is not clogged up and doesn't look disorderly for the main screen sizes like mobile, tablet, and desktop.</p>
<p>By using CSS properties like Flexbox, Grid, and so on, you can easily achieve this.</p>
<p><strong>CSS Grid</strong>: CSS Grid is a two-dimensional layout system for creating responsive web designs. </p>
<p>It allows you to define rows and columns in a grid, and then place and align content within those grid cells.</p>
<p>Grid is typically used for more complex layouts, such as those with multiple rows and columns. It gives you fine-grained control over how content is placed and spaced within the grid cells, and can even be used for overlapping content.</p>
<p>With the grid layout, you can easily have your website rearranged when used with media queries.</p>
<p><strong>Flexbox</strong>: CSS Flexbox is a one-dimensional layout system for creating flexible and responsive web designs. </p>
<p>It allows you to define a flexible container and then align and distribute items within that container along a single axis (either horizontally or vertically).</p>
<p>Flexbox is best used for simpler layouts where items need to be arranged along a single axis. It allows you to easily control the spacing and alignment of those items, and can be used for both horizontal and vertical layouts.</p>
<p>You can learn more about CSS Flexbox <a target="_blank" href="https://www.freecodecamp.org/news/learn-css-flexbox/">in this crash course</a>. And <a target="_blank" href="https://www.freecodecamp.org/news/complete-guide-to-css-grid/">here's a handbook</a> to get you started with Grid.</p>
<p>Then, if you want to put your Flexbox and Grid skills into practice, check out <a target="_blank" href="https://www.freecodecamp.org/news/css-flexbox-and-grid-tutorial/">this project-based guide</a>.</p>
<h3 id="heading-use-flexible-units">Use Flexible Units</h3>
<p>Another fundamental concept in web development is units. Depending on the kind of unit you use, it can make your website look orderly or disorderly.</p>
<p>There are different units you can use to define, for example, the size of a box or circle. And while there is a wide range of units to choose from (like rem, cm, px, inches, and more), they can be broadly classified into two types:</p>
<ul>
<li><p>Relative units: These are the units that change value based on the screen size. This kind of unit doesn't have a fixed dimension, but can easily expand or contrast based on the size of the device. Examples include percentage, rem (root element's font-size) or em.</p>
</li>
<li><p>Absolute units: These are units whose values remain the same no matter the sreen size. Regardless of the size of the screen, the space occupied will always remain the same</p>
</li>
</ul>
<p>Choosing units that automatically expand or resize based on screen size or the content it carries should be your go-to (except where absolutely necessary, and then you can go for absolute units).</p>
<p>A typical example is using a <strong>percentage value</strong> when you want a div (box) to always span the entire screen. Or you can use a <strong>px value</strong> when you want it to remain the same size regardless of the screen size. </p>
<p>Newer and easier units to use include rem and em. Let's look at an example of what not to do first:</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
        <span class="hljs-selector-class">.main</span> {
            <span class="hljs-attribute">width</span>:<span class="hljs-number">500px</span>;
            <span class="hljs-attribute">height</span>: <span class="hljs-number">500px</span>;
            <span class="hljs-attribute">background-color</span>: red;
        }
    </span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"main"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>MAIN<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>The code above is a box with some text in it. Having a set up like this will look good on your large screen, but when you compare it with what you see on the smartphone, there will be a horizontal overflow. And as a web developer, you don't want this (except where absolutely necessary). </p>
<p>Creating something better might go like this:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
        <span class="hljs-selector-class">.main</span> {
            <span class="hljs-attribute">width</span>:<span class="hljs-number">50%</span>;
           <span class="hljs-attribute">height</span>:<span class="hljs-number">100px</span>;
            <span class="hljs-attribute">background-color</span>: red;
        }
    </span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"main"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>MAIN<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>As you can see from the code above, we defined the div with class main, with a relative width. That is, depending on your screen size, the box here will take 50% of your total screen size. This is really nice because now you don't have to worry about the user's screen size because no matter the size, the box will always be half of the screen.</p>
<h3 id="heading-the-css-position-property">The CSS Position Property</h3>
<p>You can also use the various positioning properties in CSS to help you build responsive websites. Some examples include relative, absolute, static, sticky, and fixed.</p>
<p>The position property in CSS helps you easily move different elements from their normal flow, depending on the property you set.</p>
<p>These elements are then positioned using the top, bottom, left, and right properties. But these properties will not work unless the position property is set first. They also work differently depending on the position value.</p>
<ul>
<li>Static: The static position is the default position of any element on the browser, so the top, left, right and bottom properties won't work for it. This property can be used when you want to return an element back to its initial position after you have moved it with another positioning property. </li>
</ul>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
   <span class="hljs-selector-class">.position</span>{
     <span class="hljs-attribute">background</span>:red;
     <span class="hljs-attribute">padding</span>:<span class="hljs-number">5px</span>;
     <span class="hljs-attribute">position</span>:static;
     <span class="hljs-attribute">top</span>:<span class="hljs-number">10px</span>;
     <span class="hljs-attribute">left</span>:<span class="hljs-number">20px</span>;
   }
   <span class="hljs-selector-class">.wrapper</span>{
<span class="hljs-attribute">background</span>:yellow;
     <span class="hljs-attribute">padding</span>:<span class="hljs-number">5px</span>;
   }
  </span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"main"</span>&gt;</span>
     It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).<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">"wrapper"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"position"</span>&gt;</span>
      This is positioned static
    <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>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>As you can see from above, we added the position static along with other properties and nothing happened. This is not because the code is not working – this is just the behaviour of position static. Adding or removing the position static does nothing to the code, that is where it should be.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/Screenshot--1799-.png" alt="Screenshot--1799-" width="600" height="400" loading="lazy"></p>
<ul>
<li>Relative: The relative position property positions an element relative to where the intial position of that element was. The following code will explain this better:</li>
</ul>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
   <span class="hljs-selector-class">.position</span>{
     <span class="hljs-attribute">background</span>:red;
     <span class="hljs-attribute">padding</span>:<span class="hljs-number">5px</span>;
     <span class="hljs-attribute">position</span>:relative;
     <span class="hljs-attribute">top</span>:<span class="hljs-number">10px</span>;
     <span class="hljs-attribute">left</span>:<span class="hljs-number">20px</span>;
   }
   <span class="hljs-selector-class">.wrapper</span>{
<span class="hljs-attribute">background</span>:yellow;
     <span class="hljs-attribute">padding</span>:<span class="hljs-number">5px</span>;
   }
  </span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"main"</span>&gt;</span>
      It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).<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">"wrapper"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"position"</span>&gt;</span>
      This is positioned relative
    <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>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>As you can see from the code above, a position of relative will simply move the element around its actual position based on the value you set. So it is relative to its actual position:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/Screenshot--1800-.png" alt="Screenshot--1800-" width="600" height="400" loading="lazy"></p>
<ul>
<li>Fixed: We use the fixed position to keep an element at a particular point on the screen, regardless of the content of the page. The fixed position will be relative to the size of the screen, that is when you set a top value, it will be calculated from the top of your screen. Here is an example. I will reduce the dummy content I am using.</li>
</ul>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
   <span class="hljs-selector-class">.position</span>{
     <span class="hljs-attribute">background</span>:red;
     <span class="hljs-attribute">padding</span>:<span class="hljs-number">5px</span>;
     <span class="hljs-attribute">position</span>:fixed;
     <span class="hljs-attribute">top</span>:<span class="hljs-number">10px</span>;
     <span class="hljs-attribute">left</span>:<span class="hljs-number">20px</span>;
   }
   <span class="hljs-selector-class">.wrapper</span>{
<span class="hljs-attribute">background</span>:yellow;
     <span class="hljs-attribute">padding</span>:<span class="hljs-number">5px</span>;
   }
  </span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"main"</span>&gt;</span>
     This is a really long text
    <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">"wrapper"</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"position"</span>&gt;</span>
      This is positioned fixed
    <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>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p> <img src="https://www.freecodecamp.org/news/content/images/2023/05/Screenshot--1802-.png" alt="Screenshot--1802-" width="600" height="400" loading="lazy"></p>
<p>This element with the position fixed completely left its original position. Then, based on the the value of the top and left, it was aligned some distance from the top of the screen. It the content is scrollable, the element will still remain there.</p>
<ul>
<li>Absolute: The absolute property positions an element relative to a parent element. So if it is inside another element that has a position property other than static, it will be positioned relative to that element. If there is no such element, it will be positioned relative to the top of the screen.</li>
</ul>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
   <span class="hljs-selector-class">.position</span>{
     <span class="hljs-attribute">background</span>:red;
     <span class="hljs-attribute">padding</span>:<span class="hljs-number">5px</span>;
     <span class="hljs-attribute">position</span>:absolute;
     <span class="hljs-attribute">top</span>:<span class="hljs-number">7px</span>;
     <span class="hljs-attribute">left</span>:<span class="hljs-number">20px</span>;
   }
   <span class="hljs-selector-class">.wrapper</span>{
<span class="hljs-attribute">background</span>:yellow;
     <span class="hljs-attribute">position</span>:fixed;
     <span class="hljs-attribute">top</span>:<span class="hljs-number">30px</span>;
     <span class="hljs-attribute">padding</span>:<span class="hljs-number">30px</span>;
   }
  </span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"main"</span>&gt;</span>
this is dummy content
<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">"wrapper"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"position"</span>&gt;</span>
      This is positioned
    <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>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/Screenshot--1803-.png" alt="Screenshot--1803-" width="600" height="400" loading="lazy"></p>
<p>As you can see from the code and image above, the position is relative to that of the parent element – in this case, it's the fixed wrapper.</p>
<p>You can learn more about the CSS position property <a target="_blank" href="https://www.freecodecamp.org/news/css-positioning-and-flexbox-explained/">in this tutorial</a>.</p>
<h3 id="heading-make-images-responsive">Make Images Responsive</h3>
<p>Images are quite special, and that is why I am adding a section on them here too. </p>
<p>You can make images responsive by using the various methods listed above – but due to the nature of images, they are easily cropped or distorted if you're not careful.</p>
<p>Here are a couple things you can do when working with images if you want them to be responsive</p>
<p><strong>Use SVG images</strong>: SVG stands for Scalable Vector Graphics. It's a type of image format that uses vector graphics to create scalable images that can be resized without losing quality. </p>
<p>Unlike raster images (for example, jpg, png, and so on) which are made up of individual pixels, SVG images are defined by mathematical equations and can be scaled up or down infinitely without losing clarity.</p>
<p>Some developers prefer to use SVGs rather than other types of images because: </p>
<ul>
<li><strong>scalability</strong> – SVGs are infinitely scalable, which means that they can be used in a variety of different sizes and resolutions without losing quality.</li>
<li><strong>smaller file size</strong> – SVG images typically have a smaller file size than other types of images, such as JPEGs or PNGs.</li>
</ul>
<p><strong>Object-fit</strong>: The object-fit property is used to specify how the img should be resized to fit its container. This property tells the content to fill the container in a variety of ways, such as "preserve that aspect ratio" or "stretch up and take up as much space as possible".</p>
<h2 id="heading-wrapping-up">Wrapping up</h2>
<p>In this article, I hope I have helped you learn about the basic components you'll need when building responsive websites. </p>
<p>Responsive websites are necessary, and it's essential for every web developer to be able to comfortably build responsive web applications.</p>
<p>In this article, I have talked about 5 main building blocks of responsive sites, which are:</p>
<ul>
<li>Media queries</li>
<li>Flexible layout</li>
<li>Flexible units</li>
<li>Positioning elements</li>
<li>Images</li>
</ul>
<p>Hopefully you can start using them in your own projects.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Why Accessibility Matters in UI/UX Design ]]>
                </title>
                <description>
                    <![CDATA[ Accessibility is a word that is often thrown around in the design field. As a UI/UX/Web Designer, you might have heard this word a few times and you might wonder why it's important.  In this article, you will learn: What accessibility means Some myt... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/why-accessibility-matters-in-ui-ux-design/</link>
                <guid isPermaLink="false">66d03a42a30d09f91d49b78d</guid>
                
                    <category>
                        <![CDATA[ a11y ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Accessibility ]]>
                    </category>
                
                    <category>
                        <![CDATA[ responsive design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Design ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Faith Olohijere ]]>
                </dc:creator>
                <pubDate>Thu, 25 May 2023 14:18:24 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/05/pexels--------------3077882.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Accessibility is a word that is often thrown around in the design field. As a UI/UX/Web Designer, you might have heard this word a few times and you might wonder why it's important. </p>
<p>In this article, you will learn:</p>
<ul>
<li>What accessibility means</li>
<li>Some myths surrounding accessibility</li>
<li>How to make your work more accessible</li>
<li>Some practical accessibility examples</li>
</ul>
<p>Let's get started!</p>
<h2 id="heading-what-is-accessibility">What is Accessibility?</h2>
<p>There are so many definitions of accessibility on the web. But to me, accessibility in digital/web design simply means designing to make content usable for people with disabilities. </p>
<p>Working with accessibility in mind involves designing websites, applications, and digital interfaces that can be navigated by individuals with visual, hearing, motor, or cognitive impairments.</p>
<h2 id="heading-some-myths-surrounding-accessibility">Some Myths Surrounding Accessibility</h2>
<p>Like every topic under the sun, lots of people have different opinions about accessibility. Some might be true, some might be false. </p>
<p>Below, I'll share some popular misconceptions about accessibility. </p>
<h3 id="heading-myth-people-with-disabilities-dont-use-my-platform">Myth: people with disabilities don't use my platform</h3>
<p>You might be designing for a governmental or corporate platform and think that people with disabilities will not use your platform. </p>
<p>This is an incorrect notion to have. There are different forms of disability, including temporary and permanent disabilities. You have no control over who might use your platform at any time or what they might need.</p>
<h3 id="heading-myth-accessibility-is-only-for-people-with-disabilities">Myth: accessibility is only for people with disabilities</h3>
<p>While accessibility measures are crucial for individuals with disabilities, they also benefit a wide range of people, including the elderly, those with temporary disabilities, individuals with situational limitations, and even people without apparent disabilities.</p>
<p>Accessibility best practices make websites and apps easier for everyone to use in various ways.</p>
<h3 id="heading-myth-accessibility-is-all-about-adding-alt-text">Myth: accessibility is all about adding ALT text</h3>
<p>Alt (alternative) text is an assistive technology which is a valuable tool. But you shouldn't only use alt text as a substitute for general/wider accessibility best practiceds. </p>
<p>Assistive technologies work best when used in conjunction with accessible designs and content. </p>
<h3 id="heading-myth-you-should-build-accessible-sites-just-so-you-dont-get-in-trouble-with-the-law">Myth: you should build accessible sites just so you don't get in trouble with the law</h3>
<p>Although accessibility is a legal and ethical requirement, you shouldn't build it into your designs because of that reason alone.</p>
<p>You should build accessible websites and apps because accessibility helps anyone who comes to your platform interact with it well.</p>
<h2 id="heading-why-is-accessibility-important">Why is Accessibility Important?</h2>
<p>Accessibility is important for a number of reasons. They include:</p>
<ul>
<li>Improved Usability: Accessibility improves the usability of a website or application. Features like clear navigation, intuitive design, and so on benefit all users. They also contribute to user satisfaction, usability and overall engagement with products and services.</li>
<li>Broad User Base: When your platform is accessible, it increases your user base, as people from different backgrounds and situations can use your platform. This expands the reach and customer base of your product.</li>
<li>Enhanced User Experience: Incorporating accessibility in your designs will enhance the experience of your users (disabled or not), making it easier to interact with your platform.</li>
<li>Equal Rights &amp; Inclusion: Accessibility promotes inclusivity and prevents discrimination based on disabilities. Everyone deserves to have equal access to opportunities, information, and social services.</li>
<li>Legal &amp; Ethical Requirements: Legally and ethically, accessibility is a requirement for different domains and platforms. Adhering to these legal requirements ensures compliance and helps your client avoid potential legal issues. </li>
</ul>
<h2 id="heading-how-to-make-your-designs-more-accessible">How to Make Your Designs More Accessible</h2>
<h3 id="heading-understanding-accessibility-guidelines">Understanding Accessibility Guidelines</h3>
<p>Familiarize yourself with accessibility standards such as the Web Content Accessibility Guidelines<a target="_blank" href="https://www.w3.org/TR/WCAG21/">(WCAG)</a>. These guidelines provide comprehensive recommendations for designing accessible digital content.</p>
<h3 id="heading-use-sufficient-color-contrast">Use Sufficient Color Contrast</h3>
<p>Opt for color combinations that are accessible for individuals with color blindness or low vision. Use tools to check the color contrast ratio and ensure that text is easily distinguishable from the background.</p>
<p>Here's an example of creating sufficient color contrast:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/Frame-3--2-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Color contrast example</em></p>
<p>In the example above, in the first sentence, the highlighted word (link) does not contrast well with the rest of the sentence. Compare with the second sentence where "link", is perfectly contrasting and has an underline, to create more emphasis. </p>
<p>It's more likely that the second sentence is accessible for individuals with color blindness or low vision.</p>
<h3 id="heading-create-inclusive-forms">Create Inclusive Forms</h3>
<p>Design forms that are user-friendly. Include clear labels, instructions and, error messages. Make sure to enable users navigate and complete the form without relying solely on a mouse.</p>
<p>Here's an example of creating an inclusive form:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/Frame-2--1-.png" alt="Image" width="600" height="400" loading="lazy">
<em>User-friendly form example</em></p>
<p>The first form has some issues: </p>
<ul>
<li>It does not have any header (to indicate what the form is for).</li>
<li>It shows an error field without explaining what it indicates.</li>
<li>The form does not specify the number of characters the password should have, all of which are very helpful to the user(s).</li>
</ul>
<p>All these were corrected in the second form, where:</p>
<ul>
<li>A header was added indicating that the form is for "<em>Course Registration</em>".</li>
<li>The error field specifically explains what's wrong – the user entered an invalid email address.</li>
<li>The number of password characters as required by the platform was stated.</li>
</ul>
<h3 id="heading-implement-responsive-design">Implement Responsive Design</h3>
<p>Some designers design for desktop versions only, not considering accessibility. But it's much more helpful to make your design responsive. </p>
<p>Ensuring that your designs are adaptable to different screen sizes and resolutions accommodates individuals who use various devices. This is a great way to make your designs more accessible.</p>
<p>Here's an example of implementing responsive design:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/Frame-8922.png" alt="Image" width="600" height="400" loading="lazy">
<em>Responsive Design example</em></p>
<p>Above is an example of a product description page of a website. The first image on the left shows the desktop version only. In the second image, the design has been made more accessible – you can see the mobile responsive version as well.</p>
<p>Designing for different screen sizes shows that your design accommodates individuals who use various devices, as stated earlier.</p>
<h3 id="heading-provide-feedback-and-error-handling">Provide Feedback and Error Handling</h3>
<p>Making sure your designs provide adequate feedback accompanied by the next step to take, gives a great user experience. Error notifications can completely discourage a user if not handled correctly. As such, adequate feedback is necessary to make your design accessible.</p>
<p>These are few ways of making your designs accessible, amongst others. You can make an accessibility checklist to help remind yourself of accessibility when designing. To help further, check out accessibilitychecklist.org to find out.</p>
<p>Here's an example of how to provide feedback and handle errors:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/Desktop---3--1-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Error handling example</em></p>
<p>In the example above, the first 404 page tells the user what error occurred, and what might be the cause – but does not suggest a way of fixing the error. Meanwhile, the second 404 page explains the error that occurred and provides a way of fixing it – "<em>Go to homepage</em>".</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Accessibility is important to customer retention and the growth of a business. As a UI/UX/Web designer, it's your responsibility to incorporate accessibility into your product and give your users an awesome experience. Remember, your user is the priority. </p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build a Responsive Navigation Bar with a Dropdown Menu using JavaScript ]]>
                </title>
                <description>
                    <![CDATA[ By Victor Eke Navigation bars are essential components used a lot in websites and web apps. As a web developer, you will need to be able to customize them, either for a client project or a basic portfolio site. In this guide, you'll learn how to buil... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-build-a-responsive-navigation-bar-with-dropdown-menu-using-javascript/</link>
                <guid isPermaLink="false">66d4617c37bd2215d1e24600</guid>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ responsive design ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 24 May 2023 20:52:51 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/05/responsive-navigation-bar-with-dropdown-menu-using-javascript.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Victor Eke</p>
<p>Navigation bars are essential components used a lot in websites and web apps. As a web developer, you will need to be able to customize them, either for a client project or a basic portfolio site.</p>
<p>In this guide, you'll learn how to build a navigation bar for yourself from scratch using just HTML, CSS, and JavaScript. You'll also learn how to make it accessible.</p>
<p>Here's a screenshot of what this navigation bar will look like:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/navigation-bar-final-result.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Final result of navigation bar</em></p>
<p>This design is inspired by Tran Mau Tri Tam's <a target="_blank" href="https://dribbble.com/shots/17305696-Minimal-Navigation?utm_source=Clipboard_Shot&amp;utm_campaign=tranmautritam&amp;utm_content=Minimal%20Navigation&amp;utm_medium=Social_Share&amp;utm_source=Clipboard_Shot&amp;utm_campaign=tranmautritam&amp;utm_content=Minimal%20Navigation&amp;utm_medium=Social_Share">Minimal Navigation bar</a> on Dribbble.</p>
<h2 id="heading-step-1-add-the-html-markup">Step 1 – Add the HTML Markup</h2>
<p>For brevity's sake, we'll be using an icon library called <a target="_blank" href="https://github.com/atisawd/boxicons">boxicons</a> to import certain icons for this navbar. I highly recommend using inline SVGs instead. </p>
<p>To make use of this library, insert the snippet below in the head of your HTML file:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">href</span>=<span class="hljs-string">'https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css'</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">'stylesheet'</span>&gt;</span>
</code></pre>
<p>The markup is divided into three main parts:</p>
<ol>
<li>A <code>div</code> element with a class of <code>nav-start</code></li>
<li>Another <code>div</code> element with a class of <code>nav-end</code></li>
<li>A <code>button</code> element with an id of <code>hamburger</code></li>
</ol>
<p>All these elements will be enclosed within a <code>header</code> tag. To explain this better, copy the markup below and I'll explain what's happening after.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">header</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"nav-menu"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"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">"nav-start"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"logo"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://github.com/Evavic44/responsive-navbar-with-dropdown/blob/main/assets/images/logo.png?raw=true"</span> 
             <span class="hljs-attr">width</span>=<span class="hljs-string">"35"</span> 
             <span class="hljs-attr">height</span>=<span class="hljs-string">"35"</span> 
             <span class="hljs-attr">alt</span>=<span class="hljs-string">"Inc Logo"</span>
          /&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">nav</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"menu"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
    <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">"nav-end"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"right-container"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"search"</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"search"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"search"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"search"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Search"</span> /&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"bx bx-search"</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">"true"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>

        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#profile"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://github.com/Evavic44/responsive-navbar-with-dropdown/blob/main/assets/images/user.jpg?raw=true"</span> 
               <span class="hljs-attr">width</span>=<span class="hljs-string">"30"</span> 
               <span class="hljs-attr">height</span>=<span class="hljs-string">"30"</span> 
               <span class="hljs-attr">alt</span>=<span class="hljs-string">"user image"</span> 
            /&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"btn btn-primary"</span>&gt;</span>Create<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
      <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>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">header</span>&gt;</span>
</code></pre>
<p>For the nav-start, we have the following elements:</p>
<ul>
<li>An <code>&lt;img&gt;</code> element for the logo wrapped with an anchor <code>&lt;a&gt;</code> tag.</li>
<li>A <code>&lt;nav&gt;</code> element with a class of <code>menu</code> which will contain all the navigation links. We'll define these links later using a combination of <code>&lt;ul&gt;</code>, <code>li&gt;</code> and <code>&lt;a&gt;</code> tags.</li>
</ul>
<p>The nav-end has the following elements:</p>
<ul>
<li>A <code>&lt;form&gt;</code> element with a role of search that contains a search input and search icon.</li>
<li>A button element with a class of <code>btn</code>. We'll use this class to style the button.</li>
</ul>
<p>Here's the resulting output:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/markup-elements-broken-down-into-three-main-parts-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-navigation-menu">Navigation menu</h3>
<p>The navigation menu <code>&lt;nav&gt;</code> is where the navigation links will be. Replace the <code>nav</code> element you added earlier with this markup below:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">nav</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"menu"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"hamburger"</span> <span class="hljs-attr">aria-expanded</span>=<span class="hljs-string">"false"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"bx bx-menu"</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">"true"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"menu"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"menu-bar"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">button</span> 
                  <span class="hljs-attr">class</span>=<span class="hljs-string">"nav-link dropdown-btn"</span> 
                  <span class="hljs-attr">data-dropdown</span>=<span class="hljs-string">"dropdown1"</span> 
                  <span class="hljs-attr">aria-expanded</span>=<span class="hljs-string">"false"</span>&gt;</span>
                    Browse
                  <span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"bx bx-chevron-down"</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">"true"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"dropdown1"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">button</span> 
                  <span class="hljs-attr">class</span>=<span class="hljs-string">"nav-link dropdown-btn"</span> 
                  <span class="hljs-attr">data-dropdown</span>=<span class="hljs-string">"dropdown2"</span> 
                  <span class="hljs-attr">aria-expanded</span>=<span class="hljs-string">"false"</span>&gt;</span>
                    Discover
                  <span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"bx bx-chevron-down"</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">"true"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"dropdown2"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"nav-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/"</span>&gt;</span>Jobs<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"nav-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/"</span>&gt;</span>Livestream<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"nav-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/"</span>&gt;</span>About<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
</code></pre>
<p>Here you have a <code>nav</code> tag that contains a button and an unordered list of five <code>li</code> elements representing each navigation menu item: <strong>browse, discover, jobs, livestream,</strong> and <strong>about</strong>. </p>
<p>The button serves as a hamburger menu, and is a button with an id and <code>aria-expanded</code> set to "false". The <code>aria-expanded</code> attribute will enable us make this button more accessible to screen readers.</p>
<p>The first two list elements, <strong>browse</strong> and <strong>discover</strong>, are <code>button</code> elements and will be used to toggle their individual dropdown menu. The remaining elements <strong>Jobs, livestream</strong>, and <strong>about</strong>, are just regular links.</p>
<p>With the code so far, your result should look like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/Navigation-markup-with-links-and-popup-buttons.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-dropdown-element">Dropdown Element</h3>
<p>Next up, let's define the dropdown element for each navigation button. Here's the markup for the first dropdown. Replace the first <code>li</code> element in your markup with this:</p>
<pre><code class="lang-html"><span class="hljs-comment">&lt;!-- markup truncated for brevity--&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span>
      <span class="hljs-attr">class</span>=<span class="hljs-string">"nav-link dropdown-btn"</span>
      <span class="hljs-attr">data-dropdown</span>=<span class="hljs-string">"dropdown1"</span>
      <span class="hljs-attr">aria-expanded</span>=<span class="hljs-string">"false"</span>
    &gt;</span>
      Browse
      <span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"bx bx-chevron-down"</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">"true"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"dropdown1"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#best-of-the-day"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./assets/icons/botd.svg"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"icon"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link-title"</span>
                &gt;</span>Best of the day<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>
              &gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Shorts featured today by curators<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#featured-streams"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./assets/icons/fs.svg"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"icon"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link-title"</span>
                &gt;</span>Featured Streams<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>
              &gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Leading creatives livestreams<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#subscriptions"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./assets/icons/sp.svg"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"icon"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link-title"</span>&gt;</span>Subscriptions<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Gain exclusive access<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#creative-feed"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./assets/icons/cf.svg"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"icon"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link-title"</span>&gt;</span>Creative Feed<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>See trending creations<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>

      <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"apps- class="</span><span class="hljs-attr">dropdown-link-title</span>"&gt;</span>Browse by apps<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#adobe-xd"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./assets/icons/xd.svg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span>/&gt;</span>
            Adobe XD
          <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#after-effect"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./assets/icons/ae.svg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span>/&gt;</span>
            After Effect
          <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#sketch"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./assets/icons/sketch.svg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span>/&gt;</span>
            Sketch
          <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#indesign"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./assets/icons/indesign.svg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span>/&gt;</span>
            Indesign
          <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#figma"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./assets/icons/figma.svg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span> /&gt;</span>
            Figma
          <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
</code></pre>
<p>You can get the SVG icons <a target="_blank" href="https://github.com/Evavic44/responsive-navbar-with-dropdown/tree/main/assets/icons">here</a>.</p>
<p>To breakdown this markup, we added the following:</p>
<ul>
<li>A <code>div</code> element with an id of <code>dropdown1</code> and class of <code>dropdown</code>. </li>
<li>Two <code>ul</code> elements.</li>
<li>A <code>span</code> element with a class of  <code>dropdown-link-title</code> for the header of each <code>menu</code> collection.</li>
<li>A collection of links defined using <code>li</code> and <code>a</code> tags. The links each have a class of <code>dropdown-link</code>.</li>
<li>Inside each anchor tag, an icon is added via the <code>img</code> tag.</li>
</ul>
<p>Note: Since the icons added via the <code>img</code> tag are strictly declarative, I highly suggest you add them as SVG elements directly. I am only doing this to make the code more readable.</p>
<p>Here's the markup for the second dropdown element <code>dropdown2</code>:</p>
<pre><code class="lang-html"><span class="hljs-comment">&lt;!-- markup truncated for brevity--&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span>
      <span class="hljs-attr">class</span>=<span class="hljs-string">"nav-link dropdown-btn"</span>
      <span class="hljs-attr">data-dropdown</span>=<span class="hljs-string">"dropdown2"</span>
      <span class="hljs-attr">aria-expanded</span>=<span class="hljs-string">"false"</span>
    &gt;</span>
      Discover
      <span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"bx bx-chevron-down"</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">"true"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"dropdown2"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">aria-labelledby</span>=<span class="hljs-string">"categories-title"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"categories-title"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link-title"</span>&gt;</span>Browse Categories<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#branding"</span>&gt;</span>Branding<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#illustrations"</span>&gt;</span>Illustration<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">aria-labelledby</span>=<span class="hljs-string">"download-title"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"download-title"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link-title"</span>&gt;</span>Download App<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#mac-windows"</span>&gt;</span>MacOS &amp; Windows<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#linux"</span>&gt;</span>Linux<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
</code></pre>
<p>The final result should look like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/popup1-and-popup2-markup-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The full markup will be provided at the end of this tutorial.</p>
<h2 id="heading-step-2-style-the-navigation-bar">Step 2 – Style the Navigation Bar</h2>
<p>As always, we'll start by resetting the default margin and padding of every element on the page, add global variables, and some basic styling to a few elements.</p>
<pre><code class="lang-css"><span class="hljs-comment">/* style.css */</span>
<span class="hljs-keyword">@import</span> url(<span class="hljs-string">"https://fonts.googleapis.com/css2?family=Inter:wght@200;300;400;500;600;700&amp;display=swap"</span>);

* {
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">box-sizing</span>: border-box;
  <span class="hljs-attribute">font-family</span>: <span class="hljs-string">"Inter"</span>, sans-serif;
}

<span class="hljs-selector-pseudo">:root</span> {
  <span class="hljs-attribute">--dark-grey</span>: <span class="hljs-number">#333333</span>;
  <span class="hljs-attribute">--medium-grey</span>: <span class="hljs-number">#636363</span>;
  <span class="hljs-attribute">--light-grey</span>: <span class="hljs-number">#eeeeee</span>;
  <span class="hljs-attribute">--ash</span>: <span class="hljs-number">#f4f4f4</span>;
  <span class="hljs-attribute">--primary-color</span>: <span class="hljs-number">#2b72fb</span>;
  <span class="hljs-attribute">--white</span>: white;
  <span class="hljs-attribute">--border</span>: <span class="hljs-number">1px</span> solid <span class="hljs-built_in">var</span>(--light-grey);
  <span class="hljs-attribute">--shadow</span>: <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0.05</span>) <span class="hljs-number">0px</span> <span class="hljs-number">6px</span> <span class="hljs-number">24px</span> <span class="hljs-number">0px</span>,
    <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0.08</span>) <span class="hljs-number">0px</span> <span class="hljs-number">0px</span> <span class="hljs-number">0px</span> <span class="hljs-number">1px</span>;
}

<span class="hljs-selector-tag">body</span> {
  <span class="hljs-attribute">font-family</span>: inherit;
  <span class="hljs-attribute">background-color</span>: <span class="hljs-built_in">var</span>(--white);
  <span class="hljs-attribute">color</span>: <span class="hljs-built_in">var</span>(--dark-grey);
  <span class="hljs-attribute">letter-spacing</span>: -<span class="hljs-number">0.4px</span>;
}

<span class="hljs-selector-tag">ul</span> {
  <span class="hljs-attribute">list-style</span>: none;
}

<span class="hljs-selector-tag">a</span> {
  <span class="hljs-attribute">text-decoration</span>: none;
  <span class="hljs-attribute">color</span>: inherit;
}

<span class="hljs-selector-tag">button</span> {
  <span class="hljs-attribute">border</span>: none;
  <span class="hljs-attribute">background-color</span>: transparent;
  <span class="hljs-attribute">cursor</span>: pointer;
  <span class="hljs-attribute">color</span>: inherit;
}
</code></pre>
<p>Next, add some reusable styles.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.btn</span> {
  <span class="hljs-attribute">display</span>: block;
  <span class="hljs-attribute">background-color</span>: <span class="hljs-built_in">var</span>(--primary-color);
  <span class="hljs-attribute">color</span>: <span class="hljs-built_in">var</span>(--white);
  <span class="hljs-attribute">text-align</span>: center;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0.6rem</span> <span class="hljs-number">1.4rem</span>;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1rem</span>;
  <span class="hljs-attribute">font-weight</span>: <span class="hljs-number">500</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">5px</span>;
}

<span class="hljs-selector-class">.icon</span> {
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0.5rem</span>;
  <span class="hljs-attribute">background-color</span>: <span class="hljs-built_in">var</span>(--light-grey);
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">10px</span>;
}

<span class="hljs-selector-class">.logo</span> {
  <span class="hljs-attribute">margin-right</span>: <span class="hljs-number">1.5rem</span>;
}

<span class="hljs-selector-id">#nav-menu</span> {
  <span class="hljs-attribute">border-bottom</span>: <span class="hljs-built_in">var</span>(--border);
}

<span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">align-items</span>: center;
  <span class="hljs-attribute">justify-content</span>: space-between;
  <span class="hljs-attribute">max-width</span>: <span class="hljs-number">1600px</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span> auto;
  <span class="hljs-attribute">column-gap</span>: <span class="hljs-number">2rem</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">90px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">1.2rem</span> <span class="hljs-number">3rem</span>;
}
</code></pre>
<p>Now that you've gotten this basic styling out of the way, you can focus on styling the core navigation bar itself.</p>
<h3 id="heading-navigation-menu-styles">Navigation menu styles</h3>
<p>Here's the markup to style the navigation bar container:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.menu</span> {
  <span class="hljs-attribute">position</span>: relative;
  <span class="hljs-attribute">background</span>: <span class="hljs-built_in">var</span>(--white);
}

<span class="hljs-selector-class">.menu-bar</span> <span class="hljs-selector-tag">li</span><span class="hljs-selector-pseudo">:first-child</span> <span class="hljs-selector-class">.dropdown</span> {
  <span class="hljs-attribute">flex-direction</span>: initial;
  <span class="hljs-attribute">min-width</span>: <span class="hljs-number">480px</span>;
}

<span class="hljs-selector-class">.menu-bar</span> <span class="hljs-selector-tag">li</span><span class="hljs-selector-pseudo">:first-child</span> <span class="hljs-selector-tag">ul</span><span class="hljs-selector-pseudo">:nth-child(1)</span> {
  <span class="hljs-attribute">border-right</span>: <span class="hljs-built_in">var</span>(--border);
}

<span class="hljs-selector-class">.menu-bar</span> <span class="hljs-selector-tag">li</span><span class="hljs-selector-pseudo">:nth-child(n</span> + 2) <span class="hljs-selector-tag">ul</span><span class="hljs-selector-pseudo">:nth-child(1)</span> {
  <span class="hljs-attribute">border-bottom</span>: <span class="hljs-built_in">var</span>(--border);
}

<span class="hljs-selector-class">.menu-bar</span> <span class="hljs-selector-class">.dropdown-link-title</span> {
  <span class="hljs-attribute">font-weight</span>: <span class="hljs-number">600</span>;
}

<span class="hljs-selector-class">.menu-bar</span> <span class="hljs-selector-class">.nav-link</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1rem</span>;
  <span class="hljs-attribute">font-weight</span>: <span class="hljs-number">500</span>;
  <span class="hljs-attribute">letter-spacing</span>: -<span class="hljs-number">0.6px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0.3rem</span>;
  <span class="hljs-attribute">min-width</span>: <span class="hljs-number">60px</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span> <span class="hljs-number">0.6rem</span>;
}

<span class="hljs-selector-class">.menu-bar</span> <span class="hljs-selector-class">.nav-link</span><span class="hljs-selector-pseudo">:hover</span>,
<span class="hljs-selector-class">.dropdown-link</span><span class="hljs-selector-pseudo">:hover</span> {
  <span class="hljs-attribute">color</span>: <span class="hljs-built_in">var</span>(--primary-color);
}

<span class="hljs-selector-class">.nav-start</span>,
<span class="hljs-selector-class">.nav-end</span>,
<span class="hljs-selector-class">.menu-bar</span>,
<span class="hljs-selector-class">.right-container</span>,
<span class="hljs-selector-class">.right-container</span> <span class="hljs-selector-class">.search</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">align-items</span>: center;
}
</code></pre>
<h3 id="heading-dropdown-menu-styles">Dropdown Menu Styles</h3>
<p>In addition to styling the dropdown menu, it will be hidden using a combination of <code>visibility</code> and <code>opacity</code> properties. The idea is to show the menu only when the individual button has been clicked. </p>
<pre><code class="lang-css"><span class="hljs-selector-class">.dropdown</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">flex-direction</span>: column;
  <span class="hljs-attribute">min-width</span>: <span class="hljs-number">230px</span>;
  <span class="hljs-attribute">background-color</span>: <span class="hljs-built_in">var</span>(--white);
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">position</span>: absolute;
  <span class="hljs-attribute">top</span>: <span class="hljs-number">36px</span>;
  <span class="hljs-attribute">z-index</span>: <span class="hljs-number">1</span>;
  <span class="hljs-attribute">visibility</span>: hidden;
  <span class="hljs-attribute">opacity</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">scale</span>(<span class="hljs-number">0.97</span>) <span class="hljs-built_in">translateX</span>(-<span class="hljs-number">5px</span>);
  <span class="hljs-attribute">transition</span>: <span class="hljs-number">0.1s</span> ease-in-out;
  <span class="hljs-attribute">box-shadow</span>: <span class="hljs-built_in">var</span>(--shadow);
}

<span class="hljs-selector-class">.dropdown</span><span class="hljs-selector-class">.active</span> {
  <span class="hljs-attribute">visibility</span>: visible;
  <span class="hljs-attribute">opacity</span>: <span class="hljs-number">1</span>;
  <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">scale</span>(<span class="hljs-number">1</span>) <span class="hljs-built_in">translateX</span>(<span class="hljs-number">5px</span>);
}

<span class="hljs-selector-class">.dropdown</span> <span class="hljs-selector-tag">ul</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">flex-direction</span>: column;
  <span class="hljs-attribute">gap</span>: <span class="hljs-number">0.5rem</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">1.2rem</span>;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">0.95rem</span>;
}

<span class="hljs-selector-class">.dropdown-btn</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">align-items</span>: center;
  <span class="hljs-attribute">justify-content</span>: space-between;
  <span class="hljs-attribute">gap</span>: <span class="hljs-number">0.15rem</span>;
}

<span class="hljs-selector-class">.dropdown-link</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">gap</span>: <span class="hljs-number">0.5rem</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0.5rem</span> <span class="hljs-number">0</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">7px</span>;
  <span class="hljs-attribute">transition</span>: <span class="hljs-number">0.1s</span> ease-in-out;
}

<span class="hljs-selector-class">.dropdown-link</span> <span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">0.8rem</span>;
  <span class="hljs-attribute">color</span>: <span class="hljs-built_in">var</span>(--medium-grey);
}
</code></pre>
<p>Later on, the menu can be toggled by reverting the <code>visibility</code> and <code>opacity</code> properties back to the default state using the <code>active</code> class. But we'll do this via JavaScript. </p>
<p>If you prefer to hide the menu completely, substitute the <code>opacity</code> and <code>visibility</code> properties with <code>display: none;</code>. Although this property is <a target="_blank" href="https://mdn.org/animatable-properties">not animatable</a> using transition in CSS.</p>
<h3 id="heading-right-menu-styles">Right menu styles</h3>
<p>Next, add the styling for the search input, button, and profile image and then hide the hamburger button on desktop screens.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.right-container</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">align-items</span>: center;
  <span class="hljs-attribute">column-gap</span>: <span class="hljs-number">1rem</span>;
}

<span class="hljs-selector-class">.right-container</span> <span class="hljs-selector-class">.search</span> {
  <span class="hljs-attribute">position</span>: relative;
}

<span class="hljs-selector-class">.right-container</span> <span class="hljs-selector-tag">img</span> {
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span>;
}

<span class="hljs-selector-class">.search</span> <span class="hljs-selector-tag">input</span> {
  <span class="hljs-attribute">background-color</span>: <span class="hljs-built_in">var</span>(--ash);
  <span class="hljs-attribute">border</span>: none;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">6px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0.7rem</span>;
  <span class="hljs-attribute">padding-left</span>: <span class="hljs-number">2.4rem</span>;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">16px</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
  <span class="hljs-attribute">border</span>: <span class="hljs-built_in">var</span>(--border);
}

<span class="hljs-selector-class">.search</span> <span class="hljs-selector-class">.search-icon</span> {
  <span class="hljs-attribute">position</span>: absolute;
  <span class="hljs-attribute">left</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">top</span>: <span class="hljs-number">50%</span>;
  <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translateY</span>(-<span class="hljs-number">50%</span>);
  <span class="hljs-attribute">opacity</span>: <span class="hljs-number">0.6</span>;
}

<span class="hljs-selector-id">#hamburger</span> {
  <span class="hljs-attribute">display</span>: none;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0.1rem</span>;
  <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">1rem</span>;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1.9rem</span>;
}
</code></pre>
<p>Here's what it should look like:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/final-styling-output-of-navigation-bar-and-popup-menu.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>To finish up the styling, add the media query styling:</p>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">1100px</span>) {
  <span class="hljs-selector-id">#hamburger</span> {
    <span class="hljs-attribute">display</span>: block;
    <span class="hljs-attribute">position</span>: relative;
    <span class="hljs-attribute">left</span>: <span class="hljs-built_in">calc</span>(<span class="hljs-number">100vw</span> - <span class="hljs-number">9rem</span>);
  }

  <span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">1.2rem</span>;
    <span class="hljs-attribute">margin-right</span>: <span class="hljs-number">3rem</span>;
  }

  <span class="hljs-selector-class">.menu</span> {
    <span class="hljs-attribute">display</span>: none;
    <span class="hljs-attribute">position</span>: absolute;
    <span class="hljs-attribute">top</span>: <span class="hljs-number">87px</span>;
    <span class="hljs-attribute">left</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">min-height</span>: <span class="hljs-number">100vh</span>;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100vw</span>;
  }

  <span class="hljs-selector-class">.menu-bar</span> <span class="hljs-selector-tag">li</span><span class="hljs-selector-pseudo">:first-child</span> <span class="hljs-selector-tag">ul</span><span class="hljs-selector-pseudo">:nth-child(1)</span> {
    <span class="hljs-attribute">border-right</span>: none;
    <span class="hljs-attribute">border-bottom</span>: <span class="hljs-built_in">var</span>(--border);
  }

  <span class="hljs-selector-class">.dropdown</span> {
    <span class="hljs-attribute">display</span>: none;
    <span class="hljs-attribute">min-width</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">border</span>: none <span class="hljs-meta">!important</span>;
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">5px</span>;
    <span class="hljs-attribute">position</span>: static;
    <span class="hljs-attribute">top</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">left</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">visibility</span>: visible;
    <span class="hljs-attribute">opacity</span>: <span class="hljs-number">1</span>;
    <span class="hljs-attribute">transform</span>: none;
    <span class="hljs-attribute">box-shadow</span>: none;
  }

  <span class="hljs-selector-class">.menu</span><span class="hljs-selector-class">.show</span>,
  <span class="hljs-selector-class">.dropdown</span><span class="hljs-selector-class">.active</span> {
    <span class="hljs-attribute">display</span>: block;
  }

  <span class="hljs-selector-class">.dropdown</span> <span class="hljs-selector-tag">ul</span> {
    <span class="hljs-attribute">padding-left</span>: <span class="hljs-number">0.3rem</span>;
  }

  <span class="hljs-selector-class">.menu-bar</span> {
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">flex-direction</span>: column;
    <span class="hljs-attribute">align-items</span>: stretch;
    <span class="hljs-attribute">row-gap</span>: <span class="hljs-number">1rem</span>;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">1rem</span>;
  }

  <span class="hljs-selector-class">.menu-bar</span> <span class="hljs-selector-class">.nav-link</span> {
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">justify-content</span>: space-between;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">font-weight</span>: <span class="hljs-number">600</span>;
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1.2rem</span>;
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
  }

  <span class="hljs-selector-class">.menu-bar</span> &gt; <span class="hljs-selector-tag">li</span><span class="hljs-selector-pseudo">:not(</span><span class="hljs-selector-pseudo">:last-child)</span> {
    <span class="hljs-attribute">padding-bottom</span>: <span class="hljs-number">0.5rem</span>;
    <span class="hljs-attribute">border-bottom</span>: <span class="hljs-built_in">var</span>(--border);
  }
}

<span class="hljs-keyword">@media</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">600px</span>) {
  <span class="hljs-selector-class">.right-container</span> {
    <span class="hljs-attribute">display</span>: none;
  }
}
</code></pre>
<p>First, this arranges the elements, and most importantly, it targets the <code>hamburger</code> class and hides it. Now on tablet and mobile screens, the navigation bar is responsive and the hamburger button is visible.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/responsive-navigation-bar-2.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<p>This completes the navigation bar styling. Let's work on the functionality in the next section.</p>
<h2 id="heading-step-3-add-javascript-functionality">Step 3 – Add JavaScript Functionality</h2>
<p>For the JavaScript functionality, we'll focus on the following categories:</p>
<ul>
<li>Toggling the dropdown menu visibility</li>
<li>Closing the dropdown menu</li>
<li>Toggling the hamburger menu visibility</li>
<li>Toggling the aria-expanded attribute</li>
</ul>
<p>First, select your classes using the DOM's <code>querySelector</code> method and store them in variables so they are reusable.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// script.js</span>
<span class="hljs-keyword">const</span> dropdownBtn = <span class="hljs-built_in">document</span>.querySelectorAll(<span class="hljs-string">".dropdown-btn"</span>);
<span class="hljs-keyword">const</span> dropdown = <span class="hljs-built_in">document</span>.querySelectorAll(<span class="hljs-string">".dropdown"</span>);
<span class="hljs-keyword">const</span> hamburgerBtn = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"hamburger"</span>);
<span class="hljs-keyword">const</span> navMenu = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">".menu"</span>);
<span class="hljs-keyword">const</span> links = <span class="hljs-built_in">document</span>.querySelectorAll(<span class="hljs-string">".dropdown a"</span>);
</code></pre>
<p>Next add the functions below in your code. I'll explain their uses a bit later.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">setAriaExpandedFalse</span>(<span class="hljs-params"></span>) </span>{
  dropdownBtn.forEach(<span class="hljs-function">(<span class="hljs-params">btn</span>) =&gt;</span> btn.setAttribute(<span class="hljs-string">"aria-expanded"</span>, <span class="hljs-string">"false"</span>));
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">closeDropdownMenu</span>(<span class="hljs-params"></span>) </span>{
  dropdown.forEach(<span class="hljs-function">(<span class="hljs-params">drop</span>) =&gt;</span> {
    drop.classList.remove(<span class="hljs-string">"active"</span>);
    drop.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> e.stopPropagation());
  });
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">toggleHamburger</span>(<span class="hljs-params"></span>) </span>{
    navMenu.classList.toggle(<span class="hljs-string">"show"</span>);
    hamburgerBtn.setAttribute(
        <span class="hljs-string">"aria-expanded"</span>,
        hamburgerBtn.getAttribute(<span class="hljs-string">"aria-expanded"</span>) === <span class="hljs-string">"false"</span> ? <span class="hljs-string">"true"</span> : <span class="hljs-string">"false"</span>
    );
}
</code></pre>
<h3 id="heading-get-dropdown-menu-id">Get dropdown menu ID</h3>
<p>The next step is getting the dropdown menu ID. Since there are two dropdown menus, the value will be based on what dropdown button is clicked.</p>
<p>To get the ID, you'll utilize the <code>dataset</code> property and then store the value into its own variable.</p>
<pre><code class="lang-js">dropdownBtn.forEach(<span class="hljs-function">(<span class="hljs-params">btn</span>) =&gt;</span> {
  btn.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">e</span>) </span>{
    <span class="hljs-keyword">const</span> dropdownIndex = e.currentTarget.dataset.dropdown;
    <span class="hljs-keyword">const</span> dropdownElement = <span class="hljs-built_in">document</span>.getElementById(dropdownIndex);
    <span class="hljs-built_in">console</span>.log(dropdownElement);
  });
});
</code></pre>
<p>To break this snippet down:</p>
<ul>
<li>The <code>forEach</code> method loops through the collection of buttons</li>
<li>The <code>addEventListener()</code> method attaches a click event to each button</li>
<li>The <code>currentTarget.dataset</code> property fetches the current dropdown of the button clicked.</li>
<li>Each of the ids are used to target the corresponding dropdown element</li>
</ul>
<p>What this means is that when the button with a dataset of  <code>dropdown1</code> is clicked, the <code>div</code> element with an id of <code>dropdown1</code> is logged to the console, and inversely for the <code>dropdown2</code> button.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/get-popup-element-id-dynamically-1.gif" alt="Image" width="600" height="400" loading="lazy">
<em>dynamically getting each dropdown element using the button dataset property</em></p>
<h3 id="heading-toggle-the-dropdown-menu">Toggle the dropdown menu</h3>
<p>Toggling the menu is fairly easy now that you have the dropdown element ID stored into a variable called <code>dropdownElement</code>. By targeting this variable, you can toggle the <code>active</code> class on each dropdown element.</p>
<pre><code class="lang-js">dropdownBtn.forEach(<span class="hljs-function">(<span class="hljs-params">btn</span>) =&gt;</span> {
  btn.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">e</span>) </span>{
    <span class="hljs-keyword">const</span> dropdownIndex = e.currentTarget.dataset.dropdown;
    <span class="hljs-keyword">const</span> dropdownElement = <span class="hljs-built_in">document</span>.getElementById(dropdownIndex);

    dropdownElement.classList.toggle(<span class="hljs-string">"active"</span>);
    dropdown.forEach(<span class="hljs-function">(<span class="hljs-params">drop</span>) =&gt;</span> {
      <span class="hljs-keyword">if</span> (drop.id !== btn.dataset[<span class="hljs-string">"dropdown"</span>]) {
        drop.classList.remove(<span class="hljs-string">"active"</span>);
      }
    });
    e.stopPropagation();
  });
});
</code></pre>
<p>In addition to toggling the dropdown menu, we added a condition to check if the current dropdown element id matches with the active button. This makes sure only one dropdown element is expanded at a time.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/toggling-dropdown-element.gif" alt="Image" width="600" height="400" loading="lazy">
<em>toggling the dropdown menu</em></p>
<h3 id="heading-toggle-aria-expanded-property">Toggle aria-expanded property</h3>
<p>The <code>aria-expanded</code> property allows assistive technologies to announce whether an interactive menu is expanded or collapsed. To toggle this property, insert this code inside the <code>btn</code> code block under <code>e.stopPropagation()</code>:</p>
<pre><code class="lang-js">btn.setAttribute(
    <span class="hljs-string">"aria-expanded"</span>,
    btn.getAttribute(<span class="hljs-string">"aria-expanded"</span>) === <span class="hljs-string">"false"</span> ? <span class="hljs-string">"true"</span> : <span class="hljs-string">"false"</span>
);
</code></pre>
<p>Now anytime the dropdown menu is visible, the <code>aria-expanded</code> property is set to true and when collapsed, it's set to false.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/toggling-the-aria-expanded-property.gif" alt="Image" width="600" height="400" loading="lazy">
<em>toggling the aria-expanded property</em></p>
<h3 id="heading-collapse-dropdown-menu">Collapse dropdown menu</h3>
<p>So far the dropdown collapses only when the buttons are clicked. Other instances it should be collapsed include:</p>
<ul>
<li>When the links inside the dropdown menu are clicked</li>
<li>When you hit the ESC key</li>
<li>When you click on the document body – essentially, outside of the dropdown container.</li>
</ul>
<p>By calling the functions created earlier, <code>closeDropdownMenu</code> and <code>setAriaExpandedFalse</code>, the dropdown menu can be collapsed and the <code>aria-expanded</code> attribute set to false.</p>
<pre><code class="lang-js"><span class="hljs-comment">// close dropdown menu when the dropdown links are clicked</span>
links.forEach(<span class="hljs-function">(<span class="hljs-params">link</span>) =&gt;</span>
  link.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">() =&gt;</span> {
    closeDropdownMenu();
    setAriaExpandedFalse();
  })
);

<span class="hljs-comment">// close dropdown menu when you click on the document body</span>
<span class="hljs-built_in">document</span>.documentElement.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">() =&gt;</span> {
  closeDropdownMenu();
  setAriaExpandedFalse();
});

<span class="hljs-comment">// close dropdown when the escape key is pressed</span>
<span class="hljs-built_in">document</span>.addEventListener(<span class="hljs-string">"keydown"</span>, <span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> {
  <span class="hljs-keyword">if</span> (e.key === <span class="hljs-string">"Escape"</span>) {
    closeDropdownMenu();
    setAriaExpandedFalse();
  }
});
</code></pre>
<p>Here's the resulting output:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/closing-dropdown-menu-when-dropdown-links-and-escape-key-is-clicked.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-toggle-hamburger-menu">Toggle hamburger menu</h3>
<p>To see the navigation bar on tablet and mobile screens, attach the <code>toggleHamburger</code> function as a callback on the hamburger button and then call the function inside the <code>links</code> code block.</p>
<pre><code class="lang-js">links.forEach(<span class="hljs-function">(<span class="hljs-params">link</span>) =&gt;</span>
  link.addEventListener(<span class="hljs-string">"click"</span>, <span class="hljs-function">() =&gt;</span> {
    closeDropdownMenu();
    setAriaExpandedFalse();
    toggleHamburger();
  })
);
</code></pre>
<pre><code class="lang-js">hamburgerBtn.addEventListener(<span class="hljs-string">"click"</span>, toggleHamburger);
</code></pre>
<p>This will essentially toggle a different class called <code>show</code> that controls showing the navigation bar or hiding it, and update the <code>aria-expanded</code> attribute accordingly.</p>
<p>Note that to truly make the hamburger menu accessible, you would need to make it automatically close when it loses focus (either by a change in keyboard focus or a mouse click).</p>
<p>Here's the final output:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/show-hamburger-menu-on-tablet-and-mobile-screens.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-add-more-dropdown-menus">Add More Dropdown Menus</h2>
<p>You can add more dropdown menus by simply replacing any of the list items with a link to the one with a button and dropdown menu. In other for it to work, make sure you update the following:</p>
<ul>
<li>The dropdown ID according to how many menus you need. For example a third menu will have an id of <code>dropdown3</code></li>
<li>The button will have its <code>data-dropdown</code> value set to <code>dropdown3</code></li>
</ul>
<p>Here's an example that converts the <strong>Jobs</strong> link into a dropdown menu.</p>
<h3 id="heading-before">Before:</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"nav-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/"</span>&gt;</span>Jobs<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
</code></pre>
<h3 id="heading-after">After:</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span>
      <span class="hljs-attr">class</span>=<span class="hljs-string">"nav-link dropdown-btn"</span>
      <span class="hljs-attr">data-dropdown</span>=<span class="hljs-string">"dropdown3"</span>
      <span class="hljs-attr">aria-expanded</span>=<span class="hljs-string">"false"</span>
    &gt;</span>
      Jobs
      <span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"bx bx-chevron-down"</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">"true"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"dropdown3"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link-title"</span>&gt;</span>Software<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#frontend"</span>&gt;</span>Frontend<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#backend"</span>&gt;</span>Backend<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#ai-ml"</span>&gt;</span>AI/ML<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#mobile-dev"</span>&gt;</span>Mobile Development<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link-title"</span>&gt;</span>Others<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#ui-ux"</span>&gt;</span>UI/UX<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"dropdown-link"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#writing"</span>&gt;</span>Technical Writing<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
</code></pre>
<p>Here's the final result:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/additional-dropdown-menu.png" alt="Image" width="600" height="400" loading="lazy">
<em>Final result after adding the third dropdown (Jobs)</em></p>
<p>Following this process, you can add as many dropdown menus as you want.</p>
<p>And with this, you’ve successfully built a responsive navigation bar with dropdown menus using just HTML, CSS, and JavaScript. You also learned how to make the menu accessible using a few aria attributes including the <code>aria-expanded</code> property.</p>
<h3 id="heading-heres-the-codepen-file-to-test-this-navigation-bar-in-action">Here’s the codepen file to test this navigation bar in action:</h3>
<div class="embed-wrapper"><iframe height="300" style="width:100%" src="https://codepen.io/evavic44/embed/QWZYEPQ?default-tab=html%2Cresult" title="Embedded content" loading="lazy">
  See the Pen <a href="https://codepen.io/evavic44/pen/QWZYEPQ">
  navbar with popup menu</a> by Eke (<a href="https://codepen.io/evavic44">@evavic44</a>)
  on <a href="https://codepen.io">CodePen</a>.
</iframe></div>

<p>Get code files from GitHub using this <a target="_blank" href="https://github.com/Evavic44/responsive-navbar-with-dropdown">link</a></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>I sincerely hope you found this post interesting or useful. If you did, kindly share with your friends or subscribe to my blog so you won't miss any future postings. Thanks for reading.</p>
<p><a target="_blank" href="https://github.com/Evavic44">GitHub</a> | <a target="_blank" href="https://twitter.com/victorekea">Twitter</a> | <a target="_blank" href="https://eke.hashnode.dev">Blog</a> | <a target="_blank" href="https://www.linkedin.com/in/victorekeawa/">LinkedIn</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use Container Queries – Responsive Design Beyond the Viewport ]]>
                </title>
                <description>
                    <![CDATA[ Before now, making your website responsive was limited to resizing HTML elements with media queries. This was, and still is, a brilliant innovation for web development in general.  But web development has evolved with the advent of JavaScript framewo... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/container-queries-responsive-design-beyond-the-viewport/</link>
                <guid isPermaLink="false">66bc54aaa085c9ae30a3c96e</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ responsive design ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Felix Favour Chinemerem ]]>
                </dc:creator>
                <pubDate>Mon, 22 May 2023 16:24:14 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/05/container-queries-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Before now, making your website responsive was limited to resizing HTML elements with media queries. This was, and still is, a brilliant innovation for web development in general. </p>
<p>But web development has evolved with the advent of JavaScript frameworks—particularly with the use of components as building blocks in developing User Interfaces.</p>
<p>In the component-driven world we are living in, we can see the benefits of container queries in Responsive Web Design. In fact, in some cases, we can achieve a fully-responsive webpage without using media queries.</p>
<p>In this article, we will explore responsive design beyond the viewport with Container Queries and analyze an example of a fully responsive site using just container queries.</p>
<h2 id="heading-so-what-are-container-queries">So, What are Container Queries?</h2>
<p>Container queries allow you to style HTML elements based on the size of their containers. It is similar in execution to media queries, except elements are styled based on the size of a viewport with media queries.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/05/container-queries-explanation.png" alt="Image" width="600" height="400" loading="lazy">
<em>Image illustrating Container Queries in CSS</em></p>
<h2 id="heading-how-to-use-container-queries">How to Use Container Queries</h2>
<h3 id="heading-the-containment-context">The containment context</h3>
<p>To use container queries, you need to tell the browser which HTML element you wish to use as a container. We do this by declaring a “containment context”. </p>
<p>A containment context instructs the browser to start paying attention to the size of a container (or an element). This way, the browser knows when to apply the styles specified in your container query.</p>
<p>To declare a containment context, we use the <code>container-type</code> property with a value of <code>size</code>, <code>inline-size</code>, or <code>normal</code>. See the <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/container-type">container-type</a> API reference to understand what each of these values means.</p>
<p>Consider the following example of a soft drink card component below:</p>
<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">"drink-card-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">"drink-card"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"images/coke.png"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"info"</span>&gt;</span>. . .<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>
 <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>We can then add a containment context to the container:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.drink-card-container</span> {
  <span class="hljs-attribute">container-type</span>: inline-size; 
}
</code></pre>
<p>And now, the browser pays attention to the size of <code>.drink-card-container</code>. Although, we still need to apply specific styles based on this container size, so we need the <code>@container</code> at-rule.</p>
<h3 id="heading-the-container-at-rule">The <code>@container</code> at-rule</h3>
<p>The <code>@container</code> at-rule allows you to style elements based on the size of their container. The container condition is evaluated when the container changes in size. Also, the @container at-rule is what primarily defines a container query. It takes this form:</p>
<pre><code class="lang-css"><span class="hljs-keyword">@container</span> &lt;container-condition&gt; {
  &lt;<span class="hljs-selector-tag">stylesheet</span>&gt;
}
</code></pre>
<p>It has a similar syntax to the <code>@media</code> at-rule in media queries.</p>
<p>Recall our soft drink card example. We can now add a <code>@container</code> at-rule that modifies the <code>flex-direction</code> of our <code>.drink-card</code> when the container’s size is less than or equal to <code>450px</code>.</p>
<pre><code class="lang-css"><span class="hljs-keyword">@container</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">450px</span>) {
  <span class="hljs-selector-class">.drink-card-container</span> <span class="hljs-selector-class">.drink-card</span> {
    <span class="hljs-attribute">flex-direction</span>: column;
  }
}
</code></pre>
<p>And that’s it! That’s all you need to know to start using container queries.</p>
<h3 id="heading-the-container-name-property">The container-name property</h3>
<p>Now that you know how container queries work, let's think about it at scale—what happens when we have multiple containers or containment contexts to work with? </p>
<p>This introduces the need for specificity when writing container queries, which is why the <code>container-name</code> property exists.</p>
<p>Let’s reconsider the example from our soft drink card component.</p>
<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">"drink-card-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">"drink-card"</span>&gt;</span>
    . . .
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"info"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>Coke<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>On May 8, 1886, the first glass of Coke was sold.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h5</span>&gt;</span>₦ 150 <span class="hljs-tag">&lt;<span class="hljs-name">sup</span>&gt;</span>estimated RRP<span class="hljs-tag">&lt;/<span class="hljs-name">sup</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">h5</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"&lt;https://www.coca-cola.com/&gt;"</span>&gt;</span>See Official Website<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <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>
 <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>We can then add a containment context to the <code>.info</code> element by giving it a <code>container-type</code> property, as we did earlier. But this time, we include a <code>container-name</code> property to give the container a specific identity.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.info</span> {
  <span class="hljs-attribute">container-type</span>: inline-size;
  <span class="hljs-attribute">container-name</span>: drink-info;
}
</code></pre>
<p>Our container query will then take this shape:</p>
<pre><code class="lang-css"><span class="hljs-keyword">@container</span> drink-info (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">200px</span>) {
  <span class="hljs-selector-class">.info</span> <span class="hljs-selector-tag">p</span> {
    <span class="hljs-attribute">display</span>: none;
  }
}
</code></pre>
<p>The code above tracks the size of the <code>.info</code> container (named <code>drink-info</code>) and hides the paragraph element when the container’s size is less than or equal to <code>200px</code>.</p>
<h2 id="heading-source-code-for-a-responsive-site-using-only-container-queries">Source Code for a Responsive Site Using Only Container Queries</h2>
<p>To access the complete source code where all of the snippets in this article were extracted, you can visit this <a target="_blank" href="https://github.com/felixfavour/container-queries">GitHub repository</a>.</p>
<h3 id="heading-live-preview">Live Preview</h3>
<p>You can see a live preview of the GitHub code <a target="_blank" href="https://felixfavour.github.io/container-queries.">here</a>. To see the responsiveness in action, resize the browser window. Alternatively, you can interact with the codepen below.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/felixfavour/embed/ZEqqRyr" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<h2 id="heading-browser-compatibility-for-container-queries">Browser Compatibility for Container Queries</h2>
<p>Container queries are available on all the major browser engines and are stable in all modern browsers. This means you can use it today for personal and work projects.</p>
<p>I hope this article helped you learn the basics of container queries. Now, you’re won't be confined to just using media queries—container queries are also a valid way to make your websites responsive.</p>
<p>I hope you found this article helpful. If you did, feel free to connect with me on LinkedIn and check out <a target="_blank" href="http://favourfelix.com/">favourfelix.com</a> to see what else I'm writing and up to.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ CSS Grid Handbook – Complete Guide to Grid Containers and Grid Items ]]>
                </title>
                <description>
                    <![CDATA[ CSS Grid gives you the tools to create basic and advanced website layouts in responsive ways that look great on mobile, tablet, and desktop devices. This tutorial discusses everything you need to know to use CSS Grid like a pro. Table of Contents Wh... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/complete-guide-to-css-grid/</link>
                <guid isPermaLink="false">66ba0ddfc003a1736007f49a</guid>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ responsive design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Oluwatobi Sofela ]]>
                </dc:creator>
                <pubDate>Thu, 16 Mar 2023 18:19:27 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738338779416/5e58d695-6840-40da-84bc-c2b2428c16db.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>CSS Grid gives you the tools to create basic and advanced website layouts in responsive ways that look great on mobile, tablet, and desktop devices.</p>
<p>This tutorial discusses everything you need to know to use CSS Grid like a pro.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ol>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grid">What Is CSS Grid?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-grid-container-vs-grid-item-whats-the-difference">Grid Container vs. Grid Item: What's the Difference?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-a-grid-value-in-css">What Is a <code>grid</code> Value in CSS?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-an-inline-grid-value-in-css">What Is an <code>inline-grid</code> Value in CSS?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-properties-for-specifying-a-grids-layout">Properties for Specifying a Grid's Layout</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-are-the-grid-containers-properties">What Are the Grid Container's Properties?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-template-columns-property">What Is CSS Grid's <code>grid-template-columns</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-template-rows-property">What Is CSS Grid's <code>grid-template-rows</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-justify-content-property">What Is CSS Grid's <code>justify-content</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-justify-items-property">What Is CSS Grid's <code>justify-items</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-align-content-property">What Is CSS Grid's <code>align-content</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-align-items-property">What Is CSS Grid's <code>align-items</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-are-the-grid-items-properties">What Are the Grid Item's Properties?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-justify-self-property">What Is CSS Grid's <code>justify-self</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-align-self-property">What Is CSS Grid's <code>align-self</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-column-start-property">What Is CSS Grid's <code>grid-column-start</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-column-end-property">What Is CSS Grid's <code>grid-column-end</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-column-property">What Is CSS Grid's <code>grid-column</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-row-start-property">What Is CSS Grid's <code>grid-row-start</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-row-end-property">What Is CSS Grid's <code>grid-row-end</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-row-property">What Is CSS Grid's <code>grid-row</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-area-property">What Is CSS Grid's <code>grid-area</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-template-areas-property">What Is CSS Grid's <code>grid-template-areas</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-use-the-css-minmax-function-to-define-minimum-and-maximum-grid-sizes">How to Use the CSS <code>minmax()</code> function to Define Minimum and Maximum Grid Sizes</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-use-the-css-repeat-function-to-define-grid-tracks-with-repeated-patterns">How to Use the CSS <code>repeat()</code> Function to Define Grid Tracks with Repeated Patterns</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-overview">Overview</a></p>
</li>
</ol>
<p>So, without any further ado, let's understand what CSS Grid is.</p>
<h2 id="heading-what-is-css-grid">What is CSS Grid?</h2>
<p>The CSS Grid Layout Module makes browsers display the selected HTML elements as grid <a target="_blank" href="https://codesweetly.com/css-box-model">box models</a>.</p>
<p>Grid allows you to easily resize and reposition a grid container and its items two-dimensionally.</p>
<p><strong>Note:</strong></p>
<ul>
<li><p>"Two-dimensionally" means grid modules allow simultaneous laying out of box models in rows and columns.</p>
</li>
<li><p>Use <a target="_blank" href="https://codesweetly.com/css-flexbox-explained">Flexbox</a> if you only need to resize and reposition elements one-dimensionally.</p>
</li>
</ul>
<h2 id="heading-grid-container-vs-grid-item-whats-the-difference">Grid Container vs. Grid Item: What's the Difference?</h2>
<p>A <strong>grid container</strong> is an <a target="_blank" href="https://codesweetly.com/web-tech-terms-h#html-element">HTML element</a> whose <a target="_blank" href="https://codesweetly.com/css-display-property"><code>display</code></a> property's value is <code>grid</code> or <code>inline-grid</code>.</p>
<p>A <strong>grid item</strong> is any of the direct children of a grid container.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-container-grid-item-illustration-codesweetly.png" alt="Illustration of a grid container and a grid item" width="600" height="400" loading="lazy"></p>
<p><em>A grid container (the large yellow area in the image) is an HTML element whose display property's value is grid or inline-grid. Grid items (the smaller boxes within the yellow container) are the direct children of a grid container.</em></p>
<h2 id="heading-what-is-a-grid-value-in-css">What Is a <code>grid</code> Value in CSS?</h2>
<p><code>grid</code> tells browsers to display the selected HTML element as a block-level grid box model.</p>
<p>In other words, setting an element's <code>display</code> property's value to <code>grid</code> turns the box model into a <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements">block-level</a> grid layout module.</p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-5ggr6k?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid</code> value to convert the HTML document's <code>&lt;section&gt;</code> elements from regular <code>&lt;section&gt;</code> nodes to block-level grid box models.</p>
<p><strong>Note:</strong></p>
<ul>
<li><p>The <code>display: grid</code> directive creates only a single-column grid container. Therefore, the grid items will display in the normal layout flow (one item below another).</p>
</li>
<li><p>Converting a node to a grid box model makes the element's direct children become grid items.</p>
</li>
<li><p>The <code>display: grid</code> directive only affects a box model and its direct children. It does not affect grandchildren nodes.</p>
</li>
</ul>
<p>Let's now discuss the <code>inline-grid</code> value.</p>
<h2 id="heading-what-is-an-inline-grid-value-in-css">What Is an <code>inline-grid</code> Value in CSS?</h2>
<p><code>inline-grid</code> tells browsers to display the selected HTML element as an inline-level grid box model.</p>
<p>In other words, setting an element's <code>display</code> property's value to <code>inline-grid</code> turns the box model into an <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements">inline-level</a> grid layout module.</p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: inline-grid;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-ekpbac?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>inline-grid</code> value to convert the HTML document's <code>&lt;section&gt;</code> elements from regular <code>&lt;section&gt;</code> nodes to inline-level grid box models.</p>
<p><strong>Note:</strong></p>
<ul>
<li><p>Converting a node to a grid box model makes the element's direct children become grid items.</p>
</li>
<li><p>The <code>display: inline-grid</code> directive only affects a box model and its direct children. It does not affect grandchildren nodes.</p>
</li>
</ul>
<h2 id="heading-properties-for-specifying-a-grids-layout">Properties for Specifying a Grid's Layout</h2>
<p>On converting a regular HTML element to a grid (or inline-grid) box model, the grid layout module provides two categories of properties for positioning the grid box and its direct children:</p>
<ul>
<li><p>Grid container's properties</p>
</li>
<li><p>Grid item's properties</p>
</li>
</ul>
<h2 id="heading-what-are-the-grid-containers-properties">What Are the Grid Container's Properties?</h2>
<p>A grid container's properties specify how browsers should layout items within the grid box model.</p>
<p><strong>Note:</strong> We define a grid container's property on the container, not its items.</p>
<p>The eight (8) types of grid container properties are:</p>
<ul>
<li><p><code>grid-template-columns</code></p>
</li>
<li><p><code>grid-template-rows</code></p>
</li>
<li><p><code>grid-auto-columns</code></p>
</li>
<li><p><code>grid-auto-rows</code></p>
</li>
<li><p><code>justify-content</code></p>
</li>
<li><p><code>justify-items</code></p>
</li>
<li><p><code>align-content</code></p>
</li>
<li><p><code>align-items</code></p>
</li>
</ul>
<p>Let's discuss the eight types now.</p>
<h2 id="heading-what-is-css-grids-grid-template-columns-property">What Is CSS Grid's <code>grid-template-columns</code> Property?</h2>
<p><strong>grid-template-columns</strong> specifies the number and widths of columns browsers should display in the selected grid container.</p>
<h3 id="heading-example-1-how-to-create-a-two-column-grid-container">Example 1: How to create a two-column grid container</h3>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">95px</span> <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-uwtgsf?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-template-columns</code> property to display two columns of different widths in the selected <code>&lt;section&gt;</code> grid container.</p>
<p><strong>Note:</strong> We used the <a target="_blank" href="https://codesweetly.com/css-unit#fraction-fr"><code>fr</code> (fraction) unit</a> to scale the second column relative to the fraction of available space in the grid container.</p>
<h3 id="heading-example-2-how-to-create-a-three-column-grid-container">Example 2: How to create a three-column grid container</h3>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">15%</span> <span class="hljs-number">60%</span> <span class="hljs-number">25%</span>;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-xaop69?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-template-columns</code> property to display three columns of different widths in the selected <code>&lt;section&gt;</code> grid container.</p>
<p><strong>Note:</strong></p>
<ul>
<li><p>You can use the <code>grid-auto-columns</code> property to specify default column widths for all the grid container's columns. For instance, <code>grid-auto-columns: 150px</code> will set default widths of <code>150px</code> for all columns. But a <code>grid-template-columns</code> declaration will override it.</p>
</li>
<li><p>Explicit grid columns are the columns you explicitly define with the <code>grid-template-columns</code> property.</p>
</li>
<li><p>Implicit grid columns are the columns browsers create automatically. We use the <code>grid-auto-columns</code> properties to specify <a target="_blank" href="https://codesweetly.com/css-grid-lines-explained">track</a> sizes for implicit columns.</p>
</li>
</ul>
<p><strong>Tip:</strong></p>
<ul>
<li><p>Use the CSS <code>repeat()</code> function to specify <code>grid-template-columns</code> values with repeated patterns. We will discuss the <code>repeat()</code> function later in this tutorial.</p>
</li>
<li><p>Use the <a target="_blank" href="https://codesweetly.com/css-column-gap-property">CSS <code>column-gap</code> property</a> to create gaps between grid columns.</p>
</li>
</ul>
<h2 id="heading-what-is-css-grids-grid-template-rows-property">What Is CSS Grid's <code>grid-template-rows</code> Property?</h2>
<p><strong>grid-template-rows</strong> specifies the number and heights of rows browsers should display in the selected grid container.</p>
<h3 id="heading-example-1-how-to-create-a-three-row-grid-container">Example 1: How to create a three-row grid container</h3>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-number">95px</span> <span class="hljs-number">1</span>fr <span class="hljs-number">70px</span>;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-tbisxm?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-template-rows</code> property to display three rows of different heights in the selected <code>&lt;section&gt;</code> grid container.</p>
<p><strong>Note:</strong> We used the <a target="_blank" href="https://codesweetly.com/css-unit#fraction-fr"><code>fr</code> (fraction) unit</a> to scale the second row relative to the fraction of available space in the grid container.</p>
<h3 id="heading-example-2-how-to-create-a-three-row-and-four-column-grid-container">Example 2: How to create a three-row and four-column grid container</h3>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-number">90px</span> <span class="hljs-number">300px</span> <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">grid-template-columns</span>: auto auto auto auto;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-e5vtot?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-template-rows</code> property to display three columns of different heights in the selected <code>&lt;section&gt;</code> grid container.</p>
<p><strong>Note:</strong></p>
<ul>
<li><p>You can use the <code>grid-auto-rows</code> property to specify default row heights for all the grid container's rows. For instance, <code>grid-auto-rows: 100px</code> will set default heights of <code>100px</code> for all rows. But a <code>grid-template-rows</code> declaration will override it.</p>
</li>
<li><p>Explicit grid rows are the rows you explicitly define with the <code>grid-template-rows</code> property.</p>
</li>
<li><p>Implicit grid rows are the rows browsers create automatically. We use the <code>grid-auto-rows</code> properties to specify <a target="_blank" href="https://codesweetly.com/css-grid-lines-explained">track</a> sizes for implicit rows.</p>
</li>
</ul>
<p><strong>Tip:</strong></p>
<ul>
<li><p>Use the CSS <code>repeat()</code> function to specify <code>grid-template-rows</code> values with repeated patterns. We will discuss the <code>repeat()</code> function later in this tutorial.</p>
</li>
<li><p>Use the <a target="_blank" href="https://codesweetly.com/css-row-gap-property">CSS <code>row-gap</code> property</a> to create gaps between grid rows.</p>
</li>
</ul>
<h2 id="heading-what-is-css-grids-justify-content-property">What Is CSS Grid's <code>justify-content</code> Property?</h2>
<p><strong>justify-content</strong> specifies how browsers should position a grid container's columns along its row axis.</p>
<p><strong>Note:</strong></p>
<ul>
<li><p>A row axis is sometimes called an inline axis.</p>
</li>
<li><p>The <code>justify-content</code> property works if the total column widths are less than the grid container's width. In other words, you need free space along the container's row axis to justify its columns left or right.</p>
</li>
</ul>
<p>The <code>justify-content</code> property accepts the following values:</p>
<ul>
<li><p><code>start</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>end</code></p>
</li>
<li><p><code>stretch</code></p>
</li>
<li><p><code>space-between</code></p>
</li>
<li><p><code>space-around</code></p>
</li>
<li><p><code>space-evenly</code></p>
</li>
</ul>
<p>Let's discuss these values.</p>
<h3 id="heading-what-is-justify-content-start-in-css-grid">What is <code>justify-content: start</code> in CSS Grid?</h3>
<p><code>start</code> positions the grid container's columns with its row-start edge.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-content-start-illustration-codesweetly.png" alt="Illustration of justify-content's start value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-content's start value positions columns to the grid container's row-start edge</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">justify-content</span>: start;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">4</span>, <span class="hljs-number">40px</span>);
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-rkwg9r?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>start</code> value to position the <code>&lt;section&gt;</code>'s columns to the grid container's row-start edge.</p>
<h3 id="heading-what-is-justify-content-center-in-css-grid">What is <code>justify-content: center</code> in CSS Grid?</h3>
<p><code>center</code> positions the grid container's columns to the center of the grid's row axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-content-center-illustration-codesweetly.png" alt="Illustration of justify-content's center value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-content's center value positions columns to the center of the grid container</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">justify-content</span>: center;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">4</span>, <span class="hljs-number">40px</span>);
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-ft8n3n?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>center</code> value to position the <code>&lt;section&gt;</code>'s columns to the center of the grid container.</p>
<h3 id="heading-what-is-justify-content-end-in-css-grid">What is <code>justify-content: end</code> in CSS Grid?</h3>
<p><code>end</code> positions a grid container's columns with its row-end edge.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-content-end-illustration-codesweetly.png" alt="Illustration of justify-content's end value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-content's end value positions columns to the grid container's row-end edge</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">justify-content</span>: end;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">4</span>, <span class="hljs-number">40px</span>);
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-zzaxjf?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>end</code> value to position the <code>&lt;section&gt;</code>'s columns to the grid container's row-end edge.</p>
<h3 id="heading-what-is-justify-content-space-between-in-css-grid">What is <code>justify-content: space-between</code> in CSS Grid?</h3>
<p><code>space-between</code> does the following:</p>
<ul>
<li><p>It positions a grid container's first column with its row-start edge.</p>
</li>
<li><p>It positions the container's last column with the row-end edge.</p>
</li>
<li><p>It creates even spacing between each pair of columns between the first and last columns.</p>
</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-content-space-between-illustration-codesweetly.png" alt="Illustration of justify-content's space-between value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-content's space-between value creates even spacing between each pair of columns between the first and last grid column</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">justify-content</span>: space-between;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">4</span>, <span class="hljs-number">40px</span>);
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-ajbrex?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>space-between</code> value to create even spacing between each pair of columns between the first and last grid column.</p>
<h3 id="heading-what-is-justify-content-space-around-in-css-grid">What is <code>justify-content: space-around</code> in CSS Grid?</h3>
<p><code>space-around</code> assigns equal spacing to each side of a grid container's columns.</p>
<p>Therefore, the space before the first column and after the last one is half the width of the space between each pair of columns.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-content-space-around-illustration-codesweetly.png" alt="Illustration of justify-content's space-around value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-content's space-around value assigns equal spacing to each side of the grid container's columns</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">justify-content</span>: space-around;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">4</span>, <span class="hljs-number">40px</span>);
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-qnla5x?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>space-around</code> value to assign equal spacing to each side of the grid container's columns.</p>
<h3 id="heading-what-is-justify-content-space-evenly-in-css-grid">What is <code>justify-content: space-evenly</code> in CSS Grid?</h3>
<p><code>space-evenly</code> assigns even spacing to both ends of a grid container and between its columns.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-content-space-evenly-illustration-codesweetly.png" alt="Illustration of justify-content's space-evenly value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-content's space-evenly value assigns even spacing to both ends of the grid container and between its columns</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">justify-content</span>: space-evenly;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">4</span>, <span class="hljs-number">40px</span>);
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-vnd1u3?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used the <code>space-evenly</code> value to assign even spacing to both ends of the grid container and between its columns.</p>
<h2 id="heading-what-is-css-grids-justify-items-property">What Is CSS Grid's <code>justify-items</code> Property?</h2>
<p><strong>justify-items</strong> specifies the default <a target="_blank" href="https://codesweetly.com/css-grid-justify-self-property"><code>justify-self</code></a> value for all the grid items.</p>
<p>The <code>justify-items</code> property accepts the following values:</p>
<ul>
<li><p><code>stretch</code></p>
</li>
<li><p><code>start</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>end</code></p>
</li>
</ul>
<p>Let's discuss the four values.</p>
<h3 id="heading-what-is-justify-items-stretch-in-css-grid">What is <code>justify-items: stretch</code> in CSS Grid?</h3>
<p><code>stretch</code> is <code>justify-items</code>' default value. It stretches the grid container's items to fill their individual cells' row (inline) axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-items-stretch-illustration-codesweetly.png" alt="Illustration of justify-items' stretch value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-items' stretch value stretches grid items to fill their individual cells' row axis</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">justify-items</span>: stretch;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-dedmgi?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>stretch</code> value to stretch the grid items to fill their individual cells' row axis.</p>
<h3 id="heading-what-is-justify-items-start-in-css-grid">What is <code>justify-items: start</code> in CSS Grid?</h3>
<p><code>start</code> positions a grid container's items with the row-start edge of their individual cells' row axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-items-start-illustration-codesweetly.png" alt="Illustration of justify-items' start value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-items' start value positions grid items to their individual cells' row-start edge</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">justify-items</span>: start;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-zdzwmb?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>start</code> value to position the grid items to their individual cells' row-start edge.</p>
<h3 id="heading-what-is-justify-items-center-in-css-grid">What is <code>justify-items: center</code> in CSS Grid?</h3>
<p><code>center</code> positions a grid container's items to the center of their individual cells' row axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-items-center-illustration-codesweetly.png" alt="Illustration of justify-items' center value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-items' center value positions grid items to their individual cells' center</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">justify-items</span>: center;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-dsgyni?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>center</code> value to position the grid items to the center of their individual cells' row axis.</p>
<h3 id="heading-what-is-justify-items-end-in-css-grid">What is <code>justify-items: end</code> in CSS Grid?</h3>
<p><code>end</code> positions a grid container's items with the row-end edge of their individual cells' row axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-items-end-illustration-codesweetly.png" alt="Illustration of justify-items' end value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-items' end value positions grid items to their individual cells' row-end edge</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">justify-items</span>: end;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-pcenzt?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>end</code> value to position the grid items to their individual cells' row-end edge.</p>
<h2 id="heading-what-is-css-grids-align-content-property">What Is CSS Grid's <code>align-content</code> Property?</h2>
<p><strong>align-content</strong> specifies how browsers should align a grid container's rows along the container's column axis.</p>
<p><strong>Note:</strong></p>
<ul>
<li><p>A column axis is sometimes called a block axis.</p>
</li>
<li><p>The <code>align-content</code> property works if the total row heights are less than the grid container's height. In other words, you need free space along the container's column axis to align its rows up or down.</p>
</li>
</ul>
<p>The <code>align-content</code> property accepts the following values:</p>
<ul>
<li><p><code>start</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>end</code></p>
</li>
<li><p><code>stretch</code></p>
</li>
<li><p><code>space-between</code></p>
</li>
<li><p><code>space-around</code></p>
</li>
<li><p><code>space-evenly</code></p>
</li>
</ul>
<p>Let's discuss these values.</p>
<h3 id="heading-what-is-align-content-start-in-css-grid">What is <code>align-content: start</code> in CSS Grid?</h3>
<p><code>start</code> aligns a grid container's rows with the column-start edge of the grid's column axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-content-start-illustration-codesweetly.png" alt="Illustration of align-content's start value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-content's start value aligns rows to the grid container's column-start edge</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">align-content</span>: start;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">300px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-cbmgr1?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>start</code> value to align the <code>&lt;section&gt;</code>'s rows to the grid container's column-start edge.</p>
<h3 id="heading-what-is-align-content-center-in-css-grid">What is <code>align-content: center</code> in CSS Grid?</h3>
<p><code>center</code> aligns a grid container's rows to the center of the grid's column axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-content-center-illustration-codesweetly.png" alt="Illustration of align-content's center value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-content's center value aligns rows to the center of the grid container</em></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">align-content</span>: center;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">300px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-83kj8v?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>center</code> value to align the <code>&lt;section&gt;</code>'s rows to the center of the grid container.</p>
<h3 id="heading-what-is-align-content-end-in-css-grid">What is <code>align-content: end</code> in CSS Grid?</h3>
<p><code>end</code> aligns a grid container's rows with the column-end edge of the grid's column axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-content-end-illustration-codesweetly.png" alt="Illustration of align-content's end value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-content's end value aligns rows to the grid container's column-end edge</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">align-content</span>: end;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">300px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-lc1lus?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>end</code> value to align the <code>&lt;section&gt;</code>'s rows to the grid container's column-end edge.</p>
<h3 id="heading-what-is-align-content-space-between-in-css-grid">What is <code>align-content: space-between</code> in CSS Grid?</h3>
<p><code>space-between</code> does the following:</p>
<ul>
<li><p>It aligns a grid container's first row with its column-start edge.</p>
</li>
<li><p>It aligns the container's last row with the column-end edge.</p>
</li>
<li><p>It creates even spacing between each pair of rows between the first and last row.</p>
</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-content-space-between-illustration-codesweetly.png" alt="Illustration of align-content's space-between value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-content's space-between value creates even spacing between each pair of rows between the first and last grid row</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">align-content</span>: space-between;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">300px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-ieqvih?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>space-between</code> value to create even spacing between each pair of rows between the first and last grid row.</p>
<h3 id="heading-what-is-align-content-space-around-in-css-grid">What is <code>align-content: space-around</code> in CSS Grid?</h3>
<p><code>space-around</code> assigns equal spacing to each side of a grid container's rows.</p>
<p>Therefore, the space before the first row and after the last one is half the width of the space between each pair of rows.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-content-space-around-illustration-codesweetly.png" alt="Illustration of align-content's space-around value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-content's space-around value assigns equal spacing to each side of the grid container's rows</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">align-content</span>: space-around;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">300px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-eyzta5?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>space-around</code> value to assign equal spacing to each side of the grid container's rows.</p>
<h3 id="heading-what-is-align-content-space-evenly-in-css-grid">What is <code>align-content: space-evenly</code> in CSS Grid?</h3>
<p><code>space-evenly</code> assigns even spacing to both ends of a grid container and between its rows.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-content-space-evenly-illustration-codesweetly.png" alt="Illustration of align-content's space-evenly value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-content's space-evenly value assigns even spacing to both ends of the grid container and between its rows</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">align-content</span>: space-evenly;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">300px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-il5vu1?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used the <code>space-evenly</code> value to assign even spacing to both ends of the grid container and between its rows.</p>
<h2 id="heading-what-is-css-grids-align-items-property">What Is CSS Grid's <code>align-items</code> Property?</h2>
<p><strong>align-items</strong> specifies the default <a target="_blank" href="https://codesweetly.com/css-grid-align-self-property"><code>align-self</code></a> value for all the grid items.</p>
<p>The <code>align-items</code> property accepts the following values:</p>
<ul>
<li><p><code>stretch</code></p>
</li>
<li><p><code>start</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>end</code></p>
</li>
</ul>
<p>Let's discuss the four values below.</p>
<h3 id="heading-what-is-align-items-stretch-in-css-grid">What is <code>align-items: stretch</code> in CSS Grid?</h3>
<p><code>stretch</code> is the default value for <code>align-items</code>. It stretches the grid container's items to fill their individual cells' column (block) axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-items-stretch-illustration-codesweetly.png" alt="Illustration of align-items' stretch value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-items' stretch value stretches grid items to fill their individual cells' column axis</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">align-items</span>: stretch;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">400px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-fia3ra?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>stretch</code> value to stretch the grid items to fill their individual cells' column axis.</p>
<h3 id="heading-what-is-align-items-start-in-css-grid">What is <code>align-items: start</code> in CSS Grid?</h3>
<p><code>start</code> aligns a grid container's items with the column-start edge of their individual cells' column axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-items-start-illustration-codesweetly.png" alt="Illustration of align-items' start value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-items' start value aligns grid items to their individual cells' column-start edge</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">align-items</span>: start;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">400px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-achetg?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>start</code> value to align the grid items to their individual cells' column-start edge.</p>
<h3 id="heading-what-is-align-items-center-in-css-grid">What is <code>align-items: center</code> in CSS Grid?</h3>
<p><code>center</code> aligns a grid container's items to the center of their individual cells' column axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-items-center-illustration-codesweetly.png" alt="Illustration of align-items' center value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-items' center value aligns grid items to their individual cells' center</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">align-items</span>: center;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">400px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-cmqydk?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>center</code> value to align the grid items to the center of their individual cells' column axis.</p>
<h3 id="heading-what-is-align-items-end-in-css-grid">What is <code>align-items: end</code> in CSS Grid?</h3>
<p><code>end</code> aligns a grid container's items with the column-end edge of their individual cells' column axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-items-end-illustration-codesweetly.png" alt="Illustration of align-items' end value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-items' end value aligns grid items to their individual cells' column-end edge</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">align-items</span>: end;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">400px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-jei1qv?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>end</code> value to align the grid items to their individual cells' column-end edge.</p>
<p>So, now that we know the types of CSS grid container properties, we can discuss the grid item properties.</p>
<h2 id="heading-what-are-the-grid-items-properties">What Are the Grid Item's Properties?</h2>
<p>A grid item's properties specify how browsers should layout a specified item within the grid box model.</p>
<p><strong>Note:</strong> We define a grid item's property on the item, not its container.</p>
<p>The ten (10) types of grid item properties are:</p>
<ul>
<li><p><code>justify-self</code></p>
</li>
<li><p><code>align-self</code></p>
</li>
<li><p><code>grid-column-start</code></p>
</li>
<li><p><code>grid-column-end</code></p>
</li>
<li><p><code>grid-column</code></p>
</li>
<li><p><code>grid-row-start</code></p>
</li>
<li><p><code>grid-row-end</code></p>
</li>
<li><p><code>grid-row</code></p>
</li>
<li><p><code>grid-area</code></p>
</li>
<li><p><code>grid-template-areas</code></p>
</li>
</ul>
<p>Let's discuss the ten types now.</p>
<h2 id="heading-what-is-css-grids-justify-self-property">What Is CSS Grid's <code>justify-self</code> Property?</h2>
<p><strong>justify-self</strong> specifies how browsers should position the selected grid item along its cell's row (inline) axis.</p>
<p>The <code>justify-self</code> property accepts the following values:</p>
<ul>
<li><p><code>stretch</code></p>
</li>
<li><p><code>start</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>end</code></p>
</li>
</ul>
<p>Let's discuss the four values.</p>
<h3 id="heading-what-is-justify-self-stretch-in-css-grid">What is <code>justify-self: stretch</code> in CSS Grid?</h3>
<p><code>stretch</code> is <code>justify-self</code>'s default value. It stretches the selected grid item to fill its cell's row (inline) axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-self-stretch-illustration-codesweetly.png" alt="Illustration of justify-self's stretch value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-self's stretch value stretches the selected grid item to fill its cell's row axis</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">justify-self</span>: stretch;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-82a3ep?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>stretch</code> value to stretch <code>grid-item1</code> to fill its cell's row axis.</p>
<h3 id="heading-what-is-justify-self-start-in-css-grid">What is <code>justify-self: start</code> in CSS Grid?</h3>
<p><code>start</code> positions the selected grid item with the row-start edge of its cell's row axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-self-start-illustration-codesweetly.png" alt="Illustration of justify-self's start value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-self's start value positions the selected grid item to its cell's row-start edge</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">justify-self</span>: start;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-cnz92l?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>start</code> value to position <code>grid-item1</code> to its cell's row-start edge.</p>
<h3 id="heading-what-is-justify-self-center-in-css-grid">What is <code>justify-self: center</code> in CSS Grid?</h3>
<p><code>center</code> positions the selected grid item to the center of its cell's row axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-self-center-illustration-codesweetly.png" alt="Illustration of justify-self's center value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-self's center value positions the selected grid item to its cell's center</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">justify-self</span>: center;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-9kspmx?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>center</code> value to position <code>grid-item1</code> to its cell's center.</p>
<h3 id="heading-what-is-justify-self-end-in-css-grid">What is <code>justify-self: end</code> in CSS Grid?</h3>
<p><code>end</code> positions the selected grid item with the row-end edge of its cell's row axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-self-end-illustration-codesweetly.png" alt="Illustration of justify-self's end value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-self's end value positions the selected grid item to its cell's row-end edge</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">justify-self</span>: end;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-xschhb?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>end</code> value to position <code>grid-item1</code> to its cell's row-end edge.</p>
<h2 id="heading-what-is-css-grids-align-self-property">What Is CSS Grid's <code>align-self</code> Property?</h2>
<p><strong>align-self</strong> specifies how browsers should align the selected grid item along its cell's column (block) axis.</p>
<p>The <code>align-self</code> property accepts the following values:</p>
<ul>
<li><p><code>stretch</code></p>
</li>
<li><p><code>start</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>end</code></p>
</li>
</ul>
<p>Let's discuss the four values below.</p>
<h3 id="heading-what-is-align-self-stretch-in-css-grid">What is <code>align-self: stretch</code> in CSS Grid?</h3>
<p><code>stretch</code> is <code>align-self</code>'s default value. It stretches the selected grid item to fill its cell's column (block) axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-self-stretch-illustration-codesweetly-1.png" alt="Illustration of align-self's stretch value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-self's stretch value stretches the selected grid item to fill its cell's column axis</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">align-self</span>: stretch;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-unnbb9?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>stretch</code> value to stretch <code>grid-item1</code> to fill its cell's column axis.</p>
<h3 id="heading-what-is-align-self-start-in-css-grid">What is <code>align-self: start</code> in CSS Grid?</h3>
<p><code>start</code> aligns the selected grid item with the column-start edge of its cell's column axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-self-start-illustration-codesweetly-1.png" alt="Illustration of align-self's start value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-self's start value aligns the selected grid item to its cell's column-start edge</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">align-self</span>: start;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-ytttz4?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>start</code> value to align <code>grid-item1</code> to its cell's column-start edge.</p>
<h3 id="heading-what-is-align-self-center-in-css-grid">What is <code>align-self: center</code> in CSS Grid?</h3>
<p><code>center</code> aligns the selected grid item to the center of its cell's column axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-self-center-illustration-codesweetly.png" alt="Illustration of align-self's center value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-self's center value aligns the selected grid item to its cell's center</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">align-self</span>: center;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-fpv4ed?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>center</code> value to align <code>grid-item1</code> to its cell's center.</p>
<h3 id="heading-what-is-align-self-end-in-css-grid">What is <code>align-self: end</code> in CSS Grid?</h3>
<p><code>end</code> aligns the selected grid item with the column-end edge of its cell's column axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-self-end-illustration-codesweetly.png" alt="Illustration of align-self's end value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-self's end value aligns the selected grid item to its cell's column-end edge</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">align-self</span>: end;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-vvmwzv?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>end</code> value to align grid-item1 to its cell's column-end edge.</p>
<h2 id="heading-what-is-css-grids-grid-column-start-property">What Is CSS Grid's <code>grid-column-start</code> Property?</h2>
<p><strong>grid-column-start</strong> specifies where the selected grid item should start (or span) along the grid container's row (inline) axis.</p>
<p>The <code>grid-column-start</code> property accepts the following values:</p>
<ul>
<li><p><code>auto</code></p>
</li>
<li><p><code>&lt;column-line-number&gt;</code></p>
</li>
<li><p><code>span &lt;number-of-columns&gt;</code></p>
</li>
</ul>
<h3 id="heading-example-1-how-to-auto-start-the-selected-grid-item-following-the-normal-column-flow">Example 1: How to auto-start the selected grid item following the normal column flow</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-column-start</span>: auto;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-rvhhxh?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>auto</code> value to auto-start <code>grid-item1</code> according to the normal column layout flow.</p>
<h3 id="heading-example-2-how-to-start-the-selected-grid-item-at-column-line-3">Example 2: How to start the selected grid item at column line 3</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-column-start</span>: <span class="hljs-number">3</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-ep6zgd?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-column-start</code> property to start <code>grid-item1</code> at <a target="_blank" href="https://codesweetly.com/css-grid-lines-explained">column line</a> 3.</p>
<h3 id="heading-example-3-how-to-span-the-selected-grid-item-across-two-columns">Example 3: How to span the selected grid item across two columns</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-column-start</span>: span <span class="hljs-number">2</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-w1nw8k?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>span 2</code> value to span <code>grid-item1</code> across two columns.</p>
<h2 id="heading-what-is-css-grids-grid-column-end-property">What Is CSS Grid's <code>grid-column-end</code> Property?</h2>
<p><strong>grid-column-end</strong> specifies where the selected grid item should end (or span) along the grid container's row (inline) axis.</p>
<p>The <code>grid-column-end</code> property accepts the following values:</p>
<ul>
<li><p><code>auto</code></p>
</li>
<li><p><code>&lt;column-line-number&gt;</code></p>
</li>
<li><p><code>span &lt;number-of-columns&gt;</code></p>
</li>
</ul>
<h3 id="heading-example-1-how-to-auto-end-the-selected-grid-item-following-the-normal-column-flow">Example 1: How to auto-end the selected grid item following the normal column flow</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-column-end</span>: auto;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-1mmxhp?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>auto</code> value to auto-end <code>grid-item1</code> according to the normal layout flow.</p>
<h3 id="heading-example-2-how-to-end-the-selected-grid-item-at-column-line-3">Example 2: How to end the selected grid item at column line 3</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-column-start</span>: <span class="hljs-number">1</span>;
  <span class="hljs-attribute">grid-column-end</span>: <span class="hljs-number">3</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-hjcfhc?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-column-end</code> property to end <code>grid-item1</code> at <a target="_blank" href="https://codesweetly.com/css-grid-lines-explained">column line</a> 3.</p>
<h3 id="heading-example-3-how-to-span-the-selected-grid-item-across-two-columns-1">Example 3: How to span the selected grid item across two columns</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-column-start</span>: <span class="hljs-number">2</span>;
  <span class="hljs-attribute">grid-column-end</span>: span <span class="hljs-number">2</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-yhe3ew?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>span 2</code> value to span <code>grid-item1</code> across two columns.</p>
<h2 id="heading-what-is-css-grids-grid-column-property">What Is CSS Grid's <code>grid-column</code> Property?</h2>
<p><strong>grid-column</strong> is a shorthand for the <code>grid-column-start</code> and <code>grid-column-end</code> properties.</p>
<p>In other words, instead of writing:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-column-start</span>: <span class="hljs-number">1</span>;
  <span class="hljs-attribute">grid-column-end</span>: <span class="hljs-number">3</span>;
}
</code></pre>
<p>You can alternatively use the <code>grid-column</code> property to shorten your code like so:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">1</span> / <span class="hljs-number">3</span>;
}
</code></pre>
<p><strong>Here is grid-column's syntax:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-column</span>: <span class="hljs-selector-tag">grid-column-start</span> / <span class="hljs-selector-tag">grid-column-end</span>;
</code></pre>
<h2 id="heading-what-is-css-grids-grid-row-start-property">What Is CSS Grid's <code>grid-row-start</code> Property?</h2>
<p><strong>grid-row-start</strong> specifies where the selected grid item should start (or span) along the grid container's column (block) axis.</p>
<p>The <code>grid-row-start</code> property accepts the following values:</p>
<ul>
<li><p><code>auto</code></p>
</li>
<li><p><code>&lt;row-line-number&gt;</code></p>
</li>
<li><p><code>span &lt;number-of-rows&gt;</code></p>
</li>
</ul>
<h3 id="heading-example-1-how-to-auto-start-the-selected-grid-item-following-the-normal-row-flow">Example 1: How to auto-start the selected grid item following the normal row flow</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-row-start</span>: auto;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-qthpn6?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>auto</code> value to auto-start <code>grid-item1</code> according to the normal row layout flow.</p>
<h3 id="heading-example-2-how-to-start-the-selected-grid-item-at-row-line-3">Example 2: How to start the selected grid item at row line 3</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-row-start</span>: <span class="hljs-number">3</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-phrjcb?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-row-start</code> property to start <code>grid-item1</code> at <a target="_blank" href="https://codesweetly.com/css-grid-lines-explained">row line</a> 3.</p>
<h3 id="heading-example-3-how-to-span-the-selected-grid-item-across-two-rows">Example 3: How to span the selected grid item across two rows</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-row-start</span>: span <span class="hljs-number">2</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-5bchie?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>span 2</code> value to span <code>grid-item1</code> across two rows.</p>
<h2 id="heading-what-is-css-grids-grid-row-end-property">What Is CSS Grid's <code>grid-row-end</code> Property?</h2>
<p><strong>grid-row-end</strong> specifies where the selected grid item should end (or span) along the grid container's column (block) axis.</p>
<p>The <code>grid-row-end</code> property accepts the following values:</p>
<ul>
<li><p><code>auto</code></p>
</li>
<li><p><code>&lt;column-line-number&gt;</code></p>
</li>
<li><p><code>span &lt;number-of-columns&gt;</code></p>
</li>
</ul>
<h3 id="heading-example-1-how-to-auto-end-the-selected-grid-item-following-the-normal-row-flow">Example 1: How to auto-end the selected grid item following the normal row flow</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-row-end</span>: auto;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-w1rpy8?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>auto</code> value to auto-end <code>grid-item1</code> according to the normal row layout flow.</p>
<h3 id="heading-example-2-how-to-end-the-selected-grid-item-at-row-line-5">Example 2: How to end the selected grid item at row line 5</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-row-start</span>: <span class="hljs-number">1</span>;
  <span class="hljs-attribute">grid-row-end</span>: <span class="hljs-number">5</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-wps8a3?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-row-end</code> property to end <code>grid-item1</code> at <a target="_blank" href="https://codesweetly.com/css-grid-lines-explained">row line</a> 5.</p>
<h3 id="heading-example-3-how-to-span-the-selected-grid-item-across-three-rows">Example 3: How to span the selected grid item across three rows</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-row-end</span>: span <span class="hljs-number">3</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-skcbxf?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>span 3</code> value to span <code>grid-item1</code> across three rows.</p>
<h2 id="heading-what-is-css-grids-grid-row-property">What Is CSS Grid's <code>grid-row</code> Property?</h2>
<p><strong>grid-row</strong> is a shorthand for the <code>grid-row-start</code> and <code>grid-row-end</code> properties.</p>
<p>In other words, instead of writing:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-row-start</span>: <span class="hljs-number">1</span>;
  <span class="hljs-attribute">grid-row-end</span>: <span class="hljs-number">5</span>;
}
</code></pre>
<p>You can alternatively use the <code>grid-row</code> property to shorten your code like so:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-row</span>: <span class="hljs-number">1</span> / <span class="hljs-number">5</span>;
}
</code></pre>
<p><strong>Here is grid-row's syntax:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-row</span>: <span class="hljs-selector-tag">grid-row-start</span> / <span class="hljs-selector-tag">grid-row-end</span>;
</code></pre>
<h2 id="heading-what-is-css-grids-grid-area-property">What Is CSS Grid's <code>grid-area</code> Property?</h2>
<p>You can use the <strong>grid-area</strong> property for the following purposes:</p>
<ol>
<li><p>As a shorthand for the <code>grid-column-start</code>, <code>grid-column-end</code>, <code>grid-row-start</code>, and <code>grid-row-end</code> properties.</p>
</li>
<li><p>To specify a grid item's name.</p>
</li>
</ol>
<p>Let's discuss the two purposes below.</p>
<h3 id="heading-how-to-use-grid-area-as-a-shorthand">How to use <code>grid-area</code> as a shorthand</h3>
<p>Here is the syntax for using the <code>grid-area</code> property as a shorthand for the <code>grid-column-start</code>, <code>grid-column-end</code>, <code>grid-row-start</code>, and <code>grid-row-end</code> properties:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.your-grid-item</span> {
  <span class="hljs-attribute">grid-area</span>: grid-row-start / grid-column-start / grid-row-end / grid-column-end;
}
</code></pre>
<p>Therefore, instead of writing:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-row-start</span>: <span class="hljs-number">3</span>;
  <span class="hljs-attribute">grid-row-end</span>: <span class="hljs-number">5</span>;
  <span class="hljs-attribute">grid-column-start</span>: <span class="hljs-number">1</span>;
  <span class="hljs-attribute">grid-column-end</span>: span <span class="hljs-number">2</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-sqkxmk?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>You can alternatively use the <code>grid-area</code> property to shorten your code like so:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-area</span>: <span class="hljs-number">3</span> / <span class="hljs-number">1</span> / <span class="hljs-number">5</span> / span <span class="hljs-number">2</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-42swnh?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<h3 id="heading-how-to-use-grid-area-to-specify-a-grid-items-name">How to use <code>grid-area</code> to specify a grid item's name</h3>
<p>Here is the syntax for using the <code>grid-area</code> property to specify a grid item's name:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.your-grid-item</span> {
  <span class="hljs-attribute">grid-area</span>: item-name;
}
</code></pre>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-area</span>: firstDiv;
}

<span class="hljs-selector-class">.grid-item2</span> {
  <span class="hljs-attribute">grid-area</span>: middleDiv;
}

<span class="hljs-selector-class">.grid-item2</span> {
  <span class="hljs-attribute">grid-area</span>: lastDiv;
}
</code></pre>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">section</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"grid-item1"</span>&gt;</span>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">"grid-item2"</span>&gt;</span>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">"grid-item3"</span>&gt;</span>3<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
</code></pre>
<p>Using <code>grid-area</code> to define a named grid item allows your grid container's <code>grid-template-areas</code> property to use the name to set the item's size and location.</p>
<h2 id="heading-what-is-css-grids-grid-template-areas-property">What Is CSS Grid's <code>grid-template-areas</code> Property?</h2>
<p><strong>grid-template-areas</strong> specifies the area where you want to place <em>named grid items</em> within a grid container.</p>
<p><strong>Remember:</strong> We use the CSS <code>[grid-area](#heading-how-to-use-grid-area-to-specify-a-grid-items-name)</code> property to name grid items.</p>
<h3 id="heading-example-1-how-to-place-a-named-grid-item-across-three-columns">Example 1: How to place a named grid item across three columns</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-area</span>: firstDiv;
}

<span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-areas</span>: <span class="hljs-string">"firstDiv firstDiv firstDiv . ."</span>;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">50px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-1sw8ww?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-template-areas</code> property to place <code>grid-item1</code> across the first three column areas.</p>
<p><strong>Note the following:</strong></p>
<ul>
<li><p>Quotation marks (<code>""</code>) define each grid row.</p>
</li>
<li><p>A period symbol (<code>.</code>) defines an unnamed grid item.</p>
</li>
<li><p>We used the whitespace character to separate grid columns.</p>
</li>
</ul>
<h3 id="heading-example-2-how-to-specify-multiple-named-grid-items-placements">Example 2: How to specify multiple named grid items' placements</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-area</span>: header;
}

<span class="hljs-selector-class">.grid-item2</span> {
  <span class="hljs-attribute">grid-area</span>: article;
}

<span class="hljs-selector-class">.grid-item3</span> {
  <span class="hljs-attribute">grid-area</span>: footer;
}

<span class="hljs-selector-class">.grid-item4</span> {
  <span class="hljs-attribute">grid-area</span>: sidebar;
}

<span class="hljs-selector-class">.grid-item5</span> {
  <span class="hljs-attribute">grid-area</span>: ads1;
}

<span class="hljs-selector-class">.grid-item6</span> {
  <span class="hljs-attribute">grid-area</span>: ads2;
}

<span class="hljs-selector-class">.grid-item7</span> {
  <span class="hljs-attribute">grid-area</span>: ads3;
}

<span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">5</span>, <span class="hljs-number">1</span>fr);
  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">7</span>, <span class="hljs-number">1</span>fr);
  <span class="hljs-attribute">grid-template-areas</span>:
    <span class="hljs-string">"header header header header header"</span>
    <span class="hljs-string">"sidebar article article article ads1"</span>
    <span class="hljs-string">"sidebar article article article ads1"</span>
    <span class="hljs-string">"sidebar article article article ads1"</span>
    <span class="hljs-string">"sidebar article article article ads2"</span>
    <span class="hljs-string">"sidebar article article article ads3"</span>
    <span class="hljs-string">"sidebar footer footer footer footer"</span>;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">30px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-9b5emj?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-template-areas</code> property to specify where browsers should place the grid items across the rows and columns of the grid container.</p>
<h3 id="heading-important-stuff-to-know-about-the-grid-template-areas-property">Important Stuff to Know about the <code>grid-template-areas</code> Property</h3>
<p>Here are four essential facts to remember when using the <code>grid-template-areas</code> property:</p>
<h4 id="heading-1-grid-template-areas-do-not-permit-empty-cells">1. <code>grid-template-areas</code> do not permit empty cells</h4>
<p>The <code>grid-template-areas</code> property requires you to provide an item for all grid cells.</p>
<p>For instance, consider this snippet:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-areas</span>:
  "<span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads2</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads3</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">footer</span>";
</code></pre>
<p>Above is an invalid <code>grid-template-areas</code> value because the first row is incomplete.</p>
<p>In other words, the first row is the only one with two columns. However, <code>grid-template-areas</code> expect all the rows in a grid container to have the same number of columns.</p>
<h4 id="heading-2-you-can-use-dots-to-specify-empty-cells">2. You can use dots to specify empty cells</h4>
<p>Suppose you wish to leave some cells empty. In that case, use a dot (<code>.</code>) or multiple unspaced dots (<code>....</code>).</p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-areas</span>:
  "<span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> . . ."
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads2</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads3</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">footer</span>";
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-yfhx4g?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the three <em>spaced</em> dot (<code>.</code>) symbols to indicate three empty cells.</p>
<h4 id="heading-3-grid-template-areas-do-not-permit-placing-an-item-in-multiple-locations">3. <code>grid-template-areas</code> do not permit placing an item in multiple locations</h4>
<p>The <code>grid-template-areas</code> property cannot place items twice within a grid container.</p>
<p>For instance, consider this snippet:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-areas</span>:
  "<span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads2</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads3</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span>";
</code></pre>
<p>Above is an invalid <code>grid-template-areas</code> value because the <code>header</code> item occupies two grid areas.</p>
<h4 id="heading-4-grid-template-areas-allows-rectangular-areas-only">4. <code>grid-template-areas</code> allows rectangular areas only</h4>
<p>The <code>grid-template-areas</code> property cannot create non-rectangular areas (such as T-shaped or L-shaped).</p>
<p>For instance, consider this snippet:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-areas</span>:
  "<span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">ads1</span> <span class="hljs-selector-tag">ads1</span> <span class="hljs-selector-tag">ads1</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads2</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads3</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">footer</span>";
</code></pre>
<p>Above is an invalid <code>grid-template-areas</code> value because the <code>ads1</code> item creates a non-rectangular grid area.</p>
<p>So, now that we know the types of CSS grid item properties, we can discuss how to define minimum and maximum grid sizes.</p>
<h2 id="heading-how-to-use-the-css-minmax-function-to-define-minimum-and-maximum-grid-sizes">How to Use the CSS <code>minmax()</code> function to Define Minimum and Maximum Grid Sizes</h2>
<p><strong>minmax()</strong> is a CSS Grid function for defining minimum and maximum grid sizes.</p>
<h3 id="heading-syntax-of-the-css-minmax-function">Syntax of the CSS <code>minmax()</code> function</h3>
<p><code>minmax()</code> accepts two arguments. Here is the syntax:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">minmax</span>(<span class="hljs-selector-tag">minimum-size</span>, <span class="hljs-selector-tag">maximum-size</span>)
</code></pre>
<p><strong>Note the following:</strong></p>
<ul>
<li><p>The <code>minimum-size</code> argument specifies the smallest size for a specific length.</p>
</li>
<li><p>The <code>maximum-size</code> argument specifies the largest size for a specific length.</p>
</li>
<li><p><code>minmax()</code>'s arguments can be any of the non-negative <a target="_blank" href="https://codesweetly.com/css-unit">CSS lengths</a>, or any one of the keywords <code>auto</code>, <code>min-content</code>, or <code>max-content</code>.</p>
</li>
<li><p>Suppose the <code>maximum-size</code> argument is less than the <code>minimum-size</code>. In that case, browsers will ignore the <code>maximum-size</code> and treat the <code>minmax()</code> function as <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/min"><code>min()</code></a>.</p>
</li>
<li><p>An <a target="_blank" href="https://codesweetly.com/css-unit#fraction-fr"><code>fr</code> unit</a> is an _in_valid unit for the <code>minimum-size</code> argument.</p>
</li>
</ul>
<h3 id="heading-how-to-use-the-css-minmax-function">How to use the CSS <code>minmax()</code> function</h3>
<p>You can use the <code>minmax()</code> function as a value for the following CSS properties:</p>
<ul>
<li><p><code>grid-template-columns</code></p>
</li>
<li><p><code>grid-template-rows</code></p>
</li>
<li><p><code>grid-auto-columns</code></p>
</li>
<li><p><code>grid-auto-rows</code></p>
</li>
</ul>
<h3 id="heading-examples-of-the-css-minmax-function">Examples of the CSS <code>minmax()</code> function</h3>
<p>Below are examples of how the CSS <code>minmax()</code> function works.</p>
<h4 id="heading-how-to-define-a-70px-minimum-and-a-250px-maximum-row-grid-size">How to define a <code>70px</code> minimum and a <code>250px</code> maximum row grid size</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-number">50px</span> <span class="hljs-number">100px</span> <span class="hljs-built_in">minmax</span>(<span class="hljs-number">70px</span>, <span class="hljs-number">250px</span>);
  <span class="hljs-attribute">grid-template-columns</span>: auto auto auto;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-giarya?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used the CSS <code>minmax()</code> function to set the <code>&lt;section&gt;</code>'s third row's height to a minimum of <code>70px</code> and a maximum of <code>250px</code>.</p>
<h4 id="heading-how-to-define-a-30-minimum-and-a-70-maximum-column-grid-size">How to define a <code>30%</code> minimum and a <code>70%</code> maximum column grid size</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-rows</span>: auto auto auto;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-built_in">minmax</span>(<span class="hljs-number">30%</span>, <span class="hljs-number">70%</span>) <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-ekn23p?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used the CSS <code>minmax()</code> function to set the <code>&lt;section&gt;</code>'s second column's width to a minimum of <code>30%</code> and a maximum of <code>70%</code>.</p>
<p><strong>Note:</strong> You can use the CSS <code>repeat()</code> function to specify <code>grid-template-rows</code> or <code>grid-template-columns</code> values with repeated patterns. Let's discuss the <code>repeat()</code> function now.</p>
<h2 id="heading-how-to-use-the-css-repeat-function-to-define-grid-tracks-with-repeated-patterns">How to Use the CSS <code>repeat()</code> Function to Define Grid Tracks with Repeated Patterns</h2>
<p>The <strong>repeat()</strong> CSS function allows you to write more concise and readable values when specifying multiple <a target="_blank" href="https://codesweetly.com/css-grid-lines-explained">grid tracks</a> with repeated patterns.</p>
<p><strong>Note:</strong></p>
<ul>
<li><p>A track refers to a grid container's column (or row).</p>
</li>
<li><p>You can use <code>repeat()</code> as a value for the CSS <code>grid-template-columns</code> or <code>grid-template-rows</code> properties.</p>
</li>
</ul>
<h3 id="heading-syntax-of-the-css-repeat-function">Syntax of the CSS <code>repeat()</code> function</h3>
<p><code>repeat()</code> accepts two arguments. Here is the syntax:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">repeat</span>(<span class="hljs-selector-tag">number-of-repetition</span>, <span class="hljs-selector-tag">track-list-to-repeat</span>)
</code></pre>
<h3 id="heading-argument-1-number-of-repetition">Argument 1: <code>number-of-repetition</code></h3>
<p>The <code>number-of-repetition</code> argument specifies the number of times browsers should repeat the specified track list (the second argument).</p>
<p>The <code>number-of-repetition</code> argument can be any of the following values:</p>
<ul>
<li><p>Number <code>1</code> or its multiple</p>
</li>
<li><p><code>auto-fill</code></p>
</li>
<li><p><code>auto-fit</code></p>
</li>
</ul>
<h4 id="heading-auto-fill-vs-auto-fit-whats-the-difference"><code>auto-fill</code> vs. <code>auto-fit</code>: What's the difference?</h4>
<p>The <code>auto-fill</code> and <code>auto-fit</code> values automatically create as many tracks as needed to fill a grid container without causing an overflow.</p>
<p>The difference between the two values is that <code>auto-fit</code> collapses empty tracks to zero-pixel (<code>0px</code>). But <code>auto-fill</code> displays both empty and filled tracks.</p>
<p><strong>Note:</strong> Empty tracks are columns or rows with no grid item.</p>
<h3 id="heading-argument-2-track-list-to-repeat">Argument 2: <code>track-list-to-repeat</code></h3>
<p>The <code>track-list-to-repeat</code> argument specifies the track pattern you wish to repeat across a grid container's horizontal or vertical axis.</p>
<p>In other words, <code>track-list-to-repeat</code> consists of one or more values specifying the sizes of tracks browsers should repeat within a grid container.</p>
<p><strong>Note:</strong> Suppose your <code>number-of-repetition</code> is <code>auto-fill</code> or <code>auto-fit</code>. In that case, you can use only <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/repeat#fixed-size">fixed sizes</a> as the <code>track-list-to-repeat</code> argument.</p>
<h3 id="heading-examples-of-the-css-repeat-function">Examples of the CSS <code>repeat()</code> function</h3>
<p>Below are examples of how the CSS <code>repeat()</code> function works.</p>
<h4 id="heading-how-to-create-a-three-column-grid-container-with-70px-column-widths">How to create a three-column grid container with <code>70px</code> column-widths</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">3</span>, <span class="hljs-number">70px</span>);
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-imfqcm?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the CSS <code>repeat()</code> function to create three <code>70px</code>-wide columns.</p>
<p>Below is the non-<code>repeat()</code> equivalent of the above <code>grid-template-columns</code> property:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-columns</span>: 70<span class="hljs-selector-tag">px</span> 70<span class="hljs-selector-tag">px</span> 70<span class="hljs-selector-tag">px</span>;
</code></pre>
<h4 id="heading-how-to-create-a-four-column-grid-container-with-one-50px-and-three-90px-column-widths">How to create a four-column grid container with one <code>50px</code> and three <code>90px</code> column-widths</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">50px</span> <span class="hljs-built_in">repeat</span>(<span class="hljs-number">3</span>, <span class="hljs-number">90px</span>);
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-bgdk3a?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the CSS <code>repeat()</code> function to create three <code>90px</code>-wide columns.</p>
<p>Below is the non-<code>repeat()</code> equivalent of the above <code>grid-template-columns</code> property:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-columns</span>: 50<span class="hljs-selector-tag">px</span> 90<span class="hljs-selector-tag">px</span> 90<span class="hljs-selector-tag">px</span> 90<span class="hljs-selector-tag">px</span>;
</code></pre>
<h4 id="heading-how-to-create-a-five-column-grid-container-with-one-40px-and-two-60px-1fr-column-widths">How to create a five-column grid container with one <code>40px</code> and two <code>60px 1fr</code> column-widths</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">40px</span> <span class="hljs-built_in">repeat</span>(<span class="hljs-number">2</span>, <span class="hljs-number">60px</span> <span class="hljs-number">1</span>fr);
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-wjgjym?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the CSS <code>repeat()</code> function to create two <code>60px 1fr</code>-wide columns.</p>
<p>Below is the non-<code>repeat()</code> equivalent of the above <code>grid-template-columns</code> property:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-columns</span>: 40<span class="hljs-selector-tag">px</span> 60<span class="hljs-selector-tag">px</span> 1<span class="hljs-selector-tag">fr</span> 60<span class="hljs-selector-tag">px</span> 1<span class="hljs-selector-tag">fr</span>;
</code></pre>
<p><strong>Note:</strong> We used the <a target="_blank" href="https://codesweetly.com/css-unit#fraction-fr"><code>fr</code> (fraction) unit</a> to scale the third and fifth columns relative to the fraction of available space in the grid container.</p>
<h4 id="heading-how-to-auto-fill-the-grid-container-with-70px-wide-columns">How to auto-fill the grid container with <code>70px</code>-wide columns</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(auto-fill, <span class="hljs-number">70px</span>);
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-bwdeeb?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the CSS <code>repeat()</code> function to automatically fill the grid container with <code>70px</code>-wide columns.</p>
<h4 id="heading-how-to-auto-fill-the-grid-container-with-a-minimum-of-50px-and-a-maximum-of-1fr-wide-columns">How to auto-fill the grid container with a minimum of <code>50px</code> and a maximum of <code>1fr</code> wide columns</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(auto-fill, minmax(<span class="hljs-number">50px</span>, <span class="hljs-number">1</span>fr));
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-hrof4i?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the CSS <code>repeat()</code> and <code>minmax()</code> functions to automatically fill the grid container with a minimum of <code>50px</code>-wide columns and a maximum of <code>1fr</code>.</p>
<p><strong>Note:</strong> <code>1fr</code> means one <a target="_blank" href="https://codesweetly.com/css-unit#fraction-fr">fraction unit</a>.</p>
<h4 id="heading-how-to-auto-fit-the-grid-container-with-a-minimum-of-50px-and-a-maximum-of-1fr-wide-columns">How to auto-fit the grid container with a minimum of <code>50px</code> and a maximum of <code>1fr</code> wide columns</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(auto-fit, minmax(<span class="hljs-number">50px</span>, <span class="hljs-number">1</span>fr));
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-pveewm?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>CSS repeat()</code> and <code>minmax()</code> functions to automatically fit the grid container with a minimum of <code>50px</code>-wide columns and a maximum of <code>1fr</code>.</p>
<h2 id="heading-overview">Overview</h2>
<p>In this article, we discussed all the CSS Grid tools you need to create basic and advanced website layouts in responsive ways that look great on all devices.</p>
<p>I hope you've found this article helpful.</p>
<h3 id="heading-thanks-for-reading">Thanks for reading!</h3>
<p>If you like this tutorial, you can <a target="_blank" href="https://amzn.to/42s5KXZ">get the guidebook version at Amazon</a>. It is a handy quick reference guide to CSS Grid.</p>
<p><a target="_blank" href="https://amzn.to/42s5KXZ"><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-book-codesweetly.png" alt="Buy the CSS Grid Guidebook at Amazon" width="600" height="400" loading="lazy"></a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ React Native Tutorial – How to Create a Simple Responsive Layout for Beginners ]]>
                </title>
                <description>
                    <![CDATA[ Having a responsive layout is an important component of user interface (UI) design. It enables a website or application to automatically adjust its size and layout based on the size of the user's device and screen. This provides an optimal viewing ex... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/responsive-layout-react-native/</link>
                <guid isPermaLink="false">66d4619837bd2215d1e24608</guid>
                
                    <category>
                        <![CDATA[ React Native ]]>
                    </category>
                
                    <category>
                        <![CDATA[ responsive design ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Kingsley Ubah ]]>
                </dc:creator>
                <pubDate>Thu, 02 Feb 2023 23:50:26 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/02/pexels-luna-lovegood-4087468.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Having a responsive layout is an important component of user interface (UI) design. It enables a website or application to automatically adjust its size and layout based on the size of the user's device and screen. This provides an optimal viewing experience.</p>
<p>Responsive layouts also give the user a more consistent and unified look across all devices and platforms, while still making sure the user's experience is tailored to their device.</p>
<p>This helps create a more user-friendly experience and improves the overall usability of the website or application.</p>
<p>In this tutorial, I'll show you how to create a simple responsive layout in React Native. You can preview the demo <a target="_blank" href="https://snack.expo.dev/@ubahthebuilder/67d71a">here</a>.</p>
<h2 id="heading-requirements">Requirements</h2>
<p>To follow this tutorial, you'll need:</p>
<ul>
<li><p>A basic understanding of React Native</p>
</li>
<li><p><a target="_blank" href="https://snack.expo.dev/">Expo Snack</a> – a browser-based development environment for React Native</p>
</li>
</ul>
<h2 id="heading-how-to-create-a-responsive-layout">How to Create a Responsive Layout</h2>
<p>Go to Expo Snack and clear the content of App.js. Start by importing the React library and Text, View, and Stylesheet UI components:</p>
<pre><code class="lang-c"><span class="hljs-keyword">import</span> * as React from <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { Text, View, StyleSheet } from <span class="hljs-string">'react-native'</span>;
</code></pre>
<p>React Native is based on React, so we need to import the React library explicitly. The Text component is used to create text, View is a container element used for grouping other elements, and StyleSheet is used to define the components stylesheet.</p>
<p>Next, define an App function and return two custom components, <code>&lt;Header /&gt;</code> and <code>&lt;Footer /&gt;</code>:</p>
<pre><code class="lang-c"><span class="hljs-function"><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> function <span class="hljs-title">App</span><span class="hljs-params">()</span> </span>{
  <span class="hljs-keyword">return</span> (
    &lt;View style={styles.container}&gt;
      &lt;Header /&gt;
      &lt;Boxes /&gt;
    &lt;/View&gt;
  );
}
</code></pre>
<p>Here we wrap <code>&lt;Header /&gt;</code> and <code>&lt;Footer /&gt;</code> inside a <code>&lt;View /&gt;</code> container. Both of them are custom components, and because they haven't been created yet, you'll get a ReferenceError. Ignore that for now.</p>
<p>Next, create the stylesheet for this component and define the styling for the container element:</p>
<pre><code class="lang-c"><span class="hljs-keyword">const</span> styles = StyleSheet.create({
  container: {
    flex: <span class="hljs-number">1</span>,   
  },  
});
</code></pre>
<p>This <code>flex:1</code> value tells the component to fill all available space and to share the space evenly amongst its children.</p>
<p>Let's now create both the <code>&lt;Header&gt;</code> and <code>&lt;Boxes/&gt;</code> components.</p>
<h2 id="heading-how-to-create-the-component">How to Create the <code>&lt;Header /&gt;</code> Component</h2>
<p>In the components folder, create a new file named Header.js. Then import both the following:</p>
<pre><code class="lang-c"><span class="hljs-keyword">import</span> * as React from <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { Text, View, StyleSheet} from <span class="hljs-string">'react-native'</span>;
</code></pre>
<p>Create a <code>&lt;Header /&gt;</code> function and return a single <code>&lt;View /&gt;</code> with text saying "Header Component":</p>
<pre><code class="lang-c"><span class="hljs-function"><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> function <span class="hljs-title">Header</span><span class="hljs-params">()</span> </span>{
  <span class="hljs-keyword">return</span> (
    &lt;View style={styles.header}&gt;
      &lt;Text&gt;Header Component&lt;/Text&gt;
    &lt;/View&gt;
  );
}
</code></pre>
<p>The <code>&lt;View /&gt;</code> is linked to a <code>style</code> property of <code>header</code>. Keep in mind that we want to make this header responsive on all screen sizes. Let's do that using CSS.</p>
<pre><code class="lang-c"><span class="hljs-keyword">const</span> styles = StyleSheet.create({
  header: {
    width: <span class="hljs-string">"100%"</span>,
    height: <span class="hljs-string">"15%"</span>,
    alignItems: <span class="hljs-string">'center'</span>,
    justifyContent: <span class="hljs-string">'center'</span>,
    backgroundColor: <span class="hljs-string">'grey'</span>    
  },
});
</code></pre>
<p>With this stylesheet, we're specifying that, no matter how big or small the screen, the header should span the whole width of the screen (100%) and take only 15% of the screen's height.</p>
<p>Now to the boxes.</p>
<h2 id="heading-how-to-create-the-component-1">How to Create the <code>&lt;Boxes /&gt;</code> Component</h2>
<p>Below the header we want to place two boxes, one to the left and one to the right. We also want the boxes to take up a certain width and height based on the screen dimension of the target device.</p>
<p>Inside the components folder, create a new file named boxes.js. Start by importing the following:</p>
<pre><code class="lang-c"><span class="hljs-keyword">import</span> * as React from <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { Text, View, StyleSheet} from <span class="hljs-string">'react-native'</span>;
</code></pre>
<p>Next, create a Boxes function and return the markup for the boxes:</p>
<pre><code class="lang-c"><span class="hljs-function"><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> function <span class="hljs-title">Boxes</span><span class="hljs-params">()</span> </span>{
  <span class="hljs-keyword">return</span> (
    &lt;View style={styles.container}&gt;
      &lt;View style={styles.box}&gt;
        &lt;View style={styles.inner}&gt;
          &lt;Text&gt;Box <span class="hljs-number">1</span>&lt;/Text&gt;
        &lt;/View&gt;                      
      &lt;/View&gt;
      &lt;View style={styles.box}&gt;
        &lt;View style={styles.inner}&gt;
          &lt;Text&gt;Box <span class="hljs-number">2</span>&lt;/Text&gt;
        &lt;/View&gt;                      
      &lt;/View&gt;
    &lt;/View&gt;
  );
}
</code></pre>
<p>Here we have two boxes placed inside the container. Inside both is a View element containing the text label for each box.</p>
<p>Next, define the styling for the component. We'll create three sets of styles, one for the box container, one for the inner wrapper and the last for the boxes themselves.</p>
<pre><code class="lang-c"><span class="hljs-keyword">const</span> styles = StyleSheet.create({
  container: {
    width: <span class="hljs-string">"100%"</span>,
    height: <span class="hljs-string">"85%"</span>,
    alignItems: <span class="hljs-string">"center"</span>,
    flexDirection: <span class="hljs-string">'row'</span>,
    flexWrap: <span class="hljs-string">'wrap'</span>    
  },
  box: {
    width: <span class="hljs-string">"50%"</span>,
    height: <span class="hljs-string">"50%"</span>,
    padding: <span class="hljs-number">5</span>
  },
  inner: {
    flex: <span class="hljs-number">1</span>,
    backgroundColor: <span class="hljs-string">"#D3D3D3"</span>,
    alignItems: <span class="hljs-string">'center'</span>,
    justifyContent: <span class="hljs-string">'center'</span>
  }
});
</code></pre>
<p>Recall that the header takes up 15% of the screen's height. Therefore, with the above CSS, we specify that the box container should take up the remaining 85%.</p>
<p>We align the boxes to the center and place them in a row arrangement. Each box takes up 50% of the total height and width, and we apply padding of 5 to space them a bit.</p>
<p>Now that we have both the responsive Header and Boxes ready, let's import them to App.js and see the results.</p>
<h2 id="heading-how-to-import-and">How to Import <code>&lt;Header /&gt;</code> and <code>&lt;Boxes /&gt;</code></h2>
<p>Inside App.js, at the top of the file, import both <code>&lt;Header /&gt;</code> and <code>&lt;Boxes /&gt;</code> like so:</p>
<pre><code class="lang-c"><span class="hljs-keyword">import</span> Header from <span class="hljs-string">"./components/Header"</span>
<span class="hljs-keyword">import</span> Boxes from <span class="hljs-string">"./components/Boxes"</span>
</code></pre>
<p>Once the app compiles, you should see your responsive layout on the right side of your window looking like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/01/UI.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Final look of responsive layout</em></p>
<p>This arrangement will be consistent across all screen sizes because we used percentages to set the height and width instead of fixed width values.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>I hope this tutorial helped you understand React Native positioning better. You should now be able to create responsive layouts in your React Native app using the techniques we covered in this post.</p>
<p>Grab my FREE freelance writing checklist <a target="_blank" href="https://kingchuks.gumroad.com/l/fwc">here</a>. Have a great week!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Learn CSS – Responsive Web Design Study Guide ]]>
                </title>
                <description>
                    <![CDATA[ Cascading Style Sheets (CSS) represents the design for a web page. But when you are learning this information for the first time, it can be hard to keep track of all of the different CSS properties. In this article, I have created a study guide for t... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-css/</link>
                <guid isPermaLink="false">66b8d9f16b74ac70ba21e6c7</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ freeCodeCamp.org ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ responsive design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Jessica Wilkins ]]>
                </dc:creator>
                <pubDate>Mon, 07 Nov 2022 18:24:20 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/07/kobu-agency-ipARHaxETRk-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Cascading Style Sheets (CSS) represents the design for a web page. But when you are learning this information for the first time, it can be hard to keep track of all of the different CSS properties.</p>
<p>In this article, I have created a study guide for the freeCodeCamp curriculum's entire <a target="_blank" href="https://www.freecodecamp.org/learn/2022/responsive-web-design/#learn-basic-css-by-building-a-cafe-menu">Learn Basic CSS by Building a Cafe Menu practice project</a>. This study guide is filled with additional information, articles, and videos to help you understand the concepts better.</p>
<p>Feel free to reference this guide as you go through the certification. The first part of the project reviews HTML elements and then moves onto CSS. </p>
<p>Here is the complete list of topics covered. Click on any of the links below to learn more about the topic.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><a class="post-section-overview" href="#heading-doctype-and-html-elements">DOCTYPE and HTML elements</a> - Step 1</li>
<li><a class="post-section-overview" href="#heading-head-and-title-elements">Head and Title elements</a> - Step 2</li>
<li><a class="post-section-overview" href="#heading-meta-charset-attribute">Meta charset attribute</a> - Steps 3,17</li>
<li><a class="post-section-overview" href="#heading-body-element">Body element</a> - Step 4</li>
<li><a class="post-section-overview" href="#heading-heading-elements">Heading elements</a> - Steps 6,9,10, 47</li>
<li><a class="post-section-overview" href="#heading-paragraph-element">Paragraph element</a> - Steps 7, 30, 31, 49, 65</li>
<li><a class="post-section-overview" href="#heading-header-element">Header element</a> - Step 7</li>
<li><a class="post-section-overview" href="#heading-main-element">Main element</a> - Step 5 </li>
<li><a class="post-section-overview" href="#heading-section-elements">Section Elements</a> - Steps 8, 9, 46</li>
<li><a class="post-section-overview" href="#heading-style-element">Style element</a> - Step 10</li>
<li><a class="post-section-overview" href="#heading-text-align-property-in-css">text-align property in CSS</a> - Steps 11, 12,  33,  35</li>
<li><a class="post-section-overview" href="#heading-grouping-css-selectors">Grouping CSS selectors</a> - Steps 13, 51</li>
<li><a class="post-section-overview" href="#heading-linking-external-stylesheets">Linking External Stylesheets</a> - Step 16</li>
<li><a class="post-section-overview" href="#heading-viewport-meta-tag">Viewport meta tag</a> - Step 18</li>
<li><a class="post-section-overview" href="#heading-background-color-property">background-color property</a> - Steps 18, 19, 23, 68</li>
<li><a class="post-section-overview" href="#heading-div-element">Div element</a> - Step 20</li>
<li><a class="post-section-overview" href="#heading-css-width-property">CSS <code>width</code> property</a> - Steps 21, 24, 38, 39, 41, 45</li>
<li><a class="post-section-overview" href="#heading-css-comments">CSS comments</a> - Steps 22, 77</li>
<li><a class="post-section-overview" href="#heading-margin-property">Margin property</a> - Steps 25, 73, 75, 84, 85, 86, 91</li>
<li><a class="post-section-overview" href="#heading-class-selectors">Class selectors</a> - Steps 26, 27, 32,  34, 36, 42, 44, 50, 61, 76, 87</li>
<li><a class="post-section-overview" href="#heading-background-image-property"><code>background-image</code> property</a> - Step 28</li>
<li><a class="post-section-overview" href="#heading-article-element">Article element</a> - Steps 29, 31, 48, 52</li>
<li><a class="post-section-overview" href="#heading-block-inline-and-inline-block-values">Block, inline and inline-block values</a> - Steps 37, 89</li>
<li><a class="post-section-overview" href="#heading-padding">Padding</a> - Steps 53 - 55, 72</li>
<li><a class="post-section-overview" href="#heading-max-width-property"><code>max-width</code> property</a> - Step 56</li>
<li><a class="post-section-overview" href="#heading-font-family-property">font-family</a> - Step 57 - 59</li>
<li><a class="post-section-overview" href="#heading-font-style-property"><code>font-style</code> property</a> - Step 60</li>
<li><a class="post-section-overview" href="#heading-font-size-property"><code>font-size</code> property</a> - Steps 62, 74, 78</li>
<li><a class="post-section-overview" href="#heading-footer-elements">Footer elements</a> - Step 63</li>
<li><a class="post-section-overview" href="#heading-anchor-elements">Anchor elements</a> - Step 64</li>
<li><a class="post-section-overview" href="#heading-hr-element">hr element</a> - Steps 66, 71</li>
<li><a class="post-section-overview" href="#heading-height-property">Height property</a> - Steps 67, 70</li>
<li><a class="post-section-overview" href="#heading-border-color-property"><code>border-color</code> property</a> - Step 69</li>
<li><a class="post-section-overview" href="#heading-color-property">Color property</a> - Steps 79, 83</li>
<li><a class="post-section-overview" href="#heading-pseudo-classes">Pseudo-classes</a> - Steps 80, 81, 82</li>
<li><a class="post-section-overview" href="#heading-image-elements">Image elements</a> - Steps 88, 90</li>
<li><a class="post-section-overview" href="#heading-additional-resources-for-html-and-css">Additional resources for HTML and CSS</a></li>
</ul>
<h2 id="heading-doctype-and-html-elements">DOCTYPE and HTML elements</h2>
<p>The first line in your HTML code should be the <code>DOCTYPE</code> declaration. A <code>DOCTYPE</code> tells the browser what version of HTML the page is written in.</p>
<p>This is the <code>DOCTYPE</code> declaration for HTML 5:</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
</code></pre>
<p>If you forget to include this line of code in your file, then some of the HTML 5 tags like <code>&lt;article&gt;</code>, <code>&lt;footer&gt;</code>, and <code>&lt;header&gt;</code>  may not be supported by the browser.</p>
<p>The <code>html</code> element is the root element where all other elements go inside of it. </p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
  <span class="hljs-comment">&lt;!--All other elements go inside here--&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>The <code>lang</code> attribute inside the opening <code>&lt;html&gt;</code> tag sets the language for the page. It is also good to include it for accessibility reasons, because screen readers will know how to properly pronounce the text.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
</code></pre>
<h2 id="heading-head-and-title-elements">Head and Title elements</h2>
<p>The <code>&lt;head&gt;</code> tags contain information that is processed by machines. Inside the <code>&lt;head&gt;</code> tags, you will nest metadata which is data that describes the document to the machine.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-comment">&lt;!--important meta data goes inside here--&gt;</span>
  <span class="hljs-comment">&lt;!--title element also goes inside here--&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
</code></pre>
<p>The <code>&lt;title&gt;</code> tag is the title for the web page. This text is shown in the browser's title bar.</p>
<pre><code class="lang-html">    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>HTML 5 Boilerplate<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/07/Screen-Shot-2021-07-30-at-4.15.25-AM.png" alt="Screen-Shot-2021-07-30-at-4.15.25-AM" width="600" height="400" loading="lazy"></p>
<p>This is an example of what a <code>head</code> would look like on a real web page. None of this information is displayed on the web page itself.</p>
<pre><code class="lang-html"> <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"X-UA-Compatible"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"ie=edge"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>HTML 5 Boilerplate<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"style.css"</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
</code></pre>
<p>For a detailed description of each meta tag listed, you can read through <a target="_blank" href="https://www.freecodecamp.org/news/basic-html5-template-boilerplate-code-example/">this article on an HTML5 Boilerplate</a>.</p>
<h2 id="heading-meta-charset-attribute">Meta charset attribute</h2>
<p>UTF-8 is the standard character encoding you should use in your web pages. This will usually be the first <code>&lt;meta&gt;</code> tag shown in the <code>&lt;head&gt;</code> element.</p>
<pre><code class="lang-html"> <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
</code></pre>
<p>According to the <a target="_blank" href="https://www.w3.org/International/questions/qa-choosing-encodings">World Wide Web Consortium</a>,</p>
<blockquote>
<p>A Unicode-based encoding such as UTF-8 can support many languages and can accommodate pages and forms in any mixture of those languages. Its use also eliminates the need for server-side logic to individually determine the character encoding for each page served or each incoming form submission.</p>
</blockquote>
<h2 id="heading-body-element">Body element</h2>
<p>The body element contains all of the content for the web page. This includes headings, paragraphs, images, links, and more.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Let's learn about the body element<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-comment">&lt;!--web page content goes inside here--&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<h2 id="heading-heading-elements">Heading elements</h2>
<p>HTML heading elements represent the main heading and subheadings of a web page.</p>
<p>The <code>h1</code> element represents the most important heading and should only be used once per web page.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>I represent the main heading of a web page<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
</code></pre>
<p>The <code>h2</code> element represents the second most important heading on the page.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>I am the second most important heading element<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
</code></pre>
<p>There are a total of six section heading elements:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>I am the most important heading element<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>I am the second most important heading element<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>I am the third most important heading element<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">h4</span>&gt;</span>I am the fourth most important heading element<span class="hljs-tag">&lt;/<span class="hljs-name">h4</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">h5</span>&gt;</span>I am the fifth most important heading element<span class="hljs-tag">&lt;/<span class="hljs-name">h5</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">h6</span>&gt;</span>I am the least important heading element<span class="hljs-tag">&lt;/<span class="hljs-name">h6</span>&gt;</span>
</code></pre>
<p>This is what it looks like rendered to the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-18-at-9.19.27-PM.png" alt="Screen-Shot-2022-06-18-at-9.19.27-PM" width="600" height="400" loading="lazy"></p>
<p>To learn more about heading elements, you can read through this <a target="_blank" href="https://devdocs.io/html/element/heading_elements">DevDocs detailed heading elements explanation</a>.</p>
<h2 id="heading-paragraph-element">Paragraph element</h2>
<p>Paragraph elements represent the paragraphs on a web page.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>I love learning with freeCodeCamp. They have thousands of free articles and videos to help me learn how to code.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>This is what it looks like rendered to the page:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-18-at-9.55.21-PM.png" alt="Screen-Shot-2022-06-18-at-9.55.21-PM" width="600" height="400" loading="lazy"></p>
<p>To learn more about paragraph elements, you can read through this <a target="_blank" href="https://devdocs.io/html/element/p">DevDocs <code>p</code> element detailed explanation</a>.</p>
<h2 id="heading-header-element">Header element</h2>
<p>The <code>header</code> element contains introductory content of the web page. This can include elements like a <code>nav</code>, <code>h1</code> or website logo. </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">header</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"link-for-logo"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"description for fake logo goes here"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">nav</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/"</span>&gt;</span>Home<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#bio"</span>&gt;</span>Bio<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#projects"</span>&gt;</span>Projects<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">header</span>&gt;</span>
</code></pre>
<h2 id="heading-main-element">Main element</h2>
<p>The <code>main</code> element is used to group all of the main content of the web page.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>What freeCodeCamp has to offer<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">main</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>The core freeCodeCamp curriculum teaches full stack JavaScript and Python. There are hundreds of lessons to go through to get you ready for an entry level developer job.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>freeCodeCamp has thousands of free articles on their news publication. They also have hundreds of videos on their YouTube channel.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">main</span>&gt;</span>
</code></pre>
<p>This is what the code looks like rendered to the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-18-at-10.34.18-PM.png" alt="Screen-Shot-2022-06-18-at-10.34.18-PM" width="600" height="400" loading="lazy"></p>
<p>To learn more about the <code>main</code> element, you can read through this <a target="_blank" href="https://devdocs.io/html/element/main">DevDocs detailed <code>main</code> element explanation</a>.</p>
<h2 id="heading-section-elements">Section elements</h2>
<p>The <code>section</code> element is used to group sections of content in the HTML document.</p>
<p>Here is an example of the <code>section</code> element:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Let's learn about section elements<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">section</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Defintion<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>The section element is used to group sections of content in the HTML document.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
</code></pre>
<p>This is what the result looks like rendered to the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-25-at-9.34.22-PM.png" alt="Screen-Shot-2022-06-25-at-9.34.22-PM" width="600" height="400" loading="lazy"></p>
<p>To learn more about <code>section</code> elements, you can read through this <a target="_blank" href="https://devdocs.io/html/element/section">DevDocs <code>section</code> element detailed explanation</a>.</p>
<h2 id="heading-style-element">Style element</h2>
<p>The <code>style</code> element contains the styling for the web page. This is known as internal CSS.</p>
<p>The <code>style</code> element goes inside the <code>head</code> tags.</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
    <span class="hljs-comment">/*Styles will go inside here*/</span>
  </span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
  <span class="hljs-comment">&lt;!--website content goes inside here--&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>To learn more, you can read through this helpful <a target="_blank" href="https://devdocs.io/html/element/style">DevDocs explanation on the <code>style</code> element</a>.</p>
<h2 id="heading-text-align-property-in-css"><code>text-align</code> Property in CSS</h2>
<p>When you are working with heading or paragraph tags, the default styling in HTML will position the text on the left hand side of the page.</p>
<p>In this example, we have an <code>&lt;h1&gt;</code> which is placed on the upper left hand side of the page.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Let's learn about centering text<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screen-Shot-2022-04-24-at-11.41.12-AM.png" alt="Screen-Shot-2022-04-24-at-11.41.12-AM" width="600" height="400" loading="lazy"></p>
<p>If we wanted to horizontally center that text on the page, then we can use the <code>text-align</code> property.</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">h1</span> {
  <span class="hljs-attribute">text-align</span>: center;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screen-Shot-2022-04-24-at-11.42.48-AM.png" alt="Screen-Shot-2022-04-24-at-11.42.48-AM" width="600" height="400" loading="lazy"></p>
<p>To learn more, you can read through this helpful article on centering text: <a target="_blank" href="https://www.freecodecamp.org/news/text-align-in-css-how-to-align-text-in-center-with-html/">Text Align in CSS – How to Align Text in Center with HTML</a>.</p>
<h2 id="heading-grouping-css-selectors">Grouping CSS selectors</h2>
<p>If you have multiple CSS selectors with the same styles, then you can group them together like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">h1</span>, <span class="hljs-selector-tag">h2</span>, <span class="hljs-selector-tag">h3</span> {
    <span class="hljs-attribute">text-align</span>: center;
}
</code></pre>
<p>Notice how the <code>h1</code>, <code>h2</code> and <code>h3</code> are separated by commas. Grouping multiple CSS selectors together cleans up your CSS and removes repetition. </p>
<p>You can <a target="_blank" href="https://www.freecodecamp.org/news/css-combinators-to-select-elements/">read more about CSS combinators here</a>.</p>
<h2 id="heading-linking-external-stylesheets">Linking External Stylesheets</h2>
<p>The <code>link</code> element is used in most cases to link an external stylesheet to the HTML document. Using external CSS is preferred in most cases to help keep your HTML and CSS in separate documents for readability. </p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"style.css"</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p><code>rel="stylesheet"</code> defines the relationship between the HTML file and the external stylesheet.</p>
<p>To learn more, you can read this <a target="_blank" href="https://devdocs.io/html/element/link">DevDocs example on <code>link</code> elements</a>.</p>
<h2 id="heading-viewport-meta-tag">Viewport meta tag</h2>
<p>This tag renders the width of the page to the width of the device's screen size. If you have a mobile device that is 600px wide, then the browser window will also be 600px wide.</p>
<p>The initial-scale controls the zoom level. The value of 1 for the initial-scale prevents the default zoom by browsers.</p>
<pre><code class="lang-html">    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
</code></pre>
<h2 id="heading-background-color-property"><code>background-color</code> property</h2>
<p>You can change the background color of an HTML element by using the CSS <code>background-color</code> property.</p>
<p>Let's say we have this HTML markup.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Let's learn about the background-color property<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>We are learning about background colors<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>I wanted to change the background color from the default of white to pink. We can target the <code>body</code> selector and use <code>background-color: pink;</code></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span> {
  <span class="hljs-attribute">background-color</span>: pink;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/07/Screen-Shot-2022-07-02-at-10.57.53-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>To learn more, you can read through this helpful article: <a target="_blank" href="https://www.freecodecamp.org/news/css-background-color-how-to-change-the-background-color-in-html/">CSS Background Color – How to Change the Background Color in HTML</a>.</p>
<h2 id="heading-div-element">Div element</h2>
<p>The <code>div</code> HTML element is used to group multiple HTML elements and represents a generic container. This element holds no semantic meaning and is mainly used for styling purposes. </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Let's learn about divs<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>div elements are generic containers to group elements<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>To learn more, you can read through this helpful article: <a target="_blank" href="https://www.freecodecamp.org/news/html-div-what-is-a-div-tag-and-how-to-style-it-with-css/">HTML Div – What is a Div Tag and How to Style it with CSS</a>.</p>
<h2 id="heading-css-width-property">CSS width property</h2>
<p>The <code>width</code> property will set the width for the HTML element. </p>
<p>In this example, I want to set the width of this <code>div</code> to 200px.</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">div</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
}
</code></pre>
<p>To learn more, you can read through this helpful <a target="_blank" href="https://devdocs.io/css/width">DevDocs explanation</a> on the width property. </p>
<h2 id="heading-css-comments">CSS comments</h2>
<p>If you need to comment out code or leave messages for yourself or other developers, you can use comments. </p>
<p>Here is the basic syntax for a comment in CSS:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* this is a comment in CSS */</span>
</code></pre>
<p>Anything inside that comment tag will not be rendered to the web page.</p>
<p>In this example, we have some HTML markup.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>CSS comments<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"red-text"</span>&gt;</span>This is some demo text<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>For the CSS, I have changed the text color to red and increased the font size.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.red-text</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1.2rem</span>;
  <span class="hljs-attribute">color</span>: red;
}
</code></pre>
<p>Here is the current result:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/07/Screen-Shot-2022-07-09-at-9.33.31-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>If I comment out the red text color, then the text will go back to black.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.red-text</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1.2rem</span>;
  <span class="hljs-comment">/* color: red; */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/07/Screen-Shot-2022-07-09-at-9.34.30-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-margin-property">Margin property</h2>
<p>The <code>margin</code> property represents the space around the HTML element. There are four different margin properties:</p>
<ul>
<li><code>margin-left</code></li>
<li><code>margin-right</code></li>
<li><code>margin-top</code></li>
<li><code>margin-bottom</code></li>
</ul>
<p>In this first example, we have two <code>div</code> elements which represent blue and red boxes.</p>
<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">"blue-box"</span>&gt;</span><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">"red-box"</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">.blue-box</span>,
<span class="hljs-selector-class">.red-box</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
}

<span class="hljs-selector-class">.blue-box</span> {
  <span class="hljs-attribute">background-color</span>: blue;
}

<span class="hljs-selector-class">.red-box</span> {
  <span class="hljs-attribute">background-color</span>: red;
}
</code></pre>
<p>Here is what the result looks like rendered to the page:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/07/Screen-Shot-2022-07-09-at-10.26.01-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>If we want to created some space between the red and blue boxes we can use the <code>margin</code> property. I am going to add a <code>margin-bottom: 20px;</code> to the blue box to create space. </p>
<pre><code class="lang-css"><span class="hljs-selector-class">.blue-box</span> {
  <span class="hljs-attribute">background-color</span>: blue;
  <span class="hljs-attribute">margin-bottom</span>: <span class="hljs-number">20px</span>;
}
</code></pre>
<p>This is what the result looks like:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/07/Screen-Shot-2022-07-09-at-10.27.39-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We can also center both boxes, by setting the <code>margin-left</code> and <code>margin-right</code> properties to <code>auto</code>.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.blue-box</span>,
<span class="hljs-selector-class">.red-box</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
  <span class="hljs-attribute">margin-left</span>: auto;
  <span class="hljs-attribute">margin-right</span>: auto;
}
</code></pre>
<p>Here is the result:</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/jessica-wilkins/embed/yLKJyjV?editors=1100" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>In this next example, we have a green box, a blue box, and some text on the page. We can use the <code>margin-left</code>, <code>margin-right</code>, <code>margin-top</code>, and <code>margin-bottom</code> properties to create spaces between the text and boxes.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text"</span>&gt;</span>Margin shorthand property<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"green-box"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text"</span>&gt;</span>Margins create space around HTML elements<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"blue-box"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text"</span>&gt;</span>CSS is fun<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-class">.text</span> {
  <span class="hljs-attribute">text-align</span>: center;
}
<span class="hljs-selector-class">.blue-box</span>,
<span class="hljs-selector-class">.green-box</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
  <span class="hljs-attribute">margin-left</span>: auto;
  <span class="hljs-attribute">margin-right</span>: auto;
  <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">margin-bottom</span>: <span class="hljs-number">20px</span>;
}

<span class="hljs-selector-class">.blue-box</span> {
  <span class="hljs-attribute">background-color</span>: blue;
}

<span class="hljs-selector-class">.green-box</span> {
  <span class="hljs-attribute">background-color</span>: green;
}
</code></pre>
<p>Here is the result:</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/jessica-wilkins/embed/gOeMbjN?editors=1100" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>For the blue and green boxes, we can clean up our code here and place all of these <code>margin</code> styles all in one line.</p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">margin-left</span>: <span class="hljs-selector-tag">auto</span>;
  <span class="hljs-selector-tag">margin-right</span>: <span class="hljs-selector-tag">auto</span>;
  <span class="hljs-selector-tag">margin-top</span>: 20<span class="hljs-selector-tag">px</span>;
  <span class="hljs-selector-tag">margin-bottom</span>: 20<span class="hljs-selector-tag">px</span>;
</code></pre>
<p>The <code>margin</code> shorthand property is used to set the margin for all sides of the element. If two values are present, then the first value represents the top &amp; bottom margins while the second value represents the left &amp; right margins. </p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">margin</span>: 20<span class="hljs-selector-tag">px</span> <span class="hljs-selector-tag">auto</span>;
</code></pre>
<p>To learn more about the <code>margin</code> shorthand property, you can read through <a target="_blank" href="https://devdocs.io/css/margin">this helpful DevDocs explanation</a>. </p>
<h2 id="heading-class-selectors">Class selectors</h2>
<p>If you wanted a group of HTML elements to share the same styles, then you would use the <code>class</code> attribute. </p>
<p>Here is an example of how to apply a class to an HTML element.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"title"</span>&gt;</span>Jessica Wilkins blog<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
</code></pre>
<p>Then in your CSS, you can target that class and add some styles to it. </p>
<p>Here is an example of turning that text red, using CSS. Note, that you need to precede that class name with a <code>.</code> which tells the computer that you want to use a class selector.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.title</span> {
  <span class="hljs-attribute">color</span>: red;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-05-at-8.14.24-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-background-image-property">background-image property</h2>
<p>The <code>background-image</code> property is used to set the background image for an HTML element. </p>
<p>In this example, we are going to apply a background image of lasagna to the <code>body</code> element. </p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span> {
  <span class="hljs-attribute">background-image</span>: <span class="hljs-built_in">url</span>(<span class="hljs-string">"https://cdn.freecodecamp.org/curriculum/cat-photo-app/lasagna.jpg"</span>);
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-05-at-8.38.43-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The reason why this image is repeating on the screen is because that is the default behavior for the <code>background-image</code> property. You could use <code>background-repeat: no-repeat;</code> to change that default behavior. </p>
<h2 id="heading-article-element">Article element</h2>
<p>The <code>article</code> element is a semantic HTML element that is used for independent self contained content.  </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">article</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Blog entry #3<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
  content goes here...
<span class="hljs-tag">&lt;/<span class="hljs-name">article</span>&gt;</span>
</code></pre>
<h2 id="heading-block-inline-and-inline-block-values">Block, inline and inline-block values</h2>
<p>The <code>display</code> property is used to apply block or inline characteristics to an element. Block level elements take up the full horizontal space on the page while inline elements only take up the horizontal space for that element. </p>
<p>Inline elements will not work with width and height properties. The <code>margin</code> left and right values will work for inline elements but not the top and bottom values.</p>
<p>You can have multiple inline elements displayed in a row while you can have only one block level element per row. Here is an example for multiple inline elements in a row:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">""</span>&gt;</span>this is link 1<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">""</span>&gt;</span>this is link 2<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">""</span>&gt;</span>this is link 3<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-05-at-9.37.55-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>You can use the <code>display:block;</code> value on these anchor element to change their default behavior and set it to block characteristics. </p>
<pre><code class="lang-css"><span class="hljs-selector-tag">a</span> {
  <span class="hljs-attribute">display</span>: block;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-06-at-12.40.45-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>This next example is for multiple block level elements. Notice how each of these <code>divs</code> takes up the entire horizontal space on the page and they are not displayed next to each other. </p>
<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">"box red"</span>&gt;</span><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">"box green"</span>&gt;</span><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">"box blue"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-05-at-9.42.27-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>This last value is called <code>inline-block</code> which will treat elements as inline but will also have characteristics of block level elements. </p>
<p>Here is an example of two paragraph elements that are block level elements by default.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is paragraph 1.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is paragraph 2.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-05-at-9.47.44-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>I can set the width, margin, padding and <code>background-color</code> for these <code>p</code> elements. </p>
<pre><code class="lang-css"><span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#89cff0</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">15px</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-05-at-9.52.04-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We can add <code>display: inline-block;</code> to place the paragraph elements next to each other.</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#89cff0</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">15px</span>;
  <span class="hljs-attribute">display</span>: inline-block;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-05-at-9.53.52-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-padding">Padding</h2>
<p>In CSS, you can add padding to create space around the element's content. </p>
<p>In this example we have a paragraph element with a pink background that uses no padding.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is an example without padding<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">background-color</span>: pink;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-05-at-11.44.34-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Notice how the text is right up against the border of the <code>p</code> element. That is because we haven't added any padding. </p>
<p>If we want to create space around that text, then we can use padding. Let's add 10px of padding on all sides of the text.</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">background-color</span>: pink;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-05-at-11.57.14-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>If we only wanted to add padding to the left and right sides, then we can use the <code>padding-left</code> and <code>padding-right</code> properties.</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">background-color</span>: pink;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
  <span class="hljs-attribute">padding-left</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding-right</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-05-at-11.57.40-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We can also modify it so there is only space around the top and bottom of the text. </p>
<pre><code class="lang-css"><span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">background-color</span>: pink;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
  <span class="hljs-attribute">padding-top</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding-bottom</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-05-at-11.58.03-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Similar to the <code>margin</code> property, you can use a shorthand notation to apply different types of padding to the top, left, right, and bottom sides. </p>
<p>In this example we are going to add 10px of padding to the top and bottom of the text and add 15px of padding to the left and right sides of the text. </p>
<p>Without the shorthand property the code would look like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">background-color</span>: pink;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
  <span class="hljs-attribute">padding-left</span>: <span class="hljs-number">15px</span>;
  <span class="hljs-attribute">padding-right</span>: <span class="hljs-number">15px</span>;
  <span class="hljs-attribute">padding-top</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding-bottom</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p>But we can use the shorthand notation to achieve the same result. The first number in the padding property represents the top and bottom while the second number represents the left and right. </p>
<pre><code class="lang-css"><span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">background-color</span>: pink;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span> <span class="hljs-number">15px</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-05-at-11.58.42-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>To learn more about the padding shorthand notation, you can read through this helpful <a target="_blank" href="https://devdocs.io/css/padding">DevDocs explanation</a>. </p>
<h2 id="heading-max-width-property"><code>max-width</code> property</h2>
<p>The <code>max-width</code> property is useful when you want to set a maximum width for an element. </p>
<p>In this example, we have a red container with a <code>width</code> set to 70% of the viewport width.</p>
<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">"red-container"</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">.red-container</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">70%</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">40px</span>;
  <span class="hljs-attribute">background-color</span>: red;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-06-at-1.11.27-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We can use the <code>max-width</code> property to set a maximum width of 1000px to this red container. </p>
<pre><code class="lang-css"><span class="hljs-selector-class">.red-container</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">70%</span>;
  <span class="hljs-attribute">max-width</span>: <span class="hljs-number">1000px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">40px</span>;
  <span class="hljs-attribute">background-color</span>: red;
}
</code></pre>
<p>Now, when the viewport is larger than 1000px, the width will no longer be set to 70% of the viewport. Instead, it will stay at the maximum width of 1000px. </p>
<h2 id="heading-font-family-property"><code>font-family</code> property</h2>
<p>In design, a <code>font-family</code> represents a collection of fonts that share similar design characteristics. Here are some examples of some font families:</p>
<pre><code>Times, Times New Roman, serif    
Comic Sans MS, Comic Sans, cursive
</code></pre><p>In CSS, you can use the <code>font-family</code> property to apply a set of fonts to given elements.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Let's learn about font families<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is an example on how to use the font-family CSS property<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span> {
  <span class="hljs-attribute">font-family</span>: Comic Sans MS, Comic Sans, cursive;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-06-at-1.28.01-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The browser will select the first font in the list and display if it is available. If that font is not available, then it will move onto the next font in the list. </p>
<p>It is good practice to provide a fallback font in the event that the other fonts in the list are not available to the browser.  In our example, <code>cursive</code> would considered the fallback if Comic Sans MS and Comic Sans were not available. </p>
<h2 id="heading-font-style-property"><code>font-style</code> property</h2>
<p>The <code>font-style</code> property is used to set the text in a normal, italic, or oblique font style. </p>
<p>Here is an example of setting the text to an italic <code>font-style</code>.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>This example is about the font-style property<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-tag">h1</span> {
  <span class="hljs-attribute">font-style</span>: italic;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-06-at-1.36.57-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>It's important not to use the <a target="_blank" href="https://www.freecodecamp.org/news/html-italics-tutorial-how-to-make-text-italic-with-the-i-tag/">HTML <code>i</code> (Idiomatic Text) element</a> for styling text in italics. When it comes to styling text, you should always use the <code>font-style</code> property. </p>
<h2 id="heading-font-size-property"><code>font-size</code> property</h2>
<p>The <code>font-size</code> property is used to change the font sizes for HTML elements like headings and paragraphs. Here are some common values that you can use with the <code>font-size</code> property: </p>
<ul>
<li>xx-small,  x-small, small, medium, large, x-large, xx-large, xxx-large</li>
<li>smaller, larger </li>
<li>px, em, rem</li>
<li>percentages (for example, font-size: 60%;)</li>
</ul>
<p>In this example, we are going to set the <code>font-size</code> for this paragraph element to be 20px. </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This example is about the font-size property<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">20px</span>;
}
</code></pre>
<h2 id="heading-footer-elements"><strong>Footer elements</strong></h2>
<p>The <code>footer</code> element is located at the bottom of the HTML document and contains information like copyrights, or links to other related information for the page.</p>
<p>Here is a basic example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">footer</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>© 2022 Jessica Wilkins<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">footer</span>&gt;</span>
</code></pre>
<p>To learn more about the <code>footer</code> element, you can read through <a target="_blank" href="https://devdocs.io/html/element/footer">this DevDocs explanation of the <code>footer</code> element</a>.</p>
<h2 id="heading-anchor-elements"><strong>Anchor elements</strong></h2>
<p>An anchor element represents a link on the web page.</p>
<p>Here is the basic syntax:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"link-where-you-want-to-go"</span>&gt;</span>anchor text goes here<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
<p>This is what it looks like rendered to the page:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-25-at-5.10.07-PM.png" alt="Screen-Shot-2022-06-25-at-5.10.07-PM" width="600" height="400" loading="lazy"></p>
<p>You use the <code>href</code> attribute to tell the hyperlink where to go.</p>
<pre><code class="lang-html">href="link-where-you-want-to-go"
</code></pre>
<p>The anchor text is what gets displayed on the screen to users.</p>
<p>Here is an example of an anchor tag that links to freeCodeCamp:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://www.freecodecamp.org/"</span>&gt;</span>freeCodeCamp<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
<p>This is what it looks like rendered to the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-25-at-5.41.36-PM.png" alt="Screen-Shot-2022-06-25-at-5.41.36-PM" width="600" height="400" loading="lazy"></p>
<p>To learn more about HTML anchor elements, I suggest reading through these helpful articles:</p>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/the-html-a-tag-anchor-tag-example-code/">The HTML </a><a> Tag – Anchor Tag Example Code</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/html-a-tag-anchor-link-href-example/">HTML </a><a> Tag – Anchor Link HREF Example</a></li>
</ul>
<h2 id="heading-hr-element"><code>hr</code> element</h2>
<p>The <code>hr</code> (Horizontal Rule) element is used to created breaks between the paragraph elements. </p>
<p>Here is an example of how to use the <code>hr</code> element between two paragraph elements. <code>hr</code> elements are self closing. </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is paragraph 1<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">hr</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is paragraph 2<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-06-at-1.02.23-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>You can style the <code>hr</code> element by changing its border and color. </p>
<pre><code class="lang-css"><span class="hljs-selector-tag">hr</span> {
  <span class="hljs-attribute">border</span>: <span class="hljs-number">5px</span> solid red;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-06-at-1.05.39-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-height-property">Height property</h2>
<p>The <code>height</code> property in CSS is used to set the height for an HTML element. Here is an example where we have a blue container with a height of 50px.</p>
<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">"blue-container"</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">.blue-container</span> {
  <span class="hljs-attribute">background-color</span>: blue;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">30px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">50px</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-06-at-1.11.44-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>To learn more about the <code>height</code> property, you can read through this helpful <a target="_blank" href="https://devdocs.io/css/height">DevDocs explanation</a>. </p>
<h2 id="heading-border-color-property"><code>border-color</code> property</h2>
<p>The <code>border-color</code> property is used to set the color for an element's border.</p>
<p>In this example, we are going to create two paragraph elements with different border colors. The first step is to set the border widths and style. </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"para1"</span>&gt;</span>This is paragraph one with a green border<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"para2"</span>&gt;</span>This is paragraph two with a blue border<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">border-style</span>: solid;
  <span class="hljs-attribute">border-width</span>: <span class="hljs-number">3px</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-06-at-1.21.11-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Then we can set the first paragraph to have a border color of green and the second paragraph to have a border color of blue. </p>
<pre><code class="lang-css"><span class="hljs-selector-class">.para1</span> {
  <span class="hljs-attribute">border-color</span>: green;
}

<span class="hljs-selector-class">.para2</span> {
  <span class="hljs-attribute">border-color</span>: blue;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-06-at-1.22.36-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We can rewrite our example to use the border shorthand notation to apply the border width, color, and style all at the same time.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.para1</span> {
  <span class="hljs-attribute">border</span>: <span class="hljs-number">3px</span> solid green;
}

<span class="hljs-selector-class">.para2</span> {
  <span class="hljs-attribute">border</span>: <span class="hljs-number">3px</span> solid blue;
}
</code></pre>
<h2 id="heading-color-property">Color property</h2>
<p>You can change the color of the text by using the <code>color</code> property. Here is an example to change the paragraph text to blue:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is an example for the color property<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">color</span>:blue;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-06-at-1.30.47-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-pseudo-classes">Pseudo-classes</h2>
<p>Pseudo-classes are special keywords that you can add to CSS selectors to show the specific state of an HTML element. </p>
<p>In this first example, we are going to create a blue button that changes to a darker shade of blue when the user hovers over it. We can use the <code>:hover</code> pseudo-class to achieve that result. </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Login<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-tag">button</span> {
  <span class="hljs-attribute">border</span>: none;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">color</span>: white;
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#0e3386</span>;
  <span class="hljs-attribute">cursor</span>: pointer;
}

<span class="hljs-selector-tag">button</span><span class="hljs-selector-pseudo">:hover</span> {
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#041e42</span>;
}
</code></pre>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/jessica-wilkins/embed/ExRgXod" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>In this next example, we are going to use CSS pseudo-classes to style the different states for a link. </p>
<p>The <code>:link</code> pseudo-class is used to show the initial state of the link. </p>
<pre><code class="lang-css"><span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:link</span> {
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#0066b2</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-06-at-2.01.56-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The <code>:hover</code> pseudo-class is used to show when a user hovers over a link.</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span> {
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#13274f</span>;
}
</code></pre>
<p>The <code>:visited</code> pseudo-class is used to show when a user clicks on that link and visits the site. </p>
<pre><code class="lang-css"><span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:visited</span> {
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#5a4fcf</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/11/Screen-Shot-2022-11-06-at-2.11.03-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>You can play around with this CodePen example to see the different link states. </p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/jessica-wilkins/embed/RwJGgyP?editors=1100#_=_" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>If you want to learn more about pseudo-classes, then you can read through this <a target="_blank" href="https://www.freecodecamp.org/news/explained-css-pseudo-classes-cef3c3177361/">helpful article</a>. </p>
<h2 id="heading-image-elements"><strong>Image elements</strong></h2>
<p><code>img</code> elements are used to add images to the web page.</p>
<p>The <code>src</code> attribute represents the location of the image and the <code>alt</code> attribute is descriptive text for the image.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://cdn.freecodecamp.org/curriculum/cat-photo-app/lasagna.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"plate of lasagna"</span>&gt;</span>
</code></pre>
<p>This is the what code looks like rendered to the page:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-18-at-11.41.23-PM.png" alt="Screen-Shot-2022-06-18-at-11.41.23-PM" width="600" height="400" loading="lazy"></p>
<p>To learn more about the <code>img</code> element, you can read through this helpful <a target="_blank" href="https://www.freecodecamp.org/news/img-html-image-tag-tutorial/"><code>img</code> element tutorial</a>.</p>
<h2 id="heading-additional-resources-for-html-and-css">Additional resources for HTML and CSS</h2>
<p>Thanks for reading! Here are some more helpful resources to get you comfortable with CSS:</p>
<ul>
<li><a target="_blank" href="https://www.youtube.com/watch?v=OXGznpKZ_sA">CSS Tutorial – Full Course for Beginners</a></li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=1Rs2ND1ryYc">CSS Tutorial - Zero to Hero (Complete Course)</a></li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=a_iQb1lnAEQ">Learn HTML &amp; CSS – Full Course for Beginners</a></li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=srvUrASNj0s">Introduction To Responsive Web Design - HTML &amp; CSS Tutorial</a></li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=kMT54MPz9oE">HTML and CSS Tutorial - Create a Website for Beginners</a>  </li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How Responsive Web Design Can Help Your Business – A Beginner's Guide to RWD ]]>
                </title>
                <description>
                    <![CDATA[ As the world of technology continues to advance, so does the way people interact with businesses and organizations.  With the growing popularity of mobile devices, responsive website design has become a must-have. It helps you provide the best user e... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-responsive-web-design-helps-businesses/</link>
                <guid isPermaLink="false">66ba6110739c8c931a5408ab</guid>
                
                    <category>
                        <![CDATA[ responsive design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Design ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ valentine Gatwiri ]]>
                </dc:creator>
                <pubDate>Tue, 06 Sep 2022 20:18:06 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/09/Screenshot-from-2022-09-02-20-26-21.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>As the world of technology continues to advance, so does the way people interact with businesses and organizations. </p>
<p>With the growing popularity of mobile devices, responsive website design has become a must-have. It helps you provide the best user experience to customers regardless of which device they are using at any given time. </p>
<p>In this article, we'll discuss some of the benefits that responsive website design can bring to your business or organization. </p>
<h2 id="heading-what-you-will-learn">What you will learn</h2>
<p>In this article, you will learn about responsive web design and how it can benefit your business. </p>
<p>You will also learn about some of the key features that make a responsive website. </p>
<p>By the end of this post, you should have a good understanding of why you need to make the switch to a responsive website.</p>
<h2 id="heading-what-is-responsive-web-design-rwd">What is Responsive Web Design (RWD)?</h2>
<p>Responsive web design is an approach to web design that makes websites look good on all devices, from small phones to large desktop monitors, as shown below. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/09/image-209.png" alt="Image" width="600" height="400" loading="lazy">
<em>responsive web design</em></p>
<p>RWD is important because it allows your website to be accessible to everyone, no matter what device they're using.</p>
<h2 id="heading-why-does-rwd-matter-for-my-business">Why Does RWD Matter For My Business?</h2>
<p>These days, more and more people are using their mobile devices to browse the web. </p>
<p>In fact, according to <a target="_blank" href="https://www.statista.com/statistics/277125/share-of-website-traffic-coming-from-mobile-devices/">Statista</a>, mobile devices accounted for more than 50% of global internet usage this year. That’s more than half! And it's only going to increase as technology becomes even more advanced.</p>
<p>As you can see, your business needs to be accessible anywhere, on any device – and responsive design is the best way to make that happen. </p>
<p>If you have a website that is not responsive, you're losing out on valuable traffic from mobile users because they will bounce off your site immediately if they can't view it properly on their phone or tablet.</p>
<h2 id="heading-how-does-responsive-web-design-benefit-me-and-my-customers">How Does Responsive Web Design Benefit Me And My Customers?</h2>
<p>A responsive website provides a better user experience, which can lead to more customers and conversions. </p>
<p>Responsive websites aren't just beneficial for businesses. They also provide benefits to consumers. With a single touch or click of their mouse, users can access whatever they need from whichever device they prefer – be it their laptop, tablet or phone.</p>
<p>If you're like most business owners, you want to make sure your website is accessible to as many people as possible. That's why responsive design is so important. </p>
<p>Responsive sites are also easier to maintain because you can make content updates on one version and it'll automatically be reflected on all screens. This can save you time and money in the long run.</p>
<h2 id="heading-how-to-get-started-with-responsive-web-design">How to Get Started with Responsive Web Design</h2>
<p>Having a responsive design is paramount for attracting new clients. While it may seem difficult, I assure you that you can do it!</p>
<p>Here are a few simple steps you can take in order to start becoming responsive today:</p>
<ol>
<li>Start by redesigning your site with images and content scaled for smaller screens such as tablets and smartphones. This way, you will be ahead of the curve when mobile use starts dominating the market. </li>
<li>Write your content responsively.</li>
<li>Use <code>CSS</code> media queries so that you can display different styling based on the device being used to view the site. The <code>CSS</code> code below will serve as an example: </li>
</ol>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> <span class="hljs-keyword">only</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">768px</span>){...}
</code></pre>
<p>When the screen shrinks to less than 768px, each column should have a width of 95%:</p>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> <span class="hljs-keyword">only</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">768px</span>) {
  <span class="hljs-comment">/* For mobile phones: */</span>
  <span class="hljs-selector-attr">[class*=<span class="hljs-string">"col-"</span>]</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">95%</span>;
  }
}
</code></pre>
<p>Checkout the following <a target="_blank" href="https://codepen.io/gatwirival/pen/qBYBRXa">code</a>. You can play around with it to learn more about media queries.</p>
<ol start="4">
<li><p>Convert all your fonts into <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text/Web_fonts">web fonts</a>, which are faster loading and much more compatible across browsers than other fonts. You might also consider investing in a <a target="_blank" href="https://designmodo.com/responsive-retina-images/">retina ready logo and site design</a>. </p>
</li>
<li><p>Add social media icons to your site so people visiting from mobile devices can share your content with friends. </p>
</li>
<li><p>Enable any videos or slideshows on your website to auto play once they load instead of making users click first. This helps ensure that people don't exit out before viewing important information. </p>
</li>
<li><p>Make sure your navigation menu uses clear language and large buttons for easy access no matter what size screen is being used. </p>
</li>
<li><p>When adding links, think about how you would navigate the site on a smartphone or tablet to help increase usability for those browsing from these small screens.</p>
</li>
<li><p>Test your website regularly to make sure everything looks good and functions properly across various types of devices.</p>
</li>
</ol>
<h2 id="heading-timing-is-everything">Timing Is Everything!</h2>
<p>You may be wondering if responsive website design is worth the investment. After all, your current website might be getting the job done just fine. </p>
<p>But in today’s mobile-first world, a responsive website is essential to stay competitive. Here are four reasons why you should make the switch to a responsive website </p>
<ol>
<li>It will improve your customer experience</li>
<li>It will improve SEO</li>
<li>It will improve user engagement</li>
<li>It will help retain customers</li>
</ol>
<h2 id="heading-how-to-learn-responsive-web-design">How to Learn Responsive Web Design</h2>
<p>If you want to get started learning responsive web design so you can update your site, check out freeCodeCamp's newly updated <a target="_blank" href="https://www.freecodecamp.org/news/responsive-web-design-certification-redesigned/">RWD curriculum here</a>. You'll learn major responsive web design concepts and syntax through building 20 projects.</p>
<p>Here's what the certification covers:</p>
<ol>
<li>Learn HTML by Building a Cat Photo App</li>
<li>Learn Basic CSS by Building a Cafe Menu</li>
<li>Learn About CSS Colors by Creating a Marker Set</li>
<li>Learn HTML Forms by Building a Registration Form</li>
<li><strong>Certification Project: Build a Survey Form</strong></li>
<li>Learn the CSS Box Model by Building a Rothko Painting</li>
<li>Learn CSS Flexbox by Building a Photo Gallery</li>
<li>Learn Typography by Building a Nutrition Label</li>
<li>Learn Accessibility by Building a Quiz</li>
<li><strong>Certification Project:</strong> Build a Tribute Page</li>
<li>Learn More About CSS Pseudo Selectors by Building a Balance Sheet</li>
<li>Learn Intermediate CSS by Building a Picasso Painting</li>
<li>Learn Responsive Web Design by Building a Piano</li>
<li><strong>Certification Project: Build a Technical Documentation Page</strong></li>
<li>Learn CSS Variables by Building a City Skyline</li>
<li>Learn CSS Grid by Building a Magazine</li>
<li><strong>Certification Project: Build a Product Landing Page</strong></li>
<li>Learn CSS Transforms by Building a Penguin</li>
<li>Learn CSS Animations by Building a Ferris Wheel</li>
<li><strong>Certification Project: Build a Personal Portfolio Webpage</strong></li>
</ol>
<p>It's free and self-paced, and <a target="_blank" href="https://www.freecodecamp.org/learn/2022/responsive-web-design/">you can check it out here</a>.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>If you're not already using a responsive website design, it's time to make the switch. </p>
<p>A responsive website is essential for delivering a positive user experience, and that's important for keeping your customers happy. </p>
<p>In addition, responsive design can help improve your search engine ranking, which can lead to more traffic and more customers. </p>
<p>With so many benefits, there's no reason not to make the switch to a responsive website design.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Learn HTML – Responsive Web Design Study Guide ]]>
                </title>
                <description>
                    <![CDATA[ HTML (HyperText Markup Language) is an important markup language for building websites. HTML represents the content of the web page. But when you are learning this information for the first time, it can be hard to keep track of all of the different H... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/freecodecamp-responsive-web-design-study-guide/</link>
                <guid isPermaLink="false">66b8d94ace55d3ba4d93598f</guid>
                
                    <category>
                        <![CDATA[ freeCodeCamp.org ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ responsive design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Jessica Wilkins ]]>
                </dc:creator>
                <pubDate>Mon, 27 Jun 2022 16:41:05 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/06/jackson-sophat-wUbNvDTsOIc-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>HTML (HyperText Markup Language) is an important markup language for building websites. HTML represents the content of the web page.</p>
<p>But when you are learning this information for the first time, it can be hard to keep track of all of the different HTML elements. </p>
<p>In this article, I have created a study guide for the entire <a target="_blank" href="https://www.freecodecamp.org/learn/2022/responsive-web-design/#learn-html-by-building-a-cat-photo-app">Learn HTML by Building a Cat Photo App practice project</a>. This study guide is filled with additional information, links, and videos to help you understand the concepts better. </p>
<p>Feel free to reference this guide as you go through the certification. If you are interested in a detailed introduction into HTML, please read through <a target="_blank" href="https://www.freecodecamp.org/news/what-is-html-what-does-html-stand-for-solved/">this freeCodeCamp HTML article</a>. </p>
<p>Here is the complete list of topics covered. Click on any of the links below to learn more about the topic. </p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><a class="post-section-overview" href="#heading-heading-elements">Heading elements - Steps 1-2, 17, 18,25,33</a></li>
<li><a class="post-section-overview" href="#heading-paragraph-elements">Paragraph elements - Step 3</a></li>
<li><a class="post-section-overview" href="#heading-html-comments">HTML comments - Step 4</a></li>
<li><a class="post-section-overview" href="#heading-main-element">Main element - Step 5</a></li>
<li><a class="post-section-overview" href="#heading-html-indentation">HTML indentation - Step 6</a></li>
<li><a class="post-section-overview" href="#heading-image-elements">Image elements - Steps 7-9, 21,28,29</a></li>
<li><a class="post-section-overview" href="#heading-anchor-elements">Anchor elements - Steps 10-11,63</a></li>
<li><a class="post-section-overview" href="#heading-nesting-anchor-elements-inside-paragraphs">Nesting anchor elements inside paragraphs - Step 12</a></li>
<li><a class="post-section-overview" href="#heading-target-attributes">Target attributes - Step 13</a></li>
<li><a class="post-section-overview" href="#heading-nesting-images-inside-anchor-tags">Nesting images inside anchor tags - Step 14</a></li>
<li><a class="post-section-overview" href="#heading-section-elements">Section elements - Steps 15-16,32</a></li>
<li><a class="post-section-overview" href="#heading-unordered-list-elements">Unordered List elements - Steps 19-20</a></li>
<li><a class="post-section-overview" href="#heading-figure-and-figcaption-elements">Figure and Figcaption elements - Steps 22-23,27,30</a></li>
<li><a class="post-section-overview" href="#heading-emphasis-elements">Emphasis Elements - Step 24</a></li>
<li><a class="post-section-overview" href="#heading-ordered-list-elements">Ordered List elements - Step 26</a></li>
<li><a class="post-section-overview" href="#heading-strong-elements">Strong elements - Step 31</a></li>
<li><a class="post-section-overview" href="#heading-form-elements">Form elements - Steps 34-35</a></li>
<li><a class="post-section-overview" href="#heading-form-text-inputs-and-submit-buttons">Form text inputs and submit buttons  - Steps 36-42</a></li>
<li><a class="post-section-overview" href="#heading-form-radio-buttons">Form radio buttons - Steps 43,47,48</a></li>
<li><a class="post-section-overview" href="#heading-label-elements">Label elements - Steps 44-46,55</a></li>
<li><a class="post-section-overview" href="#heading-fieldset-and-legend-elements">Fieldset and Legend elements - Steps 49-52</a></li>
<li><a class="post-section-overview" href="#heading-form-checkbox-elements">Form checkbox elements - Steps 53-54,56-58</a></li>
<li><a class="post-section-overview" href="#heading-value-and-checked-attributes">Value and checked attributes - Steps 59-60</a></li>
<li><a class="post-section-overview" href="#heading-footer-elements">Footer elements - Steps 61-62</a></li>
<li><a class="post-section-overview" href="#heading-head-and-title-elements">Head and title element - Steps 64-65</a></li>
<li><a class="post-section-overview" href="#heading-lang-attribute">lang attribute - Step 66</a></li>
<li><a class="post-section-overview" href="#heading-doctype">DOCTYPE - Step 67</a></li>
</ul>
<h2 id="heading-additional-html-resources">Additional HTML resources</h2>
<ul>
<li><a target="_blank" href="https://www.youtube.com/watch?v=kUMe1FH4CHE">Learn HTML – Full Tutorial for Beginners (2022)</a></li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=pQN-pnXPaVg">HTML Full Course - Build a Website Tutorial</a></li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=PlxWf493en4">HTML Tutorial - How to Make a Super Simple Website</a></li>
</ul>
<h2 id="heading-heading-elements">Heading elements</h2>
<p>HTML heading elements represent the main heading and subheadings of a web page. </p>
<p>The <code>h1</code> element represents the most important heading and should only be used once per web page.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>I represent the main heading of a web page<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
</code></pre>
<p>The <code>h2</code> element represents the second most important heading on the page.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>I am the second most important heading element<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
</code></pre>
<p>There are a total of six section heading elements. </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>I am the most important heading element<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>I am the second most important heading element<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>I am the third most important heading element<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">h4</span>&gt;</span>I am the fourth most important heading element<span class="hljs-tag">&lt;/<span class="hljs-name">h4</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">h5</span>&gt;</span>I am the fifth most important heading element<span class="hljs-tag">&lt;/<span class="hljs-name">h5</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">h6</span>&gt;</span>I am the least important heading element<span class="hljs-tag">&lt;/<span class="hljs-name">h6</span>&gt;</span>
</code></pre>
<p>This is what it looks like rendered to the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-18-at-9.19.27-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>To learn more about heading elements, please read through this <a target="_blank" href="https://devdocs.io/html/element/heading_elements">DevDocs detailed heading elements explanation</a>. </p>
<h2 id="heading-paragraph-elements">Paragraph elements</h2>
<p>Paragraph elements represent the paragraphs on a web page.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>I love learning with freeCodeCamp. They have thousands of free articles and videos to help me learn how to code.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>This is what it looks like rendered to the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-18-at-9.55.21-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>To learn more about paragraph elements, please read through this <a target="_blank" href="https://devdocs.io/html/element/p">DevDocs <code>p</code> element detailed explanation</a>. </p>
<h2 id="heading-html-comments">HTML comments</h2>
<p>HTML comments can be helpful in code when you need to leave messages for your future self or other developers reading your code. Comments will not be rendered to the web page.</p>
<pre><code class="lang-html"><span class="hljs-comment">&lt;!--I am a comment. I am not displayed on the web page.--&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>I am a paragraph element.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>This is what the result looks like rendered to the web page. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-18-at-10.10.32-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>To learn more about HTML comments, I suggest reading through these helpful articles.</p>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/comment-out-html-code-example/">Comment out HTML – Code Example</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/html-comment-how-to-comment-out-a-line-or-tag-in-html/">HTML Comment – How to Comment Out a Line or Tag in HTML</a></li>
</ul>
<h2 id="heading-main-element">Main element</h2>
<p>The <code>main</code> element is used to group all of the main content of the web page.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>What freeCodeCamp has to offer<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">main</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>The core freeCodeCamp curriculum teaches full stack JavaScript and Python. There are hundreds of lessons to go through to get you ready for an entry level developer job.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>freeCodeCamp has thousands of free articles on their news publication. They also have hundreds of videos on their YouTube channel.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">main</span>&gt;</span>
</code></pre>
<p>This is what the code looks like rendered to the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-18-at-10.34.18-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>To learn more about the <code>main</code> element, please read through this <a target="_blank" href="https://devdocs.io/html/element/main">DevDocs detailed <code>main</code> element explanation</a>. </p>
<h2 id="heading-html-indentation">HTML indentation</h2>
<p>Whenever you have HTML elements nested inside other HTML elements, it's best to use indentation. Nested elements are known as children of their parent element.</p>
<p>Indentation is used to make your code more readable by other developers. To indent your code, you will move the element two spaces to the right. </p>
<p>This is an example <strong>without</strong> indentation. </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">main</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Let's learn about indentation<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>There is no indentation here<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">main</span>&gt;</span>
</code></pre>
<p>But if I edit the code by moving the <code>h2</code> and <code>p</code> elements two spaces to the right, now we have proper indentation.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">main</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Let's learn about indentation<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is indentation<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">main</span>&gt;</span>
</code></pre>
<p>Now we can see that the <code>h2</code> and <code>p</code> elements are children of the <code>main</code> element.</p>
<p>To learn more about HTML indentation and why it is important, please read through <a target="_blank" href="https://www.freecodecamp.org/news/how-to-indent-in-html-and-why-it-is-important/">this helpful indentation article</a>. </p>
<h2 id="heading-image-elements">Image elements</h2>
<p><code>img</code> elements are used to add images to the web page. </p>
<p>The <code>src</code> attribute represents the location of the image and the <code>alt</code> attribute is descriptive text for the image. </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://cdn.freecodecamp.org/curriculum/cat-photo-app/lasagna.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"plate of lasagna"</span>&gt;</span>
</code></pre>
<p>This is the what code looks like rendered to the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-18-at-11.41.23-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>To learn more about the <code>img</code> element, please read through this helpful <a target="_blank" href="https://www.freecodecamp.org/news/img-html-image-tag-tutorial/"><code>img</code> element tutorial</a>. </p>
<h2 id="heading-anchor-elements">Anchor elements</h2>
<p>An anchor element represents a link on the web page. </p>
<p>Here is the basic syntax:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"link-where-you-want-to-go"</span>&gt;</span>anchor text goes here<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
<p>This is what it looks like rendered to the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-25-at-5.10.07-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>You use the <code>href</code> attribute to tell the hyperlink where to go. </p>
<pre><code class="lang-html">href="link-where-you-want-to-go"
</code></pre>
<p>The anchor text is what gets displayed on the screen to users.</p>
<p>Here is an example of an anchor tag that links to freeCodeCamp.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://www.freecodecamp.org/"</span>&gt;</span>freeCodeCamp<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
<p>This is what it looks like rendered to the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-25-at-5.41.36-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>To learn more about HTML anchor elements, I suggest reading through these helpful articles.</p>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/the-html-a-tag-anchor-tag-example-code/">The HTML </a><a> Tag – Anchor Tag Example Code</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/html-a-tag-anchor-link-href-example/">HTML </a><a> Tag – Anchor Link HREF Example</a></li>
</ul>
<h2 id="heading-nesting-anchor-elements-inside-paragraphs">Nesting anchor elements inside paragraphs</h2>
<p>If you want to include links inside your paragraphs, then you can nest anchor tags inside the paragraph tags.</p>
<p>In this example we have the text "I love freeCodeCamp".</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>I love freeCodeCamp<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>If I wanted to turn the word freeCodeCamp into a link, then I would wrap it inside a set of anchor tags.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>I love <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://www.freecodecamp.org/"</span>&gt;</span>freeCodeCamp<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>This is what the result looks like rendered to the screen.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-25-at-8.53.45-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Nesting links inside paragraph tags is helpful when you want to direct your users to additional information concerning the main content on the page.</p>
<p>To learn more about nesting anchor tags inside paragraphs, I suggest reading through this helpful article.</p>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/how-to-turn-text-and-images-into-links-using-html/">HTML Link – How to Turn an Image into a Link and Nest Links Inside Paragraphs</a></li>
</ul>
<h2 id="heading-target-attributes">Target attributes</h2>
<p>You use the <code>target="_blank"</code> attribute inside the opening anchor tag like this:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"website-link-goes-here"</span> <span class="hljs-attr">target</span>=<span class="hljs-string">"_blank"</span>&gt;</span>
</code></pre>
<p>When the user clicks on the link, a new browser tab will automatically open to that page.</p>
<p>In this example, I have nested a link inside a set of paragraph tags to direct people to freeCodeCamp.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>To learn how to code for free, please visit <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://www.freecodecamp.org/learn"</span> <span class="hljs-attr">target</span>=<span class="hljs-string">"_blank"</span>&gt;</span>freeCodeCamp.org<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>When you click on the freeCodeCamp link, then it will open up a new browser tab for you.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/jessica-wilkins/embed/zYRRdmQ" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>To learn more about the target attribute, I suggest reading through this helpful article.</p>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/how-to-open-a-link-in-a-new-tab/">How to Open a Link in a New Tab – HTML target blank Attribute Explained</a></li>
</ul>
<h2 id="heading-nesting-images-inside-anchor-tags">Nesting images inside anchor tags</h2>
<p>In HTML, we can use the <code>&lt;img&gt;</code> element to add images on the page. In this example, we are adding an image of five cats.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">img</span>  <span class="hljs-attr">src</span>=<span class="hljs-string">"https://cdn.freecodecamp.org/curriculum/cat-photo-app/cats.jpg"</span>  <span class="hljs-attr">alt</span>=<span class="hljs-string">"Five cats looking around a field."</span>/&gt;</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-02-at-10.39.02-PM.png" alt="Screen-Shot-2022-06-02-at-10.39.02-PM" width="600" height="400" loading="lazy"></p>
<p>If we wanted to make that image a clickable link, then we can place it inside a set of anchor tags.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://en.wikipedia.org/wiki/Cat"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://cdn.freecodecamp.org/curriculum/cat-photo-app/cats.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Five cats looking around a field."</span>/&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
<p>We can also add the <code>target="_blank"</code> attribute to have that link open up in a new tab.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">target</span>=<span class="hljs-string">"_blank"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://en.wikipedia.org/wiki/Cat"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://cdn.freecodecamp.org/curriculum/cat-photo-app/cats.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Five cats looking around a field."</span> /&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
</code></pre>
<p>When you hover your mouse over the image, you will see the cursor pointer indicating that it is a link directing you to an article about cats.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/jessica-wilkins/embed/XWZYRgy" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<h2 id="heading-section-elements">Section elements</h2>
<p>The <code>section</code> element is used to group sections of content in the HTML document.</p>
<p>Here is an example of the <code>section</code> element.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Let's learn about section elements<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">section</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Defintion<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>The section element is used to group sections of content in the HTML document.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
</code></pre>
<p>This is what the result looks like rendered to the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-25-at-9.34.22-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>To learn more about <code>section</code> elements, please read through this <a target="_blank" href="https://devdocs.io/html/element/section">DevDocs <code>section</code> element detailed explanation</a>. </p>
<h2 id="heading-unordered-list-elements">Unordered List elements</h2>
<p>The <code>ul</code> list element is used to display a list of items in no particular order. The <code>li</code> element represents the individual list item. </p>
<p>Here is an example of a list of food items.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Favorite foods<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Salad<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Pizza<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Burger<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Carrots<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
</code></pre>
<p>This is what it looks like rendered to the screen.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-25-at-10.07.42-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>To learn more about the unordered list element, please read through this helpful article. </p>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/html-bullet-points-how-to-create-an-unordered-list-with-the-ul-tag-example/">HTML Bullet Points – How to Create an Unordered List with the <ul> Tag Example</ul></a></li>
</ul>
<h2 id="heading-figure-and-figcaption-elements">Figure and Figcaption elements</h2>
<p>The <code>figure</code> element represents self contained content which is often used with images and captions. The optional <code>figcaption</code> is a short descriptive text for the image.</p>
<p>In this example, we have an image of five kittens in the grass with a small caption underneath.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">figure</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://cdn.freecodecamp.org/curriculum/cat-photo-app/cats.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Five cats looking around a field."</span> /&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">figcaption</span>&gt;</span>Five kittens looking around in the grass<span class="hljs-tag">&lt;/<span class="hljs-name">figcaption</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">figure</span>&gt;</span>
</code></pre>
<p>This is what it looks like rendered on the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-25-at-10.24.35-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>To learn more about the <code>figure</code> and <code>figcaption</code> elements, please read through <a target="_blank" href="https://devdocs.io/html/element/figure">this helpful DevDocs explanation</a>. </p>
<h2 id="heading-emphasis-elements">Emphasis elements</h2>
<p>The <code>em</code> element is used to place extra emphasis on a section of text. </p>
<p>In this example we have the sentence, "We need to get out of the building now!"</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>We need to get out of the building now!<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>If I wanted to place emphasis on the word now, then I can wrap it in <code>&lt;em&gt;</code> tags.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>We need to get out of the building <span class="hljs-tag">&lt;<span class="hljs-name">em</span>&gt;</span>now<span class="hljs-tag">&lt;/<span class="hljs-name">em</span>&gt;</span>!<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>This is what the result looks like rendered to the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-25-at-10.38.35-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>To learn more about emphasis elements, please read through this helpful DevDocs explanation. </p>
<ul>
<li><a target="_blank" href="https://devdocs.io/html/element/em">The Emphasis element</a></li>
</ul>
<h2 id="heading-ordered-list-elements">Ordered List elements</h2>
<p>The <code>ol</code> element is used to display a list of items in a particular order. The <code>li</code> element represents the individual list item.</p>
<p>Here is an example of a set of steps for a recipe. </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>How to bake a cake<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Directions for recipe<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">ol</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Prep the oven<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Whisk the flour, sugar and cocoa in a bowl<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Mix the milk, vegetable oil, eggs, and vanilla<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Bake for 30 minutes<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Remove from oven, cool for 10 minutes and frost cake<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ol</span>&gt;</span>
</code></pre>
<p>This is what the result looks like rendered on the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-25-at-10.53.18-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>To learn more about ordered list elements, please read through this helpful article. </p>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/ordered-list-in-html-ol-tag-example/">Ordered List in HTML – OL Tag Example</a></li>
</ul>
<h2 id="heading-strong-elements">Strong elements</h2>
<p>Strong elements are sections of text that represent a sense of urgency or seriousness. </p>
<p>In this example we have the following sentence:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Danger! Unsafe area ahead<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>We can use <code>strong</code> tags to emphasize the strong sense of seriousness of the word "Danger".</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span>Danger!<span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span> Unsafe area ahead<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p>Here is what the result looks like rendered to the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-26-at-8.41.09-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-form-elements">Form elements</h2>
<p>Form elements are used to collect data from a user like names and email addresses. Examples of forms might be survey forms or forms to join a mailing list. </p>
<p>Here is the basic syntax for a form:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">"url-where-data-should-be-sent-to"</span>&gt;</span>
  <span class="hljs-comment">&lt;!--inputs go inside here--&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<p>The <code>action</code> attribute is the URL of where the user data will be sent. Inside the <code>form</code> tags, there will be inputs which is where the user provides their information. </p>
<p>Inputs will be covered more in the next section. </p>
<h2 id="heading-form-text-inputs-and-submit-buttons">Form text inputs and submit buttons</h2>
<p>The text <code>input</code> is a text field where users can enter in their information. These inputs go inside the <code>form</code> element. </p>
<p>Here is the basic syntax:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">"url-where-data-should-be-sent-to"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<p><code>type="text"</code> tells the computer that this is a text input. </p>
<p>Here is what the result looks like rendered to the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-26-at-9.44.59-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The <code>name</code> attribute is used to represent the value of the data being submitted. </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"username"</span>&gt;</span>
</code></pre>
<p>The <code>placeholder</code> text is used to provide users information on what should go inside the text inputs. </p>
<p>In this example, the placeholder text shows users an example username. Once you start typing in the input, the placeholder text disappears. </p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"username"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Ex.codergirlrules"</span>&gt;</span>
</code></pre>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/jessica-wilkins/embed/oNqvBmb" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>The submit button is used to submit the form information to the server. <code>type="submit"</code> tells the computer what type of button it is.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>&gt;</span>Submit form<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<p>The <code>required</code> attribute is used to ensure that a user has to fill out the required inputs before submitting the form. If you try to submit a form without completing the required inputs then a message will pop up directing you to fill out that information.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">required</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"username"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Ex.codergirlrules"</span>&gt;</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-26-at-10.00.04-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>To learn more about form inputs, please read through this article.</p>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/html-form-input-type-and-submit-button-example/">HTML Form – Input Type and Submit Button Example</a></li>
</ul>
<h2 id="heading-form-radio-buttons">Form radio buttons</h2>
<p>Radio buttons represent a group of options that a user can choose from. Only one option in that group can be selected at a time. </p>
<p>Here is the basic syntax:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span>&gt;</span>
</code></pre>
<p>This is what it looks like rendered to the screen.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-26-at-10.20.33-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>In this example we are using a group of radio buttons where the user can choose between beef, chicken, fish or other. When using a group of radio buttons, all of the buttons in the group must have the same value for the <code>name</code> attribute. </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"beef"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"food"</span>&gt;</span>Beef
<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"chicken"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"food"</span>&gt;</span>Chicken
<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"fish"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"food"</span>&gt;</span>Fish
<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"other"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"food"</span>&gt;</span>Other
</code></pre>
<p>Try out the example below and notice how you can only select one option at a time. Notice how all of the inputs have the same  <code>name="food"</code> value. </p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/jessica-wilkins/embed/yLKBPzE?editors=1000" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>You can learn more about the radio buttons by reading through <a target="_blank" href="https://devdocs.io/html/element/input/radio">this DevDocs radio button documentation</a>. </p>
<h2 id="heading-label-elements">Label elements</h2>
<p>The <code>label</code> element associates the label text with the input. </p>
<p>Here is an example of using the <code>label</code> element to associate the text of "Beef" with the input.  </p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"beef"</span>&gt;</span>Beef<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"beef"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"food"</span>&gt;</span>
</code></pre>
<p>The <code>for</code> attribute is used to connect the label to the input so when a user clicks on the label text it will select the input. The value of the <code>for</code> attribute is the same as the <code>id</code> of the input. </p>
<p>Try out the example below by clicking on the label text. You will see that the radio input is selected. </p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/jessica-wilkins/embed/vYRBWdG?editors=1000" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>You can also nest the input inside the <code>label</code> element. In this case you do not need to use the <code>for</code> attribute because the association between the two elements is implicit.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">label</span>&gt;</span>Beef
    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"beef"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"food"</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
</code></pre>
<p>To learn more about the <code>label</code> element, please read through this helpful article.</p>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/html-label-label-tag-example/">HTML Label – Label Tag Example</a></li>
</ul>
<h2 id="heading-fieldset-and-legend-elements">Fieldset and Legend elements</h2>
<p>The <code>fieldset</code> element is used to group form controls which are inputs and labels. The <code>legend</code> element is used to provide a caption for the <code>fieldset</code> element. </p>
<p>Here is an example of the <code>fieldset</code> element:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">""</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">fieldset</span>&gt;</span>

  <span class="hljs-tag">&lt;/<span class="hljs-name">fieldset</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<p>This is what it looks like rendered to the screen.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-26-at-11.42.04-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Here is an example of the <code>legend</code> element:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">""</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">fieldset</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">legend</span>&gt;</span>Choose your favorite programming language<span class="hljs-tag">&lt;/<span class="hljs-name">legend</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">fieldset</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<p>This is what it looks like rendered to the screen.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-26-at-11.43.51-PM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Here is the complete example of how the <code>fieldset</code> and <code>legend</code> elements work with form inputs and labels. </p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">""</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">fieldset</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">legend</span>&gt;</span>Choose your favorite programming language<span class="hljs-tag">&lt;/<span class="hljs-name">legend</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"JavaScript"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"programming"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"JavaScript"</span>&gt;</span>JavaScript<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"Python"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"programming"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"Python"</span>&gt;</span>Python<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"radio"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"Rust"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"programming"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"Rust"</span>&gt;</span>Rust<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">fieldset</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/jessica-wilkins/embed/GRxKypM?editors=1000" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<h2 id="heading-form-checkbox-elements">Form checkbox elements</h2>
<p><code>checkbox</code> elements are boxes where a user can select multiple options in a form. </p>
<p>Here is an example of a checkbox:</p>
<pre><code class="lang-html">    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"checkbox"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"London"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"London"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"London"</span>&gt;</span>London<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
</code></pre>
<p>This is what is looks like rendered to the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-27-at-12.14.29-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Here is a full example using multiple checkboxes for different cities.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">""</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">fieldset</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">legend</span>&gt;</span>Cities you would like to visit<span class="hljs-tag">&lt;/<span class="hljs-name">legend</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"checkbox"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"London"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"London"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"London"</span>&gt;</span>London<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"checkbox"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"Barcelona"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"Barcelona"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"Barcelona"</span>&gt;</span>Barcelona<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"checkbox"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"Venice"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"Venice"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"Venice"</span>&gt;</span>Venice<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"checkbox"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"Tokyo"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"Tokyo"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"Tokyo"</span>&gt;</span>Tokyo<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">fieldset</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
</code></pre>
<p>Try out the example below and you will be able to select multiple options.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/jessica-wilkins/embed/wvmwpeE?editors=1000" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>To learn more about checkbox elements, please read through <a target="_blank" href="https://devdocs.io/html/element/input/checkbox">the DevDocs checkbox documentation</a>. </p>
<h2 id="heading-value-and-checked-attributes">Value and checked attributes</h2>
<p>The <code>value</code> attribute represents the value for the input. </p>
<p>Here is an example.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"checkbox"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"London"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"London"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"London"</span>&gt;</span>
</code></pre>
<p>The checked attribute is used to indicate which inputs should be checked by default on page load. </p>
<p>Here is an example. </p>
<pre><code class="lang-html">    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"checkbox"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"London"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"London"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"London"</span> <span class="hljs-attr">checked</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">"London"</span>&gt;</span>London<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
</code></pre>
<p>Here is what the result looks like rendered to the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/Screen-Shot-2022-06-27-at-12.42.20-AM.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-footer-elements">Footer elements</h2>
<p>The <code>footer</code> element is located at the bottom of the HTML document and contains information like copyrights, or links to other related information for the page. </p>
<p>Here is a basic example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">footer</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>© 2022 Jessica Wilkins<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">footer</span>&gt;</span>
</code></pre>
<p>To learn more about the <code>footer</code> element, please read through <a target="_blank" href="https://devdocs.io/html/element/footer">this DevDocs explanation of the <code>footer</code> element</a>. </p>
<h2 id="heading-head-and-title-elements">Head and title elements</h2>
<p>The <code>&lt;head&gt;</code> tags contain information that is processed by machines. Inside the <code>&lt;head&gt;</code> tags, you will nest metadata which is data that describes the document to the machine.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-comment">&lt;!--important meta data goes inside here--&gt;</span>
  <span class="hljs-comment">&lt;!--title element also goes inside here--&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
</code></pre>
<p>The <code>&lt;title&gt;</code> tag is the title for the web page. This text is shown in the browser's title bar.</p>
<pre><code class="lang-html">    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>HTML 5 Boilerplate<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/07/Screen-Shot-2021-07-30-at-4.15.25-AM.png" alt="Screen-Shot-2021-07-30-at-4.15.25-AM" width="600" height="400" loading="lazy"></p>
<p>This is an example of what a <code>head</code> would look like on a real web page. None of this information is displayed on the web page itself. </p>
<pre><code class="lang-html"> <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"X-UA-Compatible"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"ie=edge"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>HTML 5 Boilerplate<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"style.css"</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
</code></pre>
<p>For a detailed description of each meta tag listed, please read through <a target="_blank" href="https://www.freecodecamp.org/news/basic-html5-template-boilerplate-code-example/">this article on an HTML5 Boilerplate</a>.</p>
<h2 id="heading-lang-attribute"><code>lang</code> attribute</h2>
<p>The <code>lang</code> attribute inside the opening <code>&lt;html&gt;</code> tag sets the language for the page. It is also good to include it for accessibility reasons, because screen readers will know how to properly pronounce the text.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
</code></pre>
<h2 id="heading-doctype">DOCTYPE</h2>
<p>The first line in your HTML code should be the doctype declaration. A doctype tells the browser what version of HTML the page is written in.</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
</code></pre>
<p>If you forget to include this line of code in your file, then some of the HTML 5 tags like <code>&lt;article&gt;</code>, <code>&lt; footer &gt;</code>, and <code>&lt;header&gt;</code>  may not be supported by the browser.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ CSS REM – What is REM in CSS? ]]>
                </title>
                <description>
                    <![CDATA[ By Sliman In this article I'm going to discuss some use cases of REM (Root EM) in CSS.  I will begin with some background knowledge about CSS properties and values, which I think is necessary. Then I'll discuss the differences between absolute length... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-rem-in-css/</link>
                <guid isPermaLink="false">66d460ee3bc3ab877dae222e</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ responsive design ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 17 Mar 2022 19:47:22 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/03/rem-in-css-cover-image.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Sliman</p>
<p>In this article I'm going to discuss some use cases of REM (Root EM) in CSS. </p>
<p>I will begin with some background knowledge about CSS properties and values, which I think is necessary. Then I'll discuss the differences between absolute length values and relative ones. REM is a relative length value. </p>
<p>In the last two parts I discuss why REM is useful with regard to font size, and how it can help make webpages responsive. Let's get to it. </p>
<h2 id="heading-what-you-need-to-know">What you need to know</h2>
<p>In this section I will first say a few things about CSS, as a way of introduction. </p>
<h3 id="heading-what-is-css">What is CSS?</h3>
<p>CSS (which stands for Cascading Style Sheets) uses properties and values to create all the aesthetic magic that goes on in webpages. </p>
<p>Say, you want to enhance your image with a beautifully crafted border, and you want the edges to be a solid black line. In this case <code>border</code> would be the property to choose, and <code>solid</code> the value. This is a keyword in CSS that instructs it to create the desired solid border.</p>
<p>As you may have guessed, there must be different kinds of these values, seeing that merely a solid line as a border is not much of an adornment. </p>
<p>The property <code>border</code> indeed accepts keywords, colors, and lengths. Actually, this is because <code>border</code> is shorthand for <code>border-width</code>, <code>border-style</code> and <code>border-color</code>. So instead of specifying each of these properties, <code>border</code> accepts these values for all of them at once, like so:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">border</span>: 2<span class="hljs-selector-tag">px</span> <span class="hljs-selector-tag">solid</span> <span class="hljs-selector-id">#ffff00</span>;
</code></pre>
<p>In the code snippet above, you see the value <code>2px</code> which is a length value, <code>solid</code> which is a keyword for the styling of the border, and the RGB hex value <code>#ffff00</code> of the color yellow. Now that's a nice border (not really, I know, but I made my point).</p>
<p>One last thing about these values before we get down to business. Different properties have different kinds of values that are applicable to them. These collections of values are aptly called <code>value types</code> (a.k.a. <code>data types</code>). </p>
<p>Let me clarify with a last example: <code>color</code> is a value type, and the RGB hex value <code>#ffff00</code> (which represents the color yellow) is a specific value of this value type. If you need to, think of the value types as types and the values as tokens of these types. </p>
<p>So if you ever need to know which values a specific property accepts, just search for its <code>value types</code>, and you're covered.  </p>
<h3 id="heading-what-is-rem-in-css">What is REM in CSS?</h3>
<p>This article is about one of these values, namely REM, which stands for Root EM. REM is a value of the value/ data type <code>length</code>. Another value of <code>length</code> is our good old friend pixel (<code>px</code>). Every property that accepts lengths as a value will accept REM. Some of these are <code>margin</code>, <code>padding</code>, and so on. </p>
<p>You might wonder why you should consider using REM? Let's see why in the next section.</p>
<h2 id="heading-relative-values-vs-absolute-length-values-in-css">Relative Values vs Absolute Length Values in CSS</h2>
<p>There are two types of length values in CSS: absolute length values and relative length values. </p>
<h3 id="heading-absolute-length-values">Absolute length values</h3>
<p>Examples of absolute length values are: <code>px</code> (which is 1/96th of an inch), <code>in</code> (an inch) or <code>cm</code> (which is 37.8px or 25.2/64in). You can find more information about these values in the <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units">MDN</a>. </p>
<p>When you use these length values you can be sure that they will always be more or less the same size. This is especially useful when you know the exact dimensions of the output, which is mostly with print layouts. But it's not so useful when this is not the case, like with all the different screen sizes out there. </p>
<p>And don't forget the possible different browser settings people use, either because of preferences or accessibility needs. </p>
<h3 id="heading-relative-length-values">Relative length values</h3>
<p>Relative length values are defined in terms of some other value. These are, for example, <code>REM</code>, <code>EM</code>, and <code>vw</code>. We are going to discuss <code>REM</code> in detail below, so lets discuss the others briefly. </p>
<p><code>EM</code> is defined relative to:</p>
<ul>
<li>the font size of the parent element when the property <code>font-size</code> is concerned, and </li>
<li>the font size of the element itself when we're dealing with other properties like <code>height</code>. </li>
</ul>
<p><code>vw</code> stands for 1% viewport width. That is to say that if you define the <code>width</code> property as 10vw, the element will take up 10% of the available viewport's width. There are many more, and you can find them <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units">here</a>. </p>
<p>These relative length values have a clear advantage above the absolute ones, because they can help make your website responsive. That is to say, your website automatically adapts to the size of the available screen size, doing so in a predictable way.     </p>
<h2 id="heading-root-em-and-root-font-size">Root EM and Root Font Size</h2>
<p>REM is defined relative to the font size of the root element. The root element is matched by the <code>:root</code> pseudo-class or the <code>html</code> selector. </p>
<p><code>1rem</code> therefore takes on the value which is given to the <code>font-size</code> of the root element. This means that 1 REM keeps the same value throughout your whole CSS code. If the root element's font size is not changed by the user this value is normally <code>16px</code>. </p>
<p>Here's an example:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">html</span> {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">18px</span>; // default value would be 16
}

<span class="hljs-selector-tag">h1</span> {
     <span class="hljs-attribute">font-size</span>: <span class="hljs-number">2rem</span>; // 2 * 18px = 36px;
}
</code></pre>
<p>Reasoning backwards from <code>2rem</code> to <code>px</code> is not a hard task. But do you need to keep a calculator nearby to know the exact font size of your sub-heading which you set to 1.125rem (that's: 16 * 1.125: <code>18px</code>)? </p>
<p>Thankfully there is a clever way of dealing with this problem. Keeping in mind that you can also specify the font size of the root element with a percentage (%), developers have found that 62.5% of the default value of the root element equals <code>10px</code>. This simplifies things really nicely:</p>
<pre><code>html {
    font-size: <span class="hljs-number">62</span>,<span class="hljs-number">5</span>%; <span class="hljs-comment">// 16px * 0.625 = 10px;</span>
}

h1 {
    font-size: <span class="hljs-number">1.8</span>rem; <span class="hljs-comment">// 10px * 1.8 = 18px;</span>
}
</code></pre><p>Using REM (or another relative length value) for <code>font-size</code> is a must for accessibility, because <code>px</code> in some browsers doesn't resize when the browser settings are changed. </p>
<p>Some people, for example, need to zoom maybe up to 400% to be able to read your text, due to a visual impairment. Using REM you make sure that your text respects these needs, because the font-size is defined relative to the default font-size a user has chosen.   </p>
<h2 id="heading-responsive-web-design-with-rem">Responsive Web Design with REM</h2>
<p>Let me first say that responsive web-design is an extensive subject, with many different aspects. There are two certificates about responsive web design in freeCodeCamp's curriculum (check these out at <a target="_blank" href="https://www.freecodecamp.org/learn">https://www.freecodecamp.org/learn</a>, if you're interested). </p>
<p>Below I'm going to concentrate on how REM can help with making webpages responsive.</p>
<p>Google encourages you, in this <a target="_blank" href="https://web.dev/responsive-web-design-basics/#optimize-text-for-reading">article</a> about responsive web design, to restrict line length to not much more than 10 words. This is in accordance with classical readability theory. </p>
<p>They advise that you should use media queries with break points chosen in such a manner that the width of your content/text lines are not too long. This helps provide the best possible reading experience. </p>
<p>Here is an example inspired by <a target="_blank" href="https://www.sitepoint.com/understanding-and-using-rem-units-in-css/">this</a> article by Adrian Sandu:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">html</span> {
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">62.5%</span>;
}

<span class="hljs-selector-id">#divOne</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
  <span class="hljs-attribute">box-sizing</span>: border-box;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1.6rem</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0.5rem</span>;
  <span class="hljs-attribute">background-color</span>: lightblue;
}

<span class="hljs-keyword">@media</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">27.1875rem</span>) { // <span class="hljs-selector-tag">first</span> <span class="hljs-selector-tag">breakpoint</span>: 27<span class="hljs-selector-class">.1875</span>*16<span class="hljs-selector-tag">px</span>= 435<span class="hljs-selector-tag">px</span> 
  <span class="hljs-selector-tag">p</span> {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1.6rem</span>;
  }
<span class="hljs-selector-id">#divOne</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">41.8rem</span>;
  <span class="hljs-attribute">background-color</span>: yellow;
  <span class="hljs-attribute">margin</span>: auto;
  }
}

<span class="hljs-keyword">@media</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">40.78125rem</span>) { 1<span class="hljs-selector-class">.5</span> * <span class="hljs-selector-tag">first</span> <span class="hljs-selector-tag">breakpoint</span>: 653<span class="hljs-selector-tag">px</span>
  <span class="hljs-selector-tag">p</span> {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">2.4rem</span>; // 1.5 * font-size first breakpoint
  }
<span class="hljs-selector-id">#divOne</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">62.7rem</span>; // 1.5 * width of first breakpoint
  <span class="hljs-attribute">background-color</span>: green;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0.75rem</span>; // 1.5 * padding of first break point
  <span class="hljs-attribute">margin</span>: auto;
  }
}
</code></pre>
<p>You can check this code out <a target="_blank" href="https://codepen.io/slimattcode/pen/jOaJrjZ?editors=0100">here</a> on CodePen. Change the size of your view port to see how the layout changes.</p>
<p>One thing that might stand out to you in the code above is that the value of  <code>1rem</code> in the defined media queries is always <code>16px</code>.  <code>1rem</code> inside the media query blocks follows the root definition of <code>font-size</code> of 62.5% of <code>16px</code>, which is <code>10px</code> as we found earlier. </p>
<p>This behavior is caused by the fact that REM inside media queries always takes the default value of the browser font size, which is often <code>16px</code>. However if the user changes this default browser setting, REM will take that value. This means that the accessibility preferences a user might have specified are accommodated.  </p>
<p>The code takes a mobile first design approach. The first breakpoint I have defined at <code>435px</code>. Notice that the width of the text after this breakpoint never changes, but the ratio of the values around it changes in proportion, 1.5 to be exact. Below are illustrations of each step: </p>
<p>The layout when viewport is smaller than 435px:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/03/Capture-1.JPG" alt="Image" width="600" height="400" loading="lazy">
<em>Container takes 100% width for mobile screens</em></p>
<p>The layout when viewport is between <code>435px</code> and <code>652px</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/03/Capture1.JPG" alt="Image" width="600" height="400" loading="lazy">
<em>Container keeps text at approximately 10 words per line</em></p>
<p>The layout when viewport is greater than <code>652px</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/03/Capture2.JPG" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this article we have explored the use of REM in CSS. We saw that REM is a relative length value which can be utilized to make a logical schema of the font sizes inside your webpages.</p>
<p>Using it your webpages also makes them accessible to people who need to change the default <code>font-size</code> value of the browser to suit their needs. </p>
<p>Lastly we explored how REM can help you make a webpage responsive, while also making allowances for the possible default setting changes made by users who need/ prefer other settings. </p>
<p>While writing this, I have greatly benefited from these articles:</p>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/learn-css-units-em-rem-vh-vw-with-code-examples/">Learn CSS Units – Em, Rem, VH, and VW with Code Examples</a>, by Joy Shaheb</li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/css-unit-guide/">CSS Unit Guide: CSS em, rem, vh, vw, and more, Explained</a>, from freeCodeCamp</li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/em-units-versus-rem-units-fight-382c16af8a67/">CSS Unit Battle: EMs Vs. REMs…FIGHT!</a>, by ZAYDEK</li>
<li><a target="_blank" href="https://www.sitepoint.com/understanding-and-using-rem-units-in-css/">Rem in CSS: Understanding and Using rem Units</a>, by Adrian Sandu</li>
<li><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units">CSS values and units</a>, <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/length"></a>, <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/font-size">font-size</a>, by MDN</li>
<li><a target="_blank" href="https://web.dev/accessible-responsive-design/">Accessible responsive design</a>, by Dave Gash, Meggin Kearney, Rachel Andrew, Rob Dodson</li>
<li><a target="_blank" href="https://web.dev/responsive-web-design-basics/">Responsive web design basics</a>, by Pete LePage and Rachel Andrew</li>
</ul>
<p>Cover photo by <strong><a target="_blank" href="https://www.pexels.com/nl-nl/@sora-shimazaki?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Sora Shimazaki</a></strong> via Pexels.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Learn Responsive Web Design by Building 20 Projects – a Major freeCodeCamp Curriculum Update ]]>
                </title>
                <description>
                    <![CDATA[ We just published a significant overhaul of our Responsive Web Design Certification (the first of freeCodeCamp's 10 currently-live certifications). We also updated our code editor. Instead of coding lessons, you'll learn concepts and syntax through a... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/responsive-web-design-certification-redesigned/</link>
                <guid isPermaLink="false">66b8d564d482a18d3e028250</guid>
                
                    <category>
                        <![CDATA[ education ]]>
                    </category>
                
                    <category>
                        <![CDATA[ freeCodeCamp.org ]]>
                    </category>
                
                    <category>
                        <![CDATA[ freeCodeCamp Curriculum ]]>
                    </category>
                
                    <category>
                        <![CDATA[ responsive design ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Quincy Larson ]]>
                </dc:creator>
                <pubDate>Mon, 27 Dec 2021 22:16:19 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/12/Learn_CSS_Transforms_by_Building_a_Penguin__Step_104___freeCodeCamp_org-1.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>We just published a significant overhaul of our Responsive Web Design Certification (the first of freeCodeCamp's 10 currently-live certifications). We also updated our code editor.</p>
<p>Instead of coding lessons, you'll learn concepts and syntax through a series of 15 practice projects + 5 certification projects.</p>
<p>Here is the full certification, which we estimate will take most web development beginners around 300 hours to complete:</p>
<ol>
<li>Learn HTML by Building a Cat Photo App</li>
<li>Learn Basic CSS by Building a Cafe Menu</li>
<li>Learn About CSS Colors by Creating a Marker Set</li>
<li>Learn HTML Forms by Building a Registration Form</li>
<li><strong>Certification Project: Build a Survey Form</strong></li>
<li>Learn the CSS Box Model by Building a Rothko Painting</li>
<li>Learn CSS Flexbox by Building a Photo Gallery</li>
<li>Learn Typography by Building a Nutrition Label</li>
<li>Learn Accessibility by Building a Quiz</li>
<li><strong>Certification Project:</strong> Build a Tribute Page</li>
<li>Learn More About CSS Pseudo Selectors by Building a Balance Sheet</li>
<li>Learn Intermediate CSS by Building a Picasso Painting</li>
<li>Learn Responsive Web Design by Building a Piano</li>
<li><strong>Certification Project: Build a Technical Documentation Page</strong></li>
<li>Learn CSS Variables by Building a City Skyline</li>
<li>Learn CSS Grid by Building a Magazine</li>
<li><strong>Certification Project: Build a Product Landing Page</strong></li>
<li>Learn CSS Transforms by Building a Penguin</li>
<li>Learn CSS Animations by Building a Ferris Wheel</li>
<li><strong>Certification Project: Build a Personal Portfolio Webpage</strong></li>
</ol>
<p>Note that in order to obtain the Responsive Web Design Certification, you only need to build <strong>the 5 certification projects in bold</strong> and get their test suites to pass. The rest of this coursework is optional.</p>
<p>We have sprinkled these certification projects throughout. They are open-ended. You start with a blank code editor and build the project line-by-line to ultimately get the entire test suite to pass. Note that currently we still use CodePen for these projects, but in early January 2022 we will move these over to our own code editor.</p>
<p>Also note that the 5 certification projects are the same as in the old version of this certification. Everything is fully backward-compatible, and <strong>you do not need to re-do any of these projects if you have already done them</strong>.</p>
<p>Also note that any older certifications you have earned will continue to remain valid going forward. You do not need to worry about broken links on your résumé or LinkedIn profile.</p>
<h2 id="heading-how-the-new-practice-projects-work-our-new-code-editor">How the New Practice Projects Work: Our New Code Editor</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/12/Learn_Typography_by_Building_a_Nutrition_Label__Step_66___freeCodeCamp_org_--.png" alt="Image" width="600" height="400" loading="lazy">
<em>I manually annotated some of the features of the new code editor. This is where you will build the practice projects line-by-line, getting tests to pass along the way.</em></p>
<p>I initially had the idea for this design in 2017. That is how long we've been building and iterating on this. But I am thrilled with the how this came out.</p>
<p>Each step in a practice project has its own tests. And we also have context-specific hints. These will help subtly point you in the right direction without completely giving away the answer.</p>
<p>Once you get the tests for the step to pass, you will seamlessly move to the next step, and we scroll you to the part of your codebase where you need to add your next line of code.</p>
<p>Our goal is for you to be able to get into a flow state and stay there. We want you to blast through dozens of these steps – or entire projects – in a single coding session.</p>
<p>We've built a multi-file editor, and you will be able to code fairly complicated front end projects inside of it.</p>
<p>Soon we we'll roll out our full sandbox, and you'll be able to use this to build your various certification projects. No more need to use CodePen or JSBin – everything will run right on freeCodeCamp.org.</p>
<h2 id="heading-weve-incorporated-tons-of-feedback-and-user-experience-lessons-weve-learned-over-the-years">We've incorporated tons of feedback and User Experience lessons we've learned over the years.</h2>
<p>In addition to the new code editor, the main improvements we've added are:</p>
<h3 id="heading-more-practice">More practice</h3>
<p>The curriculum now has far more projects, which will walk you through writing thousands of lines of code. </p>
<p>These will keep you in a tight feedback loop – with failing tests, error messages, and hints – the entire way through.</p>
<p>At the beginning of each project, we also give you a preview of what you will build.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/12/Learn_CSS_Transforms_by_Building_a_Penguin__Step_1___freeCodeCamp_org.png" alt="Image" width="600" height="400" loading="lazy">
<em>A preview of one of the projects you'll build – a CSS penguin.</em></p>
<h3 id="heading-more-repetition-to-help-with-retention">More repetition to help with retention</h3>
<p>Our original goal was to give people broad, rapid-fire exposure to key programming concepts. But a lot of feedback we received was that we were moving too fast.</p>
<p>Most people seem to prefer to take things slower, and get a lot more practice with each of these technologies.</p>
<p>This newly updated curriculum will give you a lot more practice to help you better retain key concepts and programming syntax.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/12/Responsive_Web_Design__Beta__Certification___freeCodeCamp_org-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>Each project has a table of steps. Completed steps are highlighted in blue. You can skip to any step at any time, but we recommend doing them in order.</em></p>
<h3 id="heading-less-reading-more-coding">Less Reading. More Coding.</h3>
<p>It took an incredible amount of work, but we were able to restructure the curriculum to teach you "just in time" with only a few sentences of explanation at a time. Here is the general "core gameplay loop" of the curriculum:</p>
<p>Read a few sentences -&gt; figure out what your next line of code should look like and type it in -&gt; Run the tests and get them to pass -&gt; repeat this process 1,000s of times</p>
<p>Here's what a typical step looks like:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/12/Learn_CSS_Transforms_by_Building_a_Penguin__Step_16___freeCodeCamp_org.png" alt="Image" width="600" height="400" loading="lazy">
<em>Each step will take you to the part of your code where you need to add a new line of code or change existing code. And it will have lots of tests. Depending on which tests fail, it will give you a context-specific hint to help you get unstuck and keep moving forward.</em></p>
<h3 id="heading-minibosses-sprinkled-throughout-the-levels">"Minibosses" sprinkled throughout the levels</h3>
<p>There's another major improvement we made. Before, you would do all 5 of a certification's big projects at the end, after you'd completed all the lessons.</p>
<p>Now you will tackle these certification projects periodically as you learn new technologies. So after 3 or 4 practice projects, which have more guided tests, you'll face a blank code editor and 10 or more "user story" tests. You will have to figure out how to get each of those tests passing using the skills you've just learned.</p>
<p>We are optimistic that this will smooth out the difficulty associated with earning these certifications. And it will help further reinforce your skills and your retention, by shortening the time in between when you learn them and when you have to recall them and apply them.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/12/Responsive_Web_Design__Beta__Certification___freeCodeCamp_org_---2.png" alt="Image" width="600" height="400" loading="lazy">
<em>You can see how many steps will be in each project and how many of them you have completed. The certifications – "minibosses" – are a single step. These are essentially an empty code editor with a test suite. You have to code the entire project yourself get all of its tests to pass.</em></p>
<h2 id="heading-you-can-try-the-new-responsive-web-design-certification-now">You can try the new Responsive Web Design Certification now</h2>
<p>It is still in beta. If you get stuck, I encourage you to ask for help on the freeCodeCamp forum. Who knows – you might discover a bug. This will be under active development.</p>
<p>We will finish building the updated JavaScript Algorithms &amp; Data Structures certification in 2022. And we will publish the updated Front End Libraries certification after that.</p>
<p>If you are ready, you can dive right into the new <a target="_blank" href="https://www.freecodecamp.org/learn/2022/responsive-web-design/">Responsive Web Design Certification</a>.</p>
<p>Happy coding.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
