Topics Covered in This Web Development Tutorial:
Mastering Flexbox Order Property: Changing the Order of Flex Items, Understanding Positive vs. Negative Order Values
Exercise Preview

Exercise Overview
In this hands-on exercise, you'll master one of CSS Flexbox's most powerful features: the ability to visually reorder content without touching your HTML structure. This technique is essential for responsive design, allowing you to create different layouts across screen sizes while maintaining semantic HTML order. You'll learn how to strategically use positive and negative order values to achieve pixel-perfect layouts that adapt seamlessly to any device.
This exercise assumes familiarity with basic Flexbox concepts and CSS media queries. Ensure you have a code editor and browser ready for hands-on practice.
Strategic Content Ordering in Modern HTML
When structuring content in HTML, you face a critical decision: should you order elements according to mobile or desktop layout priorities? The answer significantly impacts your development workflow and user experience.
Mobile-first development has become the industry standard in 2026 for compelling reasons:
Development Efficiency: Mobile layouts typically rely on vertical stacking—the browser's natural document flow. This means less CSS override work initially, then progressive enhancement for larger screens using media queries and flexbox properties.
User-Centric Approach: With mobile traffic consistently exceeding desktop usage across most industries, prioritizing your primary audience makes business sense. Your mobile experience becomes the foundation, not an afterthought.
Best practice dictates that your HTML order should follow logical, semantic structure—which typically aligns with your ideal mobile layout. Then use CSS flexbox order properties to adapt that structure for larger screens without compromising accessibility or SEO.
Getting Started
Let's set up your development environment and examine the starting point for this exercise.
- In your code editor, close any files you may have open to start with a clean workspace.
- For this exercise we'll be working with the Flexbox Reorder Content folder located in Desktop > Class Files > yourname-Flexbox Grid Class. If your code editor supports project folders (like Visual Studio Code, WebStorm, or Sublime Text), open the entire folder for easier file navigation.
- Open index.html from the Flexbox Reorder Content folder.
Preview index.html in a browser and examine the responsive behavior:
- Resize the window to be narrow (mobile width) to see how the navbar and footer items stack vertically instead of displaying in a single row.
- Notice that the order of items in both the navbar and footer differs from previous exercises. We've intentionally structured the HTML in the optimal semantic order, which displays correctly on mobile devices.
- Expand the window to desktop width to see the navbar and footer items display as horizontal rows.
- We'll be strategically reordering some elements to optimize the desktop layout while preserving the mobile experience.
Keep index.html open in your browser as you work—you'll reload the page frequently to observe your CSS changes in real-time.
Exercise Setup Process
File Preparation
Close existing files and navigate to Desktop > Class Files > yourname-Flexbox Grid Class > Flexbox Reorder Content folder
Open Project Files
Open index.html from the Flexbox Reorder Content folder in your code editor
Preview and Test
Open index.html in browser and resize window to observe different layouts at various screen sizes
Analyze Current Order
Note how navbar and footer items display differently in mobile vs desktop views
Reordering Content in the Footer (Positive vs. Negative Order Values)
Now we'll explore how flexbox order values work. Understanding this concept is crucial: the default order value for all flex items is 0. This means any negative value moves an item toward the beginning, while positive values move items toward the end.
- Switch back to your code editor.
- Open main.css from the css folder (in the Flexbox Reorder Content folder).
In the min-width: 571px media query, below the footer rule add the following new rule:
footer .social { order: -1; }NOTE: The order property only works on flex items. This works here because the .social div is a direct child of the footer, which has display: flex applied.
Save the file, and reload the page in your browser.
- The social div now appears first because -1 is less than the default value of 0. Negative values are powerful for moving important elements to prominent positions without restructuring HTML.
- Return to your code editor to experiment with positive values.
In the min-width: 571px media query's footer .social rule, change the order to 1:
footer .social { order: 1; }Save the file, and reload the page in your browser.
- The social div has moved to the end because 1 is greater than the default 0. This demonstrates how positive values push elements toward the end of the flex container.
The order property only works on flex items. Elements must be direct children of a flex container to be reorderable.
Order Value Effects
| Feature | Negative Values | Positive Values |
|---|---|---|
| Default Comparison | Less than 0 (moves earlier) | Greater than 0 (moves later) |
| Example: order: -1 | Moves to beginning | Not applicable |
| Example: order: 1 | Not applicable | Moves to end |
| Default Value | All flex items start at 0 | All flex items start at 0 |
Reordering Content in the Navbar
Next, we'll tackle a more complex reordering scenario in the navigation. This section demonstrates how to strategically assign order values when you need precise control over multiple elements.
- Return to your code editor.
In the min-width: 571px media query, below the .navbar .logo rule add the following new rule:
.navbar .signup { order: 1; }Save the file, and reload the page in your browser.
- The Sign Up button now appears at the far right because 1 is greater than the default 0.
- This positioning works for our current needs, but what if we wanted Sign Up to appear between Excursions and About? Simply setting order to 3 won't make it third, because the other items still have the default order of 0. We need a more systematic approach.
- Return to your code editor to implement a comprehensive ordering system.
In the min-width: 571px media query, above the .navbar .logo rule add the following new rule:
.navbar li { order: 5; }NOTE: By assigning a higher default number (5), we create room for lower numbers (1-4) to control the order of specific elements. This is a professional technique for maintaining flexible, scalable CSS.
In the min-width: 571px media query's .navbar .logo rule, add the following bold code:
.navbar .logo { order: 1; margin-right: auto; }In the min-width: 571px media query, below the .navbar .logo rule add the following new rule:
.navbar .excursions { order: 2; }In the min-width: 571px media query, in the .navbar .signup rule change the order to 3:
.navbar .signup { order: 3; }Save the file, and reload the page in your browser.
- The navigation order on wider screens should now display as: Logo, Excursions, Sign Up, About, Contact. This creates an optimal user flow for desktop users.
- Test the responsive behavior by resizing your browser window. Verify that all order changes only apply at desktop width (thanks to the media query) while mobile maintains the original, semantically logical order.
You've now mastered the fundamentals of flexbox content reordering. This technique is invaluable for creating responsive designs that prioritize user experience across all devices while maintaining clean, semantic HTML structure. The ability to reorder content with CSS alone gives you tremendous flexibility in responsive design without compromising accessibility or SEO performance.
Strategic Order Assignment
Set Base Order
Assign all navbar list items order: 5 to create numbered space for specific positioning
Position Logo First
Set navbar logo to order: 1 to ensure it appears at the beginning
Order Navigation Items
Assign order: 2 to Excursions and order: 3 to Sign Up for desired sequence
Leave Remaining Default
About and Contact keep order: 5, appearing after specifically ordered items
Use higher default numbers (like 5) for groups of items to leave room for inserting specific items at lower numbers (1, 2, 3) in desired positions.
Final Layout Result
Logo
First position with order: 1
Excursions
Second position with order: 2
Sign Up
Third position with order: 3
About & Contact
Final positions with order: 5