Others

How to Add a Responsive Sidebar to ASP.NET Core Razor Pages Layout

Aamir Naveed AkramAamir Naveed Akram Oct 26, 2026 868 views

Question details

The user needs to implement a responsive left navigation panel in an ASP.NET Core Razor Pages application without disrupting the header, footer, and main content.

How to Add a Responsive Sidebar to ASP.NET Core Razor Pages Layout
Product
ASP.NET Core Razor Pages
Device & OS
not provided
Scenario
Designing a web application layout containing a side navigation menu.
Observed behavior
The current sidebar implementation pushes the main page content below it instead of placing the content neatly beside it.
Before you start

Ensure you have Bootstrap linked in your ASP.NET Core project's _Layout.cshtml file, as the recommended solution utilizes Bootstrap's responsive grid system.

Solution 1Recommended

Use a Responsive Bootstrap Grid Layout

Apply Bootstrap's row and column classes to structure the layout so the navigation and content sit side-by-side.

By default, standard block-level HTML elements take up the full width of the screen, pushing subsequent elements down. Utilizing a responsive grid framework like Bootstrap allows you to divide the screen into columns. Wrapping your navigation and content in a row container and assigning specific column widths prevents the main content from dropping below the sidebar.

1
Open your layout file

In your ASP.NET Core project, navigate to the Pages/Shared folder and open the _Layout.cshtml file.

2
Create a row container

Locate the main container area between your header and footer, and wrap it in a <div class="container-fluid"> followed by a <div class="row">.

3
Assign sidebar column classes

Wrap your left navigation panel in a div with a column class for larger screens, such as <div class="col-md-3 col-lg-2 sidebar">.

4
Assign main content column classes

Wrap the @RenderBody() directive in a corresponding div that takes up the remaining grid width, for example, <div class="col-md-9 col-lg-10 content">.

5
Save and test

Save the changes to _Layout.cshtml, run your ASP.NET Core application, and resize your browser window to ensure the sidebar collapses or stacks correctly on smaller screens.

Use a Responsive Bootstrap Grid Layout
Grid Class Sizing: Bootstrap operates on a 12-column grid system. Ensure your sidebar column number (e.g., 3) and main content column number (e.g., 9) add up exactly to 12 for the intended screen size breakpoints.
Free Microsoft Office alternative

Need a powerful office suite for your project documentation?

While developing robust ASP.NET Core web applications, you likely need a reliable office suite to write technical specifications, track project tasks in spreadsheets, and create client presentations. WPS Office is a highly compatible, feature-rich alternative that easily handles all your document needs without bogging down your development machine.

  1. 1. Visit the WPS Office website: Go to the official WPS website on your browser to access the free download page.
  2. 2. Download the installer: Click the 'Free Download' button to get the lightweight installation file for your operating system.
  3. 3. Install and launch: Run the installer, follow the on-screen prompts, and start managing your development project documents seamlessly.
Fully compatible with Microsoft Word, Excel, and PowerPoint formats (.docx, .xlsx, .pptx).Lightweight installation that consumes minimal system resources.Built-in PDF toolkit for quickly reading and annotating technical guides and API documentation.Tabbed interface allows developers to open multiple documents in a single window.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my Razor Pages sidebar push the main content down?

This occurs because standard HTML elements behave as block elements that occupy 100% of the horizontal space. Without applying a flexbox, grid system, or floating layout, the browser will naturally stack block elements on top of one another.

Can I build a responsive sidebar without using Bootstrap?

Yes, you can write custom CSS using CSS Flexbox (display: flex) or CSS Grid (display: grid) on the parent container to align the sidebar and main content horizontally, alongside media queries to handle mobile responsiveness.

Where should layout changes be applied in an ASP.NET Core application?

Global layout changes, such as adding a site-wide sidebar, should be implemented in the _Layout.cshtml file, typically located in the Pages/Shared or Views/Shared folder, so they are inherited by all views.