
Two-column layouts are everywhere on the web. Blogs pair article content with a sidebar, documentation sites place navigation beside the main text, and modern landing pages often use split-screen designs with an image on one side and a message on the other. Two columns provide a clear visual hierarchy and make efficient use of wide screens. In this guide, you will learn how to divide a web page into two columns using modern CSS techniques, how to control column widths, and how to make the layout respond gracefully to smaller devices.
Expert Layouts From AAMAX.CO
A thoughtful layout can make content more readable and persuasive. AAMAX.CO is a full-service digital marketing company offering web development, digital marketing, and SEO services worldwide. Their developers build responsive, accessible layouts using clean HTML and modern CSS, ensuring every page looks great on desktops, tablets, and phones. For businesses that want pixel-perfect execution, their website development services turn designs into fast, reliable websites.
Common Types of Two-Column Layouts
Before writing code, decide which style suits your content. An equal split divides the page fifty-fifty, which works well for comparisons or split-screen hero sections. A sidebar layout uses a narrow column for navigation, filters, or related links next to a wider content column. An asymmetric layout, such as a one-third and two-thirds split, highlights primary content while keeping supporting information visible. Each style can be built with the same core techniques by adjusting column sizes.
Step 1: Create the HTML
Start with a wrapper element containing two children. For a blog, a main element might hold the article and an aside element might hold the sidebar. For a split hero, two div elements inside a section work well. Here is a simple structure:
<div class="two-col"> <main class="content">...</main> <aside class="sidebar">...</aside></div>Using semantic elements tells browsers and assistive technologies which column holds the primary content.
Step 2: Two Columns With Flexbox
Set the wrapper's display property to flex and add a gap for spacing. For equal columns, give both children a flex value of one. For a sidebar layout, give the content column a flex value of three and the sidebar a flex value of one, or assign the sidebar a fixed basis such as 300 pixels while the content grows to fill the rest. Flexbox automatically stretches both columns to equal height, so background colors and borders line up neatly.
Step 3: Two Columns With CSS Grid
Grid offers precise control in a single line of CSS. Set the wrapper to display grid and define grid-template-columns. For equal columns, use two values of one fractional unit each. For a sidebar, use a fixed width followed by one fr, or one fr and two fr for a one-third and two-thirds split. You can also use the minmax function to set a minimum and maximum width for the sidebar, which keeps it usable without letting it grow too wide.
Step 4: Place the Sidebar on Either Side
Sometimes you want the sidebar on the left visually while keeping the main content first in the HTML for accessibility and SEO. With Grid, you can assign each element to a specific column using grid-column, or define named template areas. Use visual reordering carefully, and make sure keyboard focus still moves in a logical sequence.
Step 5: Make the Layout Responsive
On phones, two columns are usually too narrow to read comfortably. Use a mobile-first approach by stacking the columns in a single column by default, then switching to two columns with a media query when the viewport reaches a comfortable width, such as 768 pixels. With Flexbox, you can achieve automatic wrapping by enabling flex-wrap and giving each column a minimum basis. With Grid, a pattern combining repeat, auto-fit, and minmax creates columns that collapse automatically when space runs out.
Step 6: Create a Sticky Sidebar
Long articles benefit from a sidebar that stays visible while scrolling. Apply position sticky to the sidebar content with a top offset, and the browser will keep it in view as the main column scrolls past. Ensure the sidebar content is shorter than the viewport height, or users may be unable to reach its lower items.
Two Columns of Flowing Text
If you want text to flow from one column to the next like a newspaper, use the CSS column-count or columns property instead of Flexbox or Grid. Setting column-count to two splits a block of text into two balanced columns, and column-gap controls spacing. This works well for short passages, lists, or footers, but avoid it for long articles on screens where readers must scroll up and down repeatedly.
Legacy Approaches
Older tutorials may recommend floats or inline-block elements to create columns. Floats require clearing techniques to prevent layout collapse, and inline-block layouts suffer from unwanted whitespace gaps. HTML tables were also used for layout in the past, but they harm accessibility and responsiveness. Flexbox and Grid are supported in all modern browsers and are the recommended solutions today.
Design Tips for Two-Column Pages
Keep line lengths readable by limiting the main column to roughly 60 to 80 characters per line. Use consistent spacing and align elements to a shared baseline for a polished look. Make the primary column visually dominant so visitors know where to focus. Finally, avoid cluttering the sidebar; a few high-value items perform better than a crowded list of widgets.
Conclusion
Dividing a web page into two columns is simple with modern CSS. Flexbox handles flexible, content-driven layouts, Grid offers precise control over column widths and placement, and CSS columns are perfect for flowing text. Combine these tools with semantic HTML, mobile-first responsive design, and thoughtful content hierarchy, and you will create two-column layouts that are attractive, readable, and accessible on every device.
