Mobile-first approach with HTML and CSS
Tags: html, css, mobile, webdev
Published: 2023-07-08 09:04:47

`<section class="max-w-3xl mx-auto py-6 lg:py-12 content">
              <blockquote><p>In today’s digital landscape, the mobile-first approach has gained significant importance in web design and development. By adopting a mobile-first approach with HTML and CSS, you prioritize the needs of mobile users and ensure your website delivers a seamless and engaging experience on small screens. This article will explain the principles and benefits of mobile-first design and implementing specific strategies with HTML and CSS so you can apply the methodology.</p></blockquote>
<p>The <a href="https://www.browserstack.com/guide/how-to-implement-mobile-first-design">mobile-first approach</a> is a design and development approach focusing on creating a user-friendly experience for mobile devices like smartphones and tablets. Unlike the traditional method of starting with desktop design and adapting it for mobile, the mobile-first approach begins with designing specifically for mobile devices and then expanding to larger screens. This approach ensures that the needs of mobile users are prioritized, considering the widespread usage of mobile devices in today’s digital world. It is an excellent approach to creating a responsive design.</p>
<p>The mobile-first approach is essential for several reasons:</p>
<ul>
<li>
<p>It ensures developers prioritize performance optimization, resulting in faster load times, reduced data usage, and a smoother experience for mobile users.</p>
</li>
<li>
<p>It enables websites and applications to adapt and scale quickly across different devices and screen sizes.</p>
</li>
<li>
<p>Users can seamlessly navigate and engage with the mobile interface, increasing user satisfaction and engagement.</p>
</li>
<li>
<p>It helps businesses to effectively target and engage with their audience, ensuring seamless experience and interaction.</p>
</li>
<li>
<p>It enables you to concentrate on delivering clear and concise content.</p>
</li>
<li>
<p>It can improve your search engine visibility and drive more organic traffic to your site.</p>
</li>
</ul>
<h2 id="fundamental-principles-of-the-mobile-first-approach">Fundamental principles of the mobile-first approach</h2>
<p><a href="https://www.uxpin.com/studio/blog/a-hands-on-guide-to-mobile-first-design/">Several principles</a> can help shape the design and development process of the mobile-first approach. They include:</p>
<ol>
<li>
<p>The mobile-first approach involves designing for the smallest screen and working your way up. Focusing on mobile users first is essential to carefully tailor the user experience to optimize smaller screens and accommodate touch-based interactions.</p>
</li>
<li>
<p>Identify core elements mobile users need to create an efficient, clutter-free experience. For example, prioritize straightforward navigation, user-friendly forms, responsive media, mobile-specific interactions, and prominent call-to-action buttons as core elements for mobile users.</p>
</li>
<li>
<p>Optimize performance by minimizing file sizes and employing techniques like lazy loading to enhance speed and responsiveness.</p>
</li>
<li>
<p>Implement responsive design techniques to ensure your website or application adapt seamlessly to different screen sizes and devices.</p>
</li>
<li>
<p>Designing intuitive touch-based interfaces is a fundamental aspect of the mobile-first approach, leveraging natural gestures like tapping, swiping, and pinching to enhance user-friendliness.</p>
</li>
<li>
<p>Begin with a solid foundation for the mobile experience and then enhance it for larger screens and more powerful devices. This approach allows you to add extra features and optimize the design for desktop users without compromising the core mobile experience.</p>
</li>
</ol>
<h2 id="structuring-html">Structuring HTML</h2>
<p>You can effectively implement a mobile-first approach with HTML and CSS, ensuring a responsive and user-friendly design for mobile devices while accommodating larger screens and providing a seamless cross-device experience. Structuring HTML is an essential aspect of building a mobile-first approach. Here are ways to do that better:</p>
<ul>
<li>
<p>Start with a well-organized HTML structure, including the doctype declaration (<code>&lt;!DOCTYPE html&gt;</code>) and semantic elements like <code>&lt;html&gt;</code>, <code>&lt;head&gt;</code>, and <code>&lt;body&gt;</code>.</p>
</li>
<li>
<p>Utilize semantic HTML tags for effective content structure, such as using <code>&lt;h1&gt;</code> to <code>&lt;h6&gt;</code> for headings based on hierarchy, <code>&lt;nav&gt;</code> for navigation menus, <code>&lt;article&gt;</code> for self-contained content, and <code>&lt;section&gt;</code> for grouping related content.</p>
</li>
<li>
<p>Enhance the mobile user experience by incorporating mobile-friendly elements like <code>&lt;input type="tel"&gt;</code> for telephone numbers, <code>&lt;input type="email"&gt;</code> for email addresses, and <code>&lt;input type="date"&gt;</code> for date inputs. These elements facilitate appropriate keyboard layouts and input options.</p>
</li>
<li>
<p>Create a mobile-friendly navigation structure for smaller screens, utilizing techniques like a collapsible menu (<code>&lt;button&gt;</code> with associated <code>&lt;ul&gt;</code> or <code>&lt;nav&gt;</code>), a hamburger icon, or a slide-out panel to ensure easy usability and accessibility.</p>
</li>
<li>
<p>Include accessibility features in your HTML structure, such as <code>alt</code> attributes for images (<code>&lt;img&gt;</code>) and proper labeling for form inputs (<code>&lt;label&gt;</code>), to enhance navigation and understanding of your content for users with disabilities.</p>
</li>
<li>
<p>Improve code readability and navigation by maintaining consistent indentation and using whitespace effectively to enhance the structure and readability of your HTML.</p>
</li>
</ul>
<p>Let’s see an example of how to structure the HTML:</p>
<pre class="astro-code" style="background-color:#0d1117;overflow-x:auto"><code><span class="line"><span style="color:#C9D1D9">&lt;!</span><span style="color:#7EE787">DOCTYPE</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">html</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">&lt;</span><span style="color:#7EE787">html</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">  &lt;</span><span style="color:#7EE787">head</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">    &lt;</span><span style="color:#7EE787">meta</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">charset</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"UTF-8"</span><span style="color:#C9D1D9"> /&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">    &lt;</span><span style="color:#7EE787">meta</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">name</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"viewport"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">content</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"width=device-width, initial-scale=1.0"</span><span style="color:#C9D1D9"> /&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">    &lt;</span><span style="color:#7EE787">title</span><span style="color:#C9D1D9">&gt;My Mobile-First Approach&lt;/</span><span style="color:#7EE787">title</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">  &lt;/</span><span style="color:#7EE787">head</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">  &lt;</span><span style="color:#7EE787">body</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">    &lt;</span><span style="color:#7EE787">header</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">      &lt;</span><span style="color:#7EE787">h1</span><span style="color:#C9D1D9">&gt;My Mobile-First Approach HTML Structuring&lt;/</span><span style="color:#7EE787">h1</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">      &lt;</span><span style="color:#7EE787">nav</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">href</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">""</span><span style="color:#C9D1D9">&gt;Home&lt;/</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">href</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">""</span><span style="color:#C9D1D9">&gt;Shop&lt;/</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">href</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">""</span><span style="color:#C9D1D9">&gt;Contact&lt;/</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">href</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">""</span><span style="color:#C9D1D9">&gt;Store&lt;/</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">      &lt;/</span><span style="color:#7EE787">nav</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">    &lt;/</span><span style="color:#7EE787">header</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">    &lt;</span><span style="color:#7EE787">main</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">      &lt;</span><span style="color:#7EE787">section</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">h2</span><span style="color:#C9D1D9">&gt;About Us&lt;/</span><span style="color:#7EE787">h2</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">p</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">          We work with skilled artisans and select premium materials to craft</span></span>
<span class="line"><span style="color:#C9D1D9">          footwear that stands the test of time</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;/</span><span style="color:#7EE787">p</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">      &lt;/</span><span style="color:#7EE787">section</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">      &lt;</span><span style="color:#7EE787">section</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">h2</span><span style="color:#C9D1D9">&gt;Our Products&lt;/</span><span style="color:#7EE787">h2</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">ul</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">li</span><span style="color:#C9D1D9">&gt;Men's shoes&lt;/</span><span style="color:#7EE787">li</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">li</span><span style="color:#C9D1D9">&gt;Women's Shoes&lt;/</span><span style="color:#7EE787">li</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">li</span><span style="color:#C9D1D9">&gt;Kid's Shoes&lt;/</span><span style="color:#7EE787">li</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;/</span><span style="color:#7EE787">ul</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">      &lt;/</span><span style="color:#7EE787">section</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">      &lt;</span><span style="color:#7EE787">section</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">h2</span><span style="color:#C9D1D9">&gt;Contact Us&lt;/</span><span style="color:#7EE787">h2</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">form</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">label</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">for</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"name"</span><span style="color:#C9D1D9">&gt;Name:&lt;/</span><span style="color:#7EE787">label</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">input</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">type</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"text"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">id</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"name"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">name</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"name"</span><span style="color:#C9D1D9"> /&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">label</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">for</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"email"</span><span style="color:#C9D1D9">&gt;Email:&lt;/</span><span style="color:#7EE787">label</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">input</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">type</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"email"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">id</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"email"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">name</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"email"</span><span style="color:#C9D1D9"> /&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">label</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">for</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"message"</span><span style="color:#C9D1D9">&gt;Message:&lt;/</span><span style="color:#7EE787">label</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">textarea</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">id</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"message"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">name</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"message"</span><span style="color:#C9D1D9">&gt;&lt;/</span><span style="color:#7EE787">textarea</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">input</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">type</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"submit"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">value</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"Send Message"</span><span style="color:#C9D1D9"> /&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;/</span><span style="color:#7EE787">form</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">      &lt;/</span><span style="color:#7EE787">section</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">    &lt;/</span><span style="color:#7EE787">main</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">    &lt;</span><span style="color:#7EE787">footer</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">      &lt;</span><span style="color:#7EE787">p</span><span style="color:#C9D1D9">&gt;</span><span style="color:#79C0FF">&amp;copy;</span><span style="color:#C9D1D9"> 2023 My Mobile-First Approach Example. All rights reserved.&lt;/</span><span style="color:#7EE787">p</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">    &lt;/</span><span style="color:#7EE787">footer</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">  &lt;/</span><span style="color:#7EE787">body</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">&lt;/</span><span style="color:#7EE787">html</span><span style="color:#C9D1D9">&gt;</span></span></code></pre>
<p>The outcome:
<img src="/images/mobile-first-approach-with-html-and-css/images/image01.png" alt="-"></p>
<p>The example above follows the mobile-first approach and includes the necessary structure for a website. It sets the document type, defines the viewport for responsive behavior, and consists of a title for the page. It also comprises a header, a main content area with sections, and a footer. The navigation bar, sections, and form are organized using semantic HTML tags.</p>
<h2 id="creating-responsive-grid-systems">Creating responsive grid systems</h2>
<p>By leveraging the power of CSS Flexbox and CSS Grid, you can create versatile and responsive grid systems that adapt gracefully to different devices, providing an optimal user experience for mobile and desktop users.
Here is how you can use CSS flexbox and grid to create a responsive grid system for the mobile-first approach:</p>
<pre class="astro-code" style="background-color:#0d1117;overflow-x:auto"><code><span class="line"><span style="color:#C9D1D9">&lt;!</span><span style="color:#7EE787">DOCTYPE</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">html</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">&lt;</span><span style="color:#7EE787">html</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">  &lt;</span><span style="color:#7EE787">head</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">    &lt;</span><span style="color:#7EE787">meta</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">charset</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"UTF-8"</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">    &lt;</span><span style="color:#7EE787">meta</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">name</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"viewport"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">content</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"width=device-width, initial-scale=1.0"</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">    &lt;</span><span style="color:#7EE787">title</span><span style="color:#C9D1D9">&gt;My Mobile-First Approach&lt;/</span><span style="color:#7EE787">title</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">    &lt;</span><span style="color:#7EE787">style</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">      </span><span style="color:#79C0FF">.grid-container-flex</span><span style="color:#C9D1D9"> {</span></span>
<span class="line"><span style="color:#C9D1D9">        </span><span style="color:#79C0FF">display</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">flex</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">        </span><span style="color:#79C0FF">flex-direction</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">column</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">        </span><span style="color:#79C0FF">background-color</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">purple</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">        </span><span style="color:#79C0FF">font-size</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">1.5</span><span style="color:#FF7B72">rem</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">        </span><span style="color:#79C0FF">color</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">white</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">        </span><span style="color:#79C0FF">margin-top</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">1</span><span style="color:#FF7B72">rem</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">        </span><span style="color:#79C0FF">height</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">7</span><span style="color:#FF7B72">em</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">      }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">      </span><span style="color:#79C0FF">.grid-container-grid</span><span style="color:#C9D1D9"> {</span></span>
<span class="line"><span style="color:#C9D1D9">        </span><span style="color:#79C0FF">display</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">grid</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">        </span><span style="color:#79C0FF">grid-template-columns</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">20</span><span style="color:#FF7B72">em</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">        </span><span style="color:#79C0FF">height</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">8</span><span style="color:#FF7B72">em</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">        </span><span style="color:#79C0FF">font-size</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">1.1</span><span style="color:#FF7B72">rem</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">      }</span></span>
<span class="line"><span style="color:#C9D1D9">    &lt;/</span><span style="color:#7EE787">style</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">  &lt;/</span><span style="color:#7EE787">head</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">  &lt;</span><span style="color:#7EE787">body</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">    &lt;</span><span style="color:#7EE787">header</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">      &lt;</span><span style="color:#7EE787">h1</span><span style="color:#C9D1D9">&gt;My Mobile-First Approach HTML Structuring&lt;/</span><span style="color:#7EE787">h1</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">      &lt;</span><span style="color:#7EE787">nav</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">href</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">""</span><span style="color:#C9D1D9">&gt;Home&lt;/</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">href</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">""</span><span style="color:#C9D1D9">&gt;Shop&lt;/</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">href</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">""</span><span style="color:#C9D1D9">&gt;Contact&lt;/</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">href</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">""</span><span style="color:#C9D1D9">&gt;Store&lt;/</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">      &lt;/</span><span style="color:#7EE787">nav</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">    &lt;/</span><span style="color:#7EE787">header</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">    &lt;</span><span style="color:#7EE787">main</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">      &lt;</span><span style="color:#7EE787">section</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">class</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"grid-container-flex"</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">h2</span><span style="color:#C9D1D9">&gt;About Us&lt;/</span><span style="color:#7EE787">h2</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">p</span><span style="color:#C9D1D9">&gt;We work with skilled artisans and select premium materials to craft footwear that stands the test of time&lt;/</span><span style="color:#7EE787">p</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">      &lt;/</span><span style="color:#7EE787">section</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">      &lt;</span><span style="color:#7EE787">section</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">class</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"grid-container-grid"</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">h2</span><span style="color:#C9D1D9">&gt;Our Products&lt;/</span><span style="color:#7EE787">h2</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">ul</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">li</span><span style="color:#C9D1D9">&gt;Men's shoes&lt;/</span><span style="color:#7EE787">li</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">li</span><span style="color:#C9D1D9">&gt;Women's Shoes&lt;/</span><span style="color:#7EE787">li</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">li</span><span style="color:#C9D1D9">&gt;Kid's Shoes&lt;/</span><span style="color:#7EE787">li</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;/</span><span style="color:#7EE787">ul</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">      &lt;/</span><span style="color:#7EE787">section</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">      &lt;</span><span style="color:#7EE787">section</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">h2</span><span style="color:#C9D1D9">&gt;Contact Us&lt;/</span><span style="color:#7EE787">h2</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;</span><span style="color:#7EE787">form</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">label</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">for</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"name"</span><span style="color:#C9D1D9">&gt;Name:&lt;/</span><span style="color:#7EE787">label</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">input</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">type</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"text"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">id</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"name"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">name</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"name"</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">label</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">for</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"email"</span><span style="color:#C9D1D9">&gt;Email:&lt;/</span><span style="color:#7EE787">label</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">input</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">type</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"email"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">id</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"email"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">name</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"email"</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">label</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">for</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"message"</span><span style="color:#C9D1D9">&gt;Message:&lt;/</span><span style="color:#7EE787">label</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">textarea</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">id</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"message"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">name</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"message"</span><span style="color:#C9D1D9">&gt;&lt;/</span><span style="color:#7EE787">textarea</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">          &lt;</span><span style="color:#7EE787">input</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">type</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"submit"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">value</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"Send Message"</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">        &lt;/</span><span style="color:#7EE787">form</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">      &lt;/</span><span style="color:#7EE787">section</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">    &lt;/</span><span style="color:#7EE787">main</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">    &lt;</span><span style="color:#7EE787">footer</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">      &lt;</span><span style="color:#7EE787">p</span><span style="color:#C9D1D9">&gt;</span><span style="color:#79C0FF">&amp;copy;</span><span style="color:#C9D1D9"> 2023 My Mobile-First Approach Example. All rights reserved.&lt;/</span><span style="color:#7EE787">p</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">    &lt;/</span><span style="color:#7EE787">footer</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">  &lt;/</span><span style="color:#7EE787">body</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">&lt;/</span><span style="color:#7EE787">html</span><span style="color:#C9D1D9">&gt;</span></span></code></pre>
<p>The outcome:
<img src="/images/mobile-first-approach-with-html-and-css/images/image02.png" alt="-"></p>
<p>The Flexbox layout is applied to the “About Us” section in the above example, arranging its elements in a vertical column. The Grid layout is used for the “Our Products” section, organizing its elements in a single column. These CSS techniques help create responsive and adaptable layouts that can be customized and optimized for different devices and screen sizes.</p>
<p>You can check out <a href="https://blog.openreplay.com/building-layouts-with-css3-flexbox/">CSS Flexbox</a> and <a href="https://blog.openreplay.com/working-with-the-css-grid/">CSS Grid</a> for in-depth knowledge of how to use them and create a responsive grid system for the mobile-first approach.</p>
<p>You can effectively implement a mobile-first approach with HTML and CSS, ensuring a responsive and user-friendly design for mobile devices while accommodating larger screens and providing a seamless cross-device experience.</p>
<h2 id="responsive-design-with-css-media-queries">Responsive Design with CSS Media Queries</h2>
<p>Implementing responsive design with CSS media queries enables you to apply different styles based on the device’s screen size. This approach is commonly used with the mobile-first approach to improve user experience across various devices.</p>
<p>You can create a responsive design using CSS media queries that provides an optimal viewing experience across multiple devices. It allows you to tailor your styles to different screen sizes’ specific needs and constraints, ensuring that your website or application is user-friendly and visually appealing on all devices.</p>
<p>Here is how you can use CSS media queries for a mobile-first approach:</p>
<ol>
<li>
<p>Design and style your mobile device website or application using CSS rules targeting smaller screens. This enables your design optimization for mobile users and establishes the mobile-first foundation.</p>
</li>
<li>
<p>You will use the <code>min-width</code> media query for the mobile-first approach to enhance the design as the screen size increases progressively. This means that the default styles will be for mobile, and additional styles will be added as the screen size increases.</p>
</li>
<li>
<p>You must determine the breakpoints at which you want to introduce layout or styling changes. Breakpoints are specific screen widths at which your design will adapt to fit the screen size better. Standard breakpoints include tablets, desktops, and larger screens.</p>
</li>
<li>
<p>To target specific screen sizes, write media queries using the <code>@media</code> rule and the <code>min-width</code> property.</p>
</li>
</ol>
<p>For example:</p>
<pre class="astro-code" style="background-color:#0d1117;overflow-x:auto"><code><span class="line"><span style="color:#C9D1D9">&lt;!</span><span style="color:#7EE787">DOCTYPE</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">html</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">&lt;</span><span style="color:#7EE787">html</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9"> &lt;</span><span style="color:#7EE787">head</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">   &lt;</span><span style="color:#7EE787">meta</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">charset</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"UTF-8"</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">   &lt;</span><span style="color:#7EE787">meta</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">name</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"viewport"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">content</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"width=device-width, initial-scale=1.0"</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">   &lt;</span><span style="color:#7EE787">title</span><span style="color:#C9D1D9">&gt;My Mobile-First Approach&lt;/</span><span style="color:#7EE787">title</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">   &lt;</span><span style="color:#7EE787">style</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">     </span><span style="color:#8B949E">/* Default styles for mobile */</span></span>
<span class="line"><span style="color:#C9D1D9">     </span><span style="color:#79C0FF">.grid-container-flex</span><span style="color:#C9D1D9"> {</span></span>
<span class="line"><span style="color:#C9D1D9">       </span><span style="color:#79C0FF">display</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">flex</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">       </span><span style="color:#79C0FF">flex-direction</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">column</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">       </span><span style="color:#79C0FF">background-color</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">purple</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">       </span><span style="color:#79C0FF">font-size</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">0.9</span><span style="color:#FF7B72">rem</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">       </span><span style="color:#79C0FF">color</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">white</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">       </span><span style="color:#79C0FF">margin-top</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">1</span><span style="color:#FF7B72">rem</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">       </span><span style="color:#79C0FF">height</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">9</span><span style="color:#FF7B72">em</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">     }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">     </span><span style="color:#79C0FF">.grid-container-grid</span><span style="color:#C9D1D9"> {</span></span>
<span class="line"><span style="color:#C9D1D9">       </span><span style="color:#79C0FF">display</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">grid</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">       </span><span style="color:#79C0FF">grid-template-columns</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">20</span><span style="color:#FF7B72">em</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">       </span><span style="color:#79C0FF">height</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">8</span><span style="color:#FF7B72">em</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">       </span><span style="color:#79C0FF">font-size</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">1.1</span><span style="color:#FF7B72">rem</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">     }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">     </span><span style="color:#8B949E">/* Media query for tablets */</span></span>
<span class="line"><span style="color:#C9D1D9">     </span><span style="color:#FF7B72">@media</span><span style="color:#C9D1D9"> (</span><span style="color:#79C0FF">min-width</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">768</span><span style="color:#FF7B72">px</span><span style="color:#C9D1D9">) {</span></span>
<span class="line"><span style="color:#C9D1D9">       </span><span style="color:#79C0FF">.grid-container-flex</span><span style="color:#C9D1D9"> {</span></span>
<span class="line"><span style="color:#C9D1D9">         </span><span style="color:#79C0FF">font-size</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">1.3</span><span style="color:#FF7B72">rem</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">       }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">       </span><span style="color:#79C0FF">.grid-container-grid</span><span style="color:#C9D1D9"> {</span></span>
<span class="line"><span style="color:#C9D1D9">         </span><span style="color:#79C0FF">grid-template-columns</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">none</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">         </span><span style="color:#79C0FF">height</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">10</span><span style="color:#FF7B72">em</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">       }</span></span>
<span class="line"><span style="color:#C9D1D9">     }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">     </span><span style="color:#8B949E">/* Media query for desktops */</span></span>
<span class="line"><span style="color:#C9D1D9">     </span><span style="color:#FF7B72">@media</span><span style="color:#C9D1D9"> (</span><span style="color:#79C0FF">min-width</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">1024</span><span style="color:#FF7B72">px</span><span style="color:#C9D1D9">) {</span></span>
<span class="line"><span style="color:#C9D1D9">       </span><span style="color:#79C0FF">.grid-container-flex</span><span style="color:#C9D1D9"> {</span></span>
<span class="line"><span style="color:#C9D1D9">         </span><span style="color:#79C0FF">font-size</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">2</span><span style="color:#FF7B72">rem</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">       }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">       </span><span style="color:#79C0FF">.grid-container-grid</span><span style="color:#C9D1D9"> {</span></span>
<span class="line"><span style="color:#C9D1D9">         </span><span style="color:#79C0FF">grid-template-columns</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">none</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">         </span><span style="color:#79C0FF">height</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">12</span><span style="color:#FF7B72">em</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">       }</span></span>
<span class="line"><span style="color:#C9D1D9">     }</span></span>
<span class="line"><span style="color:#C9D1D9">   &lt;/</span><span style="color:#7EE787">style</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9"> &lt;/</span><span style="color:#7EE787">head</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9"> &lt;</span><span style="color:#7EE787">body</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">   &lt;</span><span style="color:#7EE787">header</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">     &lt;</span><span style="color:#7EE787">h1</span><span style="color:#C9D1D9">&gt;My Mobile-First Approach HTML Structuring&lt;/</span><span style="color:#7EE787">h1</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">     &lt;</span><span style="color:#7EE787">nav</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">       &lt;</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">href</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">""</span><span style="color:#C9D1D9">&gt;Home&lt;/</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">       &lt;</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">href</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">""</span><span style="color:#C9D1D9">&gt;Shop&lt;/</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">       &lt;</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">href</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">""</span><span style="color:#C9D1D9">&gt;Contact&lt;/</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">       &lt;</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">href</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">""</span><span style="color:#C9D1D9">&gt;Store&lt;/</span><span style="color:#7EE787">a</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">     &lt;/</span><span style="color:#7EE787">nav</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">   &lt;/</span><span style="color:#7EE787">header</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">   &lt;</span><span style="color:#7EE787">main</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">     &lt;</span><span style="color:#7EE787">section</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">class</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"grid-container-flex"</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">       &lt;</span><span style="color:#7EE787">h2</span><span style="color:#C9D1D9">&gt;About Us&lt;/</span><span style="color:#7EE787">h2</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">       &lt;</span><span style="color:#7EE787">p</span><span style="color:#C9D1D9">&gt;We work with skilled artisans and select premium materials to craft footwear that stands the test of time&lt;/</span><span style="color:#7EE787">p</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">     &lt;/</span><span style="color:#7EE787">section</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">     &lt;</span><span style="color:#7EE787">section</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">class</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"grid-container-grid"</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">       &lt;</span><span style="color:#7EE787">h2</span><span style="color:#C9D1D9">&gt;Our Products&lt;/</span><span style="color:#7EE787">h2</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">       &lt;</span><span style="color:#7EE787">ul</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">         &lt;</span><span style="color:#7EE787">li</span><span style="color:#C9D1D9">&gt;Men's shoes&lt;/</span><span style="color:#7EE787">li</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">         &lt;</span><span style="color:#7EE787">li</span><span style="color:#C9D1D9">&gt;Women's Shoes&lt;/</span><span style="color:#7EE787">li</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">         &lt;</span><span style="color:#7EE787">li</span><span style="color:#C9D1D9">&gt;Kid's Shoes&lt;/</span><span style="color:#7EE787">li</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">       &lt;/</span><span style="color:#7EE787">ul</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">     &lt;/</span><span style="color:#7EE787">section</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">     &lt;</span><span style="color:#7EE787">section</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">       &lt;</span><span style="color:#7EE787">h2</span><span style="color:#C9D1D9">&gt;Contact Us&lt;/</span><span style="color:#7EE787">h2</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">       &lt;</span><span style="color:#7EE787">form</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">         &lt;</span><span style="color:#7EE787">label</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">for</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"name"</span><span style="color:#C9D1D9">&gt;Name:&lt;/</span><span style="color:#7EE787">label</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">         &lt;</span><span style="color:#7EE787">input</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">type</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"text"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">id</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"name"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">name</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"name"</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">         &lt;</span><span style="color:#7EE787">label</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">for</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"email"</span><span style="color:#C9D1D9">&gt;Email:&lt;/</span><span style="color:#7EE787">label</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">         &lt;</span><span style="color:#7EE787">input</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">type</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"email"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">id</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"email"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">name</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"email"</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">         &lt;</span><span style="color:#7EE787">label</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">for</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"message"</span><span style="color:#C9D1D9">&gt;Message:&lt;/</span><span style="color:#7EE787">label</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">         &lt;</span><span style="color:#7EE787">textarea</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">id</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"message"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">name</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"message"</span><span style="color:#C9D1D9">&gt;&lt;/</span><span style="color:#7EE787">textarea</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">         &lt;</span><span style="color:#7EE787">input</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">type</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"submit"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">value</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"Send Message"</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">       &lt;/</span><span style="color:#7EE787">form</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">     &lt;/</span><span style="color:#7EE787">section</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">   &lt;/</span><span style="color:#7EE787">main</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C9D1D9">   &lt;</span><span style="color:#7EE787">footer</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">     &lt;</span><span style="color:#7EE787">p</span><span style="color:#C9D1D9">&gt;</span><span style="color:#79C0FF">&amp;copy;</span><span style="color:#C9D1D9"> 2023 My Mobile-First Approach Example. All rights reserved.&lt;/</span><span style="color:#7EE787">p</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">   &lt;/</span><span style="color:#7EE787">footer</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9"> &lt;/</span><span style="color:#7EE787">body</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">&lt;/</span><span style="color:#7EE787">html</span><span style="color:#C9D1D9">&gt;</span></span></code></pre>
<p>The above example includes CSS media queries for a mobile-first approach to adjust the styles for different screen sizes. The mobile styles are applied by default, and certain elements’ font size and height are increased for tablets. The font size and height are further adjusted for desktops to ensure optimal display on larger screens.</p>
<p>You can check out <a href="https://blog.openreplay.com/understanding-css-media-queries/">CSS media queries</a> for an in-depth understanding of using CSS media queries.</p>
<h2 id="testing-and-optimization">Testing and Optimization</h2>
<p>Testing and optimization are crucial steps in the mobile-first approach to ensure the effectiveness and performance of the designed website or application on various mobile devices.</p>
<p>In the developer tools, you can use responsive design testing tools in modern browsers, such as Chrome’s Device Mode, to test on various devices and screen sizes. These tools allow you to simulate multiple devices and screen sizes, visually representing how the code renders on different devices.</p>
<p>Let’s check how the mobile-first approach is displayed on different devices.</p>
<p>Mobile display:
<img src="/images/mobile-first-approach-with-html-and-css/images/image03.gif" alt="-">)</p>
<p>Large screen display:
<img src="/images/mobile-first-approach-with-html-and-css/images/image04.gif" alt="-"></p>
<p>Tablet display:
<img src="/images/mobile-first-approach-with-html-and-css/images/image05.png" alt="-"></p>
<h2 id="using-responsive-image-techniques">Using responsive image techniques</h2>
<p>Responsive image techniques for the mobile-first approach allow the images to adjust to different screen sizes, ensuring a better user experience on mobile devices while still providing high-quality images on larger screens.</p>
<p>Some of the techniques to use when implementing responsive image techniques for a mobile-first approach include:</p>
<ul>
<li>the picture element can present different images based on screen size.
For example:</li>
</ul>
<pre class="astro-code" style="background-color:#0d1117;overflow-x:auto"><code><span class="line"><span style="color:#C9D1D9">&lt;</span><span style="color:#7EE787">picture</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">  &lt;</span><span style="color:#7EE787">source</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">media</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"(min-width: 768px)"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">srcset</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"large.jpg"</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">  &lt;</span><span style="color:#7EE787">source</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">media</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"(min-width: 480px)"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">srcset</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"medium.jpg"</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">  &lt;</span><span style="color:#7EE787">img</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">src</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"small.jpg"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">alt</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"Responsive image"</span><span style="color:#C9D1D9">&gt;</span></span>
<span class="line"><span style="color:#C9D1D9">&lt;/</span><span style="color:#7EE787">picture</span><span style="color:#C9D1D9">&gt;</span></span></code></pre>
<p>The above example enables the browser to choose <code>large.jpg</code> for screens wider than 768 pixels, <code>medium.jpg</code> for screens wider than 480 pixels, and fallback to <code>small.jpg</code> for smaller screens.</p>
<ul>
<li>To avoid overflow of images from the container on different screen sizes, set the <code>max-width</code> property of the image to 100% and let the height scale automatically to maintain the image’s aspect ratio.</li>
</ul>
<p>For example:</p>
<pre class="astro-code" style="background-color:#0d1117;overflow-x:auto"><code><span class="line"><span style="color:#7EE787">img</span><span style="color:#C9D1D9"> {</span></span>
<span class="line"><span style="color:#C9D1D9">  </span><span style="color:#79C0FF">max-width</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">100</span><span style="color:#FF7B72">%</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">  </span><span style="color:#79C0FF">height</span><span style="color:#C9D1D9">: </span><span style="color:#79C0FF">auto</span><span style="color:#C9D1D9">;</span></span>
<span class="line"><span style="color:#C9D1D9">}</span></span></code></pre>
<ul>
<li>To set multiple image sources with different resolutions or sizes, use the <code>srcset</code> attribute. This enables the browser to select the most appropriate image based on the device’s screen size and pixel density.</li>
</ul>
<p>Example:</p>
<pre class="astro-code" style="background-color:#0d1117;overflow-x:auto"><code><span class="line"><span style="color:#C9D1D9">&lt;</span><span style="color:#7EE787">img</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">src</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"small.jpg"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">srcset</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"medium.jpg 800w, large.jpg 1200w"</span><span style="color:#C9D1D9"> </span><span style="color:#79C0FF">alt</span><span style="color:#C9D1D9">=</span><span style="color:#A5D6FF">"Responsive Image"</span><span style="color:#C9D1D9">&gt;</span></span></code></pre>
<p>The above example shows the browser will choose between <code>small.jpg</code>, <code>medium.jpg</code>, or <code>large.jpg</code> based on the available width (<code>800w</code> or <code>1200w</code>).</p>
<h2 id="conclusion">Conclusion</h2>
<p>The mobile-first approach prioritizes mobile users and eliminates the issues associated with scaling down from desktop to mobile. By following the mobile-first approach and incorporating responsive design principles, we can create flexible and adaptive websites that meet the diverse needs of users across different screen sizes and devices. We can create a user-centered and efficient design that works well on mobile devices by starting with the smallest screens and focusing on essential content and functionality.</p>
<div class="p-5 bg-gradient-to-t from-violet-100 from-90% to-blue-50 to-180% rounded-md xl:hidden">
<h3>Gain Debugging Superpowers</h3> 
<p class="text-slate-800">
  Unleash the power of session replay to reproduce bugs and track user frustrations. Get complete visibility into your frontend with OpenReplay, the most advanced open-source session replay tool for developers.
</p>
<a class="post-end-cta-img-web hover:opacity-90" href="https://github.com/openreplay/openreplay" target="_blank"><img class="my-4" src="/media/openreplay-git-hero.svg" alt="OpenReplay"></a>
  <div class="grid gap-4 md:grid-cols-2 text-center mt-4">
    <a class="post-end-cta-git flex px-3 py-2 font-normal rounded-md no-underline bg-brand-blue hover:bg-indigo-700 text-white justify-center" href="https://github.com/openreplay/openreplay" target="_blank">
      <p class="flex items-center gap-1"><span class="inline-block align-text-top"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-github" viewBox="0 0 16 16">
        <path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path>
      </svg></span> Check our GitHub Repo</p>
    </a>
  </div>
</div>
            </section>`