LATEST 🚀 Welcome to Upgradix by Shrash Studio – Your destination for free technology learning and career growth.
🕘 Updated:
HTML & CSS

Build a Professional Dashboard with Sidebar and Main Content

Build a flexbox dashboard from the outside in. Make the page shell a flex container with min-height: 100vh. Give the sidebar a fixed size that cannot shrink, such as flex: 0 0 240px, and let the main area take the rest with flex: 1 and min-width: 0.

Build a Professional Dashboard with Sidebar and Main Content

Quick Answer: Build a flexbox dashboard from the outside in. Make the page shell a flex container with min-height: 100vh. Give the sidebar a fixed size that cannot shrink, such as flex: 0 0 240px, and let the main area take the rest with flex: 1 and min-width: 0. Make the sidebar and the main area column flex containers, so the user block sits at the bottom of the sidebar and the footer stays at the bottom of the page. Inside the main area, use wrapping flex rows for stat cards and panels, and put wide tables in a wrapper with overflow-x: auto. Write the stacked small-screen layout first, then switch the shell to a row with a min-width media query.

S1. Why Do We Need Flexbox for a Dashboard?

Imagine an admin page for a small business. A menu runs down the left side, and the reports, numbers and tables fill the right side. The menu should reach the bottom of the screen, even when the content is short. The content should never slide under the menu, even when a table is very wide.

Dashboards are the screens people use all day: analytics, admin panels, learning platforms and account settings. They mix a fixed-size part, the sidebar, with a flexible part, the main content. On a phone they must also change shape.

Would you fix the height of the sidebar and the margin of the content, and hope the content never changes? One extra row of data or one new menu item, and the layout needs new numbers.

Flexbox solves this. A fixed-size item and a flexible item can share one row, and both can have the same height. Each part can also be a flex container, so the same ideas work from the page shell down to a single card. Let's first see what the old approach looks like.

S2. The Problem: A Dashboard Built With Floats and Fixed Sizes

Float-based dashboard = a dashboard whose sidebar uses float with fixed sizes, and whose main area uses a margin to make room for it.

Imagine a dashboard that is 600px wide. The sidebar floats on the left, 200px wide and 160px tall. The main area has a left margin of 220px, so it starts after the sidebar plus a 20px gap. The main content is 240px tall.

Example 1: A float-based dashboard with a fixed-height sidebar

Assumption: In the output diagrams, one character is about 20px wide and one text row is about 40px tall. S is the sidebar and M is the main content.

<!-- HTML -->
<div class="app">
    <aside class="sidebar">Sidebar</aside>
    <main class="main">Main content, 240px tall</main>
</div>

/* CSS */
.app { width: 600px; }

.sidebar {
    float: left;
    width: 200px;
    height: 160px;
}

.main { margin-left: 220px; }

Expected output

|SSSSSSSSSS MMMMMMMMMMMMMMMMMMM|
|SSSSSSSSSS MMMMMMMMMMMMMMMMMMM|
|SSSSSSSSSS MMMMMMMMMMMMMMMMMMM|
|SSSSSSSSSS MMMMMMMMMMMMMMMMMMM|
|           MMMMMMMMMMMMMMMMMMM|
|           MMMMMMMMMMMMMMMMMMM|

The sidebar stops after 4 rows, because its height is fixed at 160px.
The main content continues for 2 more rows, and the left column under the sidebar is empty.
The main area is 600 - 220 = 380px wide, because the margin must match the sidebar width plus the gap.
If the sidebar width changes to 240px, the margin must be changed to 260px by hand.

The page renders without any error, and every rule is valid. The sidebar simply does not reach the bottom.

What goes wrong?

  1. A guessed height: The sidebar needs a fixed height to look right, but the right number changes whenever the content changes.
  2. Linked numbers: The margin of the main area has to match the width of the sidebar. Change one, and you must remember to change the other.
  3. Wide content overflows: A table wider than the main area spills out of it, because a normal block does not shrink around its content.
  4. No small-screen plan: A reserved 220px leaves very little room for the content on a phone.
  5. No natural footer position: Keeping a footer at the bottom of a short page needs another trick.

Now think about a real dashboard with a user block in the sidebar, a header, stat cards and a footer. Each part adds more numbers to keep in sync.

Remember: The sidebar and the main area are not independent. The height of one should follow the other, and the width of one should leave room for the other. A layout tool should handle that relationship for us.

Animation 1: How fixed sizes break a dashboard

Linked numbers meet changing content

The red highlights show where the layout stops following the plan.

📏Fixed sizesSidebar height 160pxSidebar width 200px
🔗Linked numbersMargin must match widthChange one, fix the other
📱Small screens220px stays reservedMain gets squeezed
 
Fragile dashboard Short sidebar · overflow · squeezed main
Numbers are kept in sync by hand

The animation highlights the three causes that make the dashboard fragile.

S3. The Solution: A Flex Shell With a Fixed Sidebar and a Flexible Main Area

Flexbox gives us a simpler design, and it lets the browser share the space between the sidebar and the main area.

app shell = the outer container that holds the sidebar and the main area, and often fills at least the whole height of the screen.

A dashboard shell needs only three ideas.

  • The shell is a flex container, so the sidebar and the main area sit side by side.
  • The sidebar has a fixed size and does not shrink. The main area takes all the remaining width.
  • Items in a row stretch to the same height by default, so the sidebar is as tall as the main area.

Now the same dashboard works with no height guess and no matching margin.

Example 2: The same dashboard with flexbox

Assumption: The app is 600px wide, and the main content is 240px tall. The gap between the sidebar and the main area is 20px.

<!-- HTML (same as Example 1) -->
<div class="app">
    <aside class="sidebar">Sidebar</aside>
    <main class="main">Main content, 240px tall</main>
</div>

/* CSS */
.app {
    display: flex;
    gap: 20px;
    width: 600px;
}

.sidebar { flex: 0 0 200px; }

.main {
    flex: 1;
    min-width: 0;
}

Expected output

|SSSSSSSSSS MMMMMMMMMMMMMMMMMMM|
|SSSSSSSSSS MMMMMMMMMMMMMMMMMMM|
|SSSSSSSSSS MMMMMMMMMMMMMMMMMMM|
|SSSSSSSSSS MMMMMMMMMMMMMMMMMMM|
|SSSSSSSSSS MMMMMMMMMMMMMMMMMMM|
|SSSSSSSSSS MMMMMMMMMMMMMMMMMMM|

The sidebar is exactly 200px: flex: 0 0 200px means no growing, no shrinking, and a 200px basis.
The main area gets the rest: 600 - 200 - 20 = 380px (19 characters).
Both items stretch to the same height, so the sidebar reaches the bottom without a height rule.
No margin has to match the sidebar width, so changing the width needs only one edit.

Notice the difference. We never wrote a height for the sidebar, and we never wrote a margin to make room for it.

Animation 2: How the flex dashboard is built

Shell, main, widgets

Each level uses a different direction of flexbox.

🧭ShellRow: sidebar and mainEqual heights
🪟Main areaColumn: header, content, footerFooter stays down
📊WidgetsWrapping rowsStats and panels
 
 
 
flex: 0 0 240pxflex: 1 · min-width: 0
flex-direction: columncontent with flex: 1
flex-wrap: wrapflex: 2 1 200px
Space is shared by the browser

The animation highlights the three levels of the dashboard and the flexbox feature each one uses.

Compare both approaches

Floats and fixed sizes compared with flexbox
Floats and fixed sizes Flexbox dashboard
The sidebar height is guessed. The sidebar stretches to the height of the main area.
The main margin must match the sidebar width. flex: 1 takes whatever space is left.
Wide content spills out of the main area. min-width: 0 and a scroll wrapper keep it inside.
A footer at the bottom needs a trick. A column layout with a growing content area does it.
Small screens need many patches. One flex-direction change switches the shell.

The idea to remember

  • The shell is a row = a fixed sidebar and a flexible main area share the width.
  • Fixed parts must not shrink = flex: 0 0 240px keeps the sidebar at its size.
  • Flexible parts need min-width: 0 = it lets the main area get narrower than its widest content.
  • Parts can be columns too = the sidebar and the main area are column flex containers inside the row.
  • Mobile first = write the stacked layout first, then switch the shell to a row with a min-width media query.

S4. Step-by-Step Code Breakdown

1. Learn the properties and the screen modes

A dashboard layout uses a small set of properties. The table shows each property, the element it belongs to, and what it does.

Properties used in a dashboard layout
Property Set on What it does in a dashboard
display: flex and min-height: 100vh The app shell Puts the sidebar and the main area side by side, at least as tall as the screen
flex: 0 0 240px The sidebar Gives it a fixed width that never grows or shrinks
flex: 1 and min-width: 0 The main area Takes the remaining width, and lets wide content scroll inside instead of pushing the layout
flex-direction: column The sidebar and the main area Stacks their parts vertically
margin-top: auto The user block in the sidebar Pushes it to the bottom of the sidebar
flex: 1 The content area in the main column Grows to fill the height, so the footer stays at the bottom
flex-wrap and gap The rows of stat cards and panels Wraps widgets onto new lines with equal spacing
overflow-x: auto A table wrapper Scrolls a wide table inside its own box

The same markup works in two modes, depending on the width of the screen.

How the dashboard behaves at each width
Screen Sidebar Main area
Below the breakpoint On top as a strip, with the links in a wrapping row Below the sidebar, using the full width
At or above the breakpoint A fixed-width column on the left, as tall as the page Takes the remaining width, and wide content scrolls inside

2. Build the shell

Example 2 already showed this step. The shell is a flex container. The sidebar uses flex: 0 0 200px, which is grow 0, shrink 0 and a basis of 200px. The main area uses flex: 1 to take the rest. The min-width: 0 rule is easy to forget, and Step 6 shows why it matters.

3. Make the sidebar a column

A sidebar usually has a logo at the top, the menu in the middle and a user block at the bottom. When the sidebar is a column flex container, an auto margin on the last item pushes it to the bottom, however tall the sidebar is.

Example 3: A sidebar with the user block at the bottom

Assumption: The sidebar is 200px wide. Each item (logo L, links O, R and T, and the user block U) is 40px tall. The sidebar is 240px tall because the main area next to it is that tall. A dot is empty sidebar background.

<!-- HTML -->
<aside class="sidebar">
    <a class="brand" href="#">Logo</a>
    <nav aria-label="Dashboard">
        <ul class="menu">
            <li><a href="#" aria-current="page">Overview</a></li>
            <li><a href="#">Reports</a></li>
            <li><a href="#">Team</a></li>
        </ul>
    </nav>
    <div class="sidebar-user">Profile</div>
</aside>

/* CSS */
.sidebar {
    display: flex;
    flex-direction: column;
    flex: 0 0 200px;
}

.menu {
    margin: 0;
    padding: 0;
    list-style: none;
}

.brand, .menu a, .sidebar-user {
    display: block;
    padding: 10px 20px;
}

.sidebar-user { margin-top: auto; }

Expected output

|LLLLLLLLLL|
|OOOOOOOOOO|
|RRRRRRRRRR|
|TTTTTTTTTT|
|..........|
|UUUUUUUUUU|

Used height = logo 40 + menu 120 + user 40 = 200px, and the sidebar is 240px tall.
The free space is 40px (1 row). margin-top: auto gives all of it to the area above the user block.
The user block stays at the bottom, however tall the main area becomes.
aria-current="page" marks the active link for assistive technology.

4. Make the main area a column

The main area also has parts that stack: a top bar, the content, and a footer. When the content area has flex: 1, it takes all the extra height. The footer then stays at the bottom, even when the content is short.

Example 4: A top bar, growing content and a footer at the bottom

Assumption: The app is 600px wide, so the main area is 380px wide, as in Example 2. The viewport is 320px tall (8 rows). The top bar title (T) is about 160px wide, and the user name (U) is about 80px wide.

<!-- HTML -->
<main class="main">
    <header class="topbar">
        <h1>Overview</h1>
        <span>Asha</span>
    </header>
    <div class="content">Content</div>
    <footer>Footer</footer>
</main>

/* CSS */
.app {
    display: flex;
    gap: 20px;
    min-height: 100vh;
}

.main {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.content { flex: 1; }

Expected output

|TTTTTTTT       UUUU|
|MMMMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMMMMMM|
|FFFFFFFFFFFFFFFFFFF|

The shell is at least 100vh tall, which is 320px, so the main column is 8 rows tall.
Used height = top bar 40 + footer 40 = 80px, so the free height is 240px (6 rows).
flex: 1 gives all of it to the content area, and the footer sits at the bottom.
Without flex: 1, the content would be as short as its text, and the footer would sit right under it.
The top bar is a row: space-between pushes the title and the user name to opposite ends.

5. Add stat cards and panels

Inside the content area, most dashboards show a row of numbers and then a few larger panels. Both rows are wrapping flex containers, as in the card layout. Different grow values let one panel take a larger share of the free space than another.

Example 5: Stat cards and two panels of different weight

Assumption: The content area is 380px wide, as in Example 4. There are four stat cards (K), one chart panel (C) and one activity panel (A), and each is 40px tall.

/* CSS (HTML: four .stat cards in .stats, then .panel-chart and .panel-activity in .panels) */
.stats, .panels {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
}

.stat { flex: 1 1 140px; }

.panel-chart { flex: 2 1 200px; }

.panel-activity { flex: 1 1 100px; }

Expected output

|KKKKKKKKK KKKKKKKKK|
|KKKKKKKKK KKKKKKKKK|
|CCCCCCCCCCCC AAAAAA|

Stats: two cards fit in a row (140 + 20 + 140 = 300px), and a third would need 460px, so they wrap.
Free space in a row = 380 - 300 = 80px, and each stat card grows by 40px to 180px (9 characters).
Panels: 200 + 20 + 100 = 320px fits in one row, so the free space is 380 - 320 = 60px.
Grow values share the free space 2 to 1: the chart gets 40px more (240px) and the activity panel 20px more (120px).
The grow values share only the free space. They do not set the final widths directly.

6. Make it responsive and handle wide content

Now we write the small-screen layout first. The shell is a column, so the sidebar sits on top as a strip with its links in a wrapping row. From a breakpoint, the shell becomes a row, and the sidebar becomes a fixed-width column. A wide report table sits in a wrapper that scrolls by itself.

Example 6: Mobile first, with a table that scrolls inside the main area

Assumption: The HTML is Example 4 plus a wide table (900px) inside a .table-wrap in the content area. The menu links (O, R and T) are about 80px wide, with a 20px gap. The sidebar is 240px wide on large screens, and the page has no outer padding.

/* CSS: small screens first */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.menu {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.main {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.content { flex: 1; }

.table-wrap { overflow-x: auto; }

/* CSS: larger screens, written after the base rules */
@media (min-width: 900px) {
    .app { flex-direction: row; }

    .sidebar {
        display: flex;
        flex-direction: column;
        flex: 0 0 240px;
    }

    .menu { flex-direction: column; gap: 0; }
}

Expected output

Viewport 360px wide (18 characters):
|LLLLLLLLLLLLLLLLLL|
|OOOO RRRR TTTT    |
|HHHHHHHHHHHHHHHHHH|
|MMMMMMMMMMMMMMMMMM|
|MMMMMMMMMMMMMMMMMM|
|FFFFFFFFFFFFFFFFFF|

Viewport 1000px wide (50 characters):
|LLLLLLLLLLLLHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH|
|OOOOOOOOOOOOMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM|
|RRRRRRRRRRRRMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM|
|TTTTTTTTTTTTMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM|
|............MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM|
|............FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF|

Small screen: the shell is a column, and the three links fit in one row (80 x 3 + 2 x 20 = 280px).
Large screen: the sidebar is 240px (12 characters), and the main area gets 1000 - 240 = 760px (38 characters).
The table is 900px wide, which is more than 760px, so it scrolls inside .table-wrap.
Without min-width: 0 on .main, the main area cannot become narrower than the widest content inside it,
so it would stay 900px wide and make the whole page scroll sideways.

S5. Architecture and Real-World Trade-Offs

On a real project, a dashboard is a set of layers, and each layer solves one layout problem. A team that keeps the shell, the main column and the widgets in separate small rules can change one layer without breaking the others.

How the design fits a project

Imagine a team building an admin tool with many pages. Every page reuses the same shell, and only the content inside the main area changes.

Three layers of one dashboard

Each layer has its own flexbox job and does not depend on the others.

🧭App shellSidebar and main areaShared by every page
🪟Main columnTop bar, content, footerFooter stays down
📊WidgetsStats, panels, tablesDifferent on each page
 
 
 
Row flexfixed sidebar · flexible main
Column flexheader · growing content · footer
Wrapping flexflex basis · scroll wrapper

The animation traces each layer of the dashboard to the flexbox feature that supports it.

Benefits for larger websites

  • One shell for every page: New pages only fill the main area, and the sidebar and footer stay the same.
  • Content-proof layouts: A longer menu, a taller table or an empty page does not break the shell.
  • Fewer linked numbers: Changing the sidebar width is a single edit.
  • Nested layouts: The same few properties work at every level, from the shell to a card.
  • Accessible structure: aside, nav and main are landmarks that assistive technology can jump to.

Important trade-offs

  • CSS Grid is also a strong tool for dashboards, because it can name areas such as sidebar, header and content. Flexbox is simple and enough for the shell, and many teams use Grid for the page and Flexbox inside the parts.
  • Keeping the sidebar visible while the page scrolls needs extra rules, such as position: sticky or an inner scrolling area. That is outside the scope of this article.
  • A sidebar with many links may be too tall for a small screen. The stacked strip in this article works for a few links, and for a long menu you may prefer a toggle button like the one in the navigation bar article.
  • 100vh can include the browser's address bar on some mobile browsers, so the page may feel slightly too tall. Modern browsers also offer the dvh unit, so test on real devices.
  • Charts and data tables have their own responsive needs. A scrolling wrapper keeps the layout safe, but a very wide table may still need a different design on phones.
  • A fixed sidebar width can cut long labels in other languages, so test with long and short text.
  • Dark sidebars and colored widgets need enough color contrast, and every link needs a visible focus style.

Important: Flexbox only shares space and sets direction. It does not decide which part should be fixed and which should be flexible. That is your design, written in flex, min-width and flex-direction.

S6. Common Mistakes and Best Practices

Mistake 1: Forgetting min-width: 0 on the main area

Wrong: Write .main { flex: 1; } and put a wide table inside it.

Why it fails: A flex item cannot shrink below the size of its content by default. The main area stays as wide as the table, and the page scrolls sideways.

Better: Add min-width: 0 to the main area, and put the table in a wrapper with overflow-x: auto.

Rule: A flexible area that holds wide content needs min-width: 0.

Mistake 2: Giving the sidebar only a width

Wrong: Write .sidebar { width: 240px; } and expect the width to stay fixed.

Why it fails: A flex item can shrink by default, so a wide main area can squeeze the sidebar below 240px.

Better: Write flex: 0 0 240px, so the sidebar never grows or shrinks.

Rule: A part with a fixed size must not shrink.

Mistake 3: Using a fixed height for the page shell

Wrong: Write .app { height: 100vh; } and let long content run past it.

Why it fails: The shell keeps the height of the screen, but the content does not fit inside it. Backgrounds end early and the content overflows.

Better: Use min-height: 100vh, so the shell is at least as tall as the screen and grows with the content.

Rule: Use min-height for the shell, not height.

Mistake 4: Making room for the sidebar with a margin

Wrong: Give the main area margin-left: 240px to match the width of the sidebar.

Why it fails: The two numbers must always match. If one changes and the other is forgotten, the content hides under the sidebar or leaves a gap.

Better: Let the shell share the space: a fixed sidebar and flex: 1 for the main area.

Rule: Let flexbox share the space instead of matching numbers by hand.

Mistake 5: Keeping the sidebar beside the content on every screen

Wrong: Keep a 240px sidebar in a row on a 360px phone.

Why it fails: The main area gets only 120px, which is too narrow to read.

Better: Make the shell a column first, and switch it to a row inside a min-width media query.

Rule: Write the small-screen layout first.

S7. How This Comes Up in Interviews

Question 1: How do you build a sidebar and main content layout with flexbox?

What the interviewer wants: They want to hear which part is fixed, which part is flexible, and how each is written.

Strong answer:

"I make the page shell a flex container. The sidebar gets flex: 0 0 240px, so it keeps its width, and the main area gets flex: 1 with min-width: 0, so it takes the remaining space and can still shrink. Both stretch to the same height by default, so I do not need to set a height on the sidebar."

Question 2: Why does a wide table break a flex layout, and how do you fix it?

Strong answer:

"A flex item has an automatic minimum size, so it cannot get narrower than its content. A wide table makes the main area at least that wide, and the page scrolls sideways. I set min-width: 0 on the main area and put the table in a wrapper with overflow-x: auto, so the table scrolls inside its own box."

Strong answer:

"I give the shell min-height: 100vh and make the main area a column flex container. The content area gets flex: 1, so it takes all the extra height, and the footer is pushed to the bottom. When the content is long, the page simply grows."

Question 4: When would you choose Grid instead of Flexbox for a dashboard?

Strong answer:

"Flexbox is a good fit for the shell, the sidebar and the footer, because each is a one-direction layout. Grid is the better fit when the page has named areas, or widgets that must line up in both rows and columns. In practice I often use Grid for the overall page and Flexbox inside the parts."

What should different experience levels explain?

  • Junior developer: Explain how to put a sidebar and a main area side by side, and what flex: 1 does.
  • Senior developer: Explain flex: 0 0 240px, the automatic minimum size and why min-width: 0 is needed, and how to keep a footer at the bottom with a column layout.
  • Technical architect: Explain how a shared shell, a main column and widgets stay independent, when to combine Grid and Flexbox, and how accessibility landmarks and small screens affect the design.

S8. Hands-On Practice

Beginner: Build the shell

Create the HTML and CSS from Example 2. Change the sidebar width to 240px, and add more text to the main area.

Expected result: The sidebar keeps its width, the main area takes the rest, and the sidebar grows as tall as the main area. You change only one number.

Add the sidebar from Example 3 and the main column from Example 4. Make the viewport taller than the content, and then add more content to the page.

Hint: Look at where the free space goes each time.

Expected result: The user block stays at the bottom of the sidebar, and the footer stays at the bottom of the page when the content is short. When the content becomes long, the page grows and the footer follows it.

Advanced: Build the full responsive dashboard

Build a dashboard with the shell, a sidebar, a top bar, four stat cards, two panels and a table that is wider than the main area. Use the mobile-first CSS from Example 6, and test at 360px and 1000px. Then remove min-width: 0 and see what changes.

Expected result: On the small screen, the sidebar is a strip on top. On the large screen, it is a 240px column. The table scrolls inside the main area. Without min-width: 0, the whole page scrolls sideways.

S9. Next Steps and Community

Previous article: Build a Responsive Card and Product Listing Layout.

Next article: Build a Complete Responsive Web Page Using CSS Flexbox.

Continue the series by combining what you have learned into one complete page, with a header, navigation, content sections and a footer. The shell, the columns and the wrapping rows from this article will all come back.

Try the examples in your own HTML and CSS project. Add more menu items, widen the table and shrink the screen, and watch how the layout adapts. Share your dashboard with the Upgradix community, and help other developers understand Flexbox through practical examples.

Fix the sidebar. Let the main area flex. Keep wide content inside.

Upgradix by Shrash Studio
Learn Technology. Build Your Future.
Quality Technology Education. Completely Free.

Comments & Ratings (0)

Log in or create a student account to comment and rate this article.

Be the first to comment on this article.