Magento 2 issue on header minicart

Magento 2 issue on header minicart

October 14, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 2 issue on header minicart

Solving Magento 2 Header Mini-Cart Integration Issues

Hello developers! Today, I’m going to help you troubleshoot a common issue many of us face while integrating the header mini-cart into our custom themes in Magento 2.

The Issue: Missing or Misaligned Mini-Cart in Header

Our friend here is having trouble getting the mini-cart to display properly in their theme. As you can see from the screenshots, the cart icon and content are not aligned correctly when compared to the default theme layout.

The issue seems to stem from the custom XML code for the header container in the default.xml file. Let’s take a closer look at where things might be going wrong.

Analyzing the Default.xml Code

In their provided default.xml code, they’ve set up several containers and blocks, including one for the mini-cart named “minicart”. However, there are some potential issues to note:

  1. Incorrect Positioning: The mini-cart is placed after the “logo” block, which means it’s positioned below the logo in the layout hierarchy.

  2. No Alignment Specified: There’s no CSS class specified for the mini-cart container, so its alignment might be affected by other styles in the theme.

  3. Potential Overriding Styles: If the theme has custom CSS files that override the default Magento styling, this could be causing conflicts with the mini-cart layout.

The Solution: Position and Style Your Mini-Cart

To resolve this issue, you need to make sure your mini-cart is positioned correctly in relation to other header elements. Here’s how I would approach fixing it:

1. Change the Mini-Cart Positioning

Move the minicart block above the “topcartoptions” container where the top links and cart are placed by default. This ensures that the mini-cart appears alongside these elements rather than below them.

<referenceContainer name="header.container">
    <container name="header-wrapper" label="Page Header" as="header-wrapper" htmlTag="div" htmlClass="top-header">

        <!-- top links with cart -->
        <container name="topcartoptions" label="Top Cart Options" htmlTag="div" htmlClass="top-cart-options text-right" before="-">
            ...
        </container>

        <!-- Top menu -->

        ...

        <!-- mini-cart block moved here -->
        <block class="Magento\Checkout\Block\Cart\Sidebar" name="minicart" as="minicart" template="cart/minicart.phtml"/>

    </container>
</referenceContainer>

2. Add CSS for Alignment

Create a new CSS file (e.g., web/css/source/_extend.less) or modify an existing one in your theme. Add the following rules to style and align the mini-cart:

#minicart {
    display: inline-block;
    vertical-align: middle;
}

#minicart .cart-label,
#minicart .empty-container {
    position: relative;
}

This LESS code ensures that the mini-cart aligns properly with other elements in the header.

3. Check for Overriding Styles

If you still face issues, check if any CSS files in your theme are overriding the default Magento styles or layout for the header and mini-cart.

Conclusion

Remember, when working with custom themes in Magento 2, it’s crucial to understand how the layout and styling work together. By positioning the mini-cart correctly within the header container and adding appropriate alignment styles, you can ensure that your theme displays the mini-cart as intended.

Don’t hesitate to experiment with different positions and CSS rules until you achieve the perfect layout for your header. For more detailed guides on layout customization in Magento 2, feel free to explore our other blog posts on Laravel Company.

Happy coding!

Magento 2 Checkout Themes Errors

Our network