By the end of this lesson, you will:
display, position, flexbox, and grid.HTML gives your website structure, but CSS gives it form. Good layout design isn’t just about looking pretty—it’s about usability, readability, and responsive behavior across screen sizes.
With just a few CSS layout properties, you can go from a jumbled pile of content to a clean, responsive, and modern design.
display – The Foundation of LayoutThe display property defines how elements behave in the layout flow.
div {
display: block; /* Default for <div> */
}
span {
display: inline; /* Default for <span> */
}
Common values:
blockinlineinline-blocknoneflexgridUse display: flex to align items horizontally or vertically.
.container {
display: flex;
justify-content: space-between;
align-items: center;
}
Key properties:
justify-content: aligns items horizontallyalign-items: aligns items verticallyflex-direction: row (default) or columnflex-wrap: wraps items when neededBest for: Toolbars, navigation bars, cards, and lists.
Use display: grid to control rows and columns.
.container {
display: grid;
grid-template-columns: 1fr 2fr;
gap: 20px;
}
Key properties:
grid-template-columns: sets column widthsgrid-template-rows: sets row heightsgap: spacing between grid itemsgrid-column / grid-row: controls item spanBest for: Page templates, dashboards, galleries.
position – Control Exact Placement.box {
position: absolute;
top: 50px;
left: 100px;
}
Values:
static (default)relativeabsolutefixedstickyUse carefully – best for specific use cases like modals, tooltips, or sticky headers.
Make layouts adapt to screen size.
@media (max-width: 600px) {
.container {
flex-direction: column;
}
}
Create a horizontal nav bar using Flexbox:
Design a layout with:
Use grid-template-areas or manual row/column placement.
Use Flexbox to display a row of cards, then stack them vertically on small screens using a media query.
absolute or fixed positioning?📚 MDN: CSS Layout Techniques
📚 Flexbox Froggy – Gamified Flexbox practice
📚 Grid Garden – Gamified CSS Grid learning
🧪 CodePen – Live test your layouts
With tools like Flexbox, Grid, and positioning, CSS gives you full control over how your content flows and adapts. Choosing the right layout strategy helps your website feel organized, modern, and responsive.
Create a simple webpage layout using either Flexbox or Grid with at least 3 sections. Test it on different screen sizes or simulate mobile view in your browser.
Not a member yet? Register now
Are you a member? Login now