HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
  • Insights
  • Verify Certificate
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials

HTML5andCSS3.org helps developers learn modern frontend skills with practical tutorials, production-ready snippets, and fast web tools built for everyday coding.

Quick Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Copyright
  • Disclaimer

Top Tools

  • Try It Editor
  • JSON Formatter
  • CSS Minifier
  • HTML Minifier
  • Base64 Encoder / Decoder

Contact

  • business@html5andcss3.org
Newsletter

Learn at your own pace, practice with useful tools, and build websites you're proud of.

© 2011-2026 html5andcss3.org. All rights reserved.

How to Use

CSS Tutorial

CSS Introduction

What is CSSCSS SyntaxHow to Add CSSCSS Comments

CSS Foundations

Cascade & InheritanceCSS SpecificityCSS UnitsBox SizingCSS VariablesCSS Math Functions

CSS Selectors

CSS Element SelectorCSS Class SelectorCSS ID SelectorCSS Universal SelectorCSS Group SelectorCSS CombinatorsCSS Attribute SelectorsCSS Pseudo ClassesCSS Pseudo Elements

CSS Colors and Backgrounds

CSS ColorsCSS HEX ColorsCSS RGB ColorsModern ColorsCSS Background ColorCSS Background ImageLayered Backgrounds

CSS Text & Fonts

CSS Text ColorCSS Text AlignmentCSS Text DecorationCSS Font FamilyCSS Font SizeWeb Fonts & TypographyText Wrapping

CSS Box Model

CSS MarginCSS PaddingCSS BorderCSS OutlineCSS Width and Height

CSS Layout

Normal FlowCSS DisplayCSS PositionAnchor PositioningCSS FloatCSS OverflowCSS Z-indexIntrinsic SizingAspect Ratio & Object FitMulti-column Layout

CSS Flexbox

Flex ContainerFlex DirectionJustify ContentAlign ItemsFlex WrapFlex Item Sizing

CSS Grid

CSS Grid ContainerCSS Grid ColumnsCSS Grid RowsCSS Grid GapCSS Grid Layout ExampleGrid PlacementGrid AreasCSS Subgrid

CSS Lists, Tables & Forms

CSS ListsCSS TablesCSS Form StylingCSS Input Fields

CSS Effects

CSS ShadowsCSS GradientsCSS FiltersCSS OpacityClipping & MaskingBlending & BackdropScroll Snap

CSS Animations & Transitions

CSS TransformCSS 2D TransformCSS 3D TransformCSS TransitionsEntry & Exit TransitionsCSS AnimationsScroll AnimationsView TransitionsMotion Paths

CSS Responsive Design

CSS Media QueriesResponsive LayoutMobile First DesignContainer QueriesPreference Media QueriesFeature Queries

Modern CSS Authoring

Cascade LayersNesting & ScopeLogical PropertiesGenerated Content

CSS Accessibility

Accessible CSSCSS ThemingModern Form StylingCSS User Interface

CSS Output & Performance

Print StylesCSS PerformanceCSS ArchitectureDebugging CSS

CSS Reference

CSS At-rulesCSS FunctionsCSS Tutorial PDF

CSS Projects

Responsive CSS Project
  1. Home
  2. /
  3. Tutorials
  4. /
  5. CSS Tutorial
  6. /
  7. Responsive Layout

CSS Responsive Design

Responsive Layout

A Responsive Layout is a web page layout that automatically adjusts to different screen sizes and devices.

Instead of creating separate versions of a website for mobile, tablet, and desktop users, responsive layouts adapt dynamically using CSS techniques. The supporting concepts are explained in CSS Media Queries and Mobile First Design.

Responsive layouts help ensure that content remains:

  • Readable
  • Accessible
  • User-friendly
  • Consistent across devices

Modern responsive layouts are commonly built using:

  • Flexible widths
  • CSS Flexbox
  • CSS Grid
  • Responsive images
  • Media Queries

Syntax

A responsive layout typically combines flexible units with media queries.

Responsive Layout Syntax

css

.container {
    width: 100%;
    max-width: 1200px;
}

Allows the layout to shrink and grow based on screen size.

Attributes

TechniqueDescriptionExample
width: 100%Makes elements flexiblewidth: 100%;
max-widthPrevents excessive stretchingmax-width: 1200px;
FlexboxCreates flexible layoutsdisplay: flex;
GridCreates responsive gridsdisplay: grid;
Media QueriesApplies styles for specific screen sizes@media (...)

Example

Responsive Layout Complete Example

html

<!DOCTYPE html>
<html>
<head>
    <title>Responsive Layout Example</title>
    <style>
        .container {
            display: flex;
            gap: 20px;
            max-width: 1200px;
            margin: auto;
        }
        .box {
            flex: 1;
            background-color: lightblue;
            padding: 20px;
        }
        @media (max-width: 768px) {
            .container {
                flex-direction: column;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="box">Section 1</div>
        <div class="box">Section 2</div>
        <div class="box">Section 3</div>
    </div>
</body>
</html>

Output

Browser Output

css

Desktop View
Section 1 | Section 2 | Section 3

Mobile View
Section 1
Section 2
Section 3

Desktop displays sections side by side
Mobile stacks sections vertically
The layout automatically adjusts to screen size

Browser Support

Feature
Chrome
Edge
Firefox
Safari
Media-query layouts11213

Versions show the first stable desktop release with unprefixed support. Data source: MDN Browser Compatibility Data 8.0.8.

Notes

Responsive Images

Responsive Images

css

img {
    max-width: 100%;
    height: auto;
}

Prevents images from overflowing their container.

Responsive Grid Example

Responsive Grid Example

css

.container {
    display: grid;
    grid-template-columns:
        repeat(auto-fit, minmax(250px, 1fr));
}

Automatically adjusts column count based on screen size.

Responsive Flexbox Example

Responsive Flexbox Example

css

.container {
    display: flex;
    flex-wrap: wrap;
}

Allows items to move onto new rows when space is limited.

Best Practices

PracticeBenefit
Use relative unitsBetter scalability
Use Flexbox/GridEasier responsive layouts
Use media queriesDevice-specific styling
Use responsive imagesPrevent overflow
Test on multiple devicesBetter user experience

Conclusion

Responsive Layouts ensure that websites work effectively across different devices and screen sizes. By combining flexible units, responsive images, Flexbox, Grid, and Media Queries, developers can create layouts that provide a consistent and user-friendly experience for all users.

PreviousCSS Media QueriesNextMobile First Design