Browse tutorial categories
On this page

Build a Responsive Layout with HTML and CSS

Start with semantic HTML and use a flexible CSS grid that adapts to narrow screens without fixed-width overflow.

Responsive layouts adapt to available space instead of assuming every visitor has the same screen. Begin with meaningful HTML, then let CSS Grid determine how many columns fit.

Use semantic markup

<main>
  <section aria-labelledby="guides-title">
    <h1 id="guides-title">Guides</h1>
    <div class="guide-grid">
      <article class="guide-card">
        <h2>Getting started</h2>
        <p>A short description of the guide.</p>
      </article>
    </div>
  </section>
</main>

Use heading levels to reflect document structure, not just visual size. The article element works well for a card that can stand on its own.

Let the grid adapt

.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
  gap: 1rem;
}

.guide-card {
  min-width: 0;
  padding: 1.25rem;
  border: 1px solid #dbe2ea;
  border-radius: 1rem;
}

minmax() sets a useful minimum card size while allowing columns to grow. The nested min() avoids overflow on screens narrower than the preferred card width.

Test the real content

Resize the browser and inspect long headings, translated labels, and narrow interactive controls. Avoid fixed widths for the page shell, provide visible keyboard focus, and make sure text remains readable at browser zoom.

#HTML#CSS#responsive design#accessibility