mx-auto Tailwind CSS Class

Center horizontally. The generated CSS output is margin-left/right: auto. This page gives you the generated CSS output, a copy-paste example, and an interactive demo for search-friendly utility lookups.

Quick Answer

mx-auto maps to margin-left/right: auto. It belongs to the Spacing category and was generated from Tailwind CSS v4.1.14 reference data.

Interactive Demo

Toggle the utility on and off, switch preview surfaces, and adjust the demo content to see how this class behaves.

Tailwind utility preview

This preview simulates the effect of mx-auto using structured data generated from your Tailwind reference snapshot.

Visual Comparison

mx-auto changes spacing rhythm by adjusting margin-left/right to auto, which affects how tightly or loosely elements sit together.

Before
Tailwind utility preview
After
Tailwind utility preview
margin-left/rightSpacingspacing

Variants & Breakpoints

Use the base utility directly, then layer state or responsive variants when the component needs more specific behavior.

ContextClass syntaxWhy use itPreview
Basemx-autoApply mx-auto directly to the element.Default application
smsm:mx-autoApplies from 640px and up.640px
mdmd:mx-autoApplies from 768px and up.768px
lglg:mx-autoApplies from 1024px and up.1024px

Utility Family Comparison

Compare nearby options and related companions so you can choose the right intensity before reaching for trial-and-error tweaks.

When to use this class

Use it when you need consistent breathing room in a component instead of ad hoc inline spacing tweaks across multiple child elements.

Watch out for

Avoid mixing multiple spacing strategies for the same relationship. Combining margin, padding, and gap without a clear rule usually creates uneven layouts.

Class Reference

FieldValue
Utility classmx-auto
CategorySpacing
CSS outputmargin-left/right: auto
Source pageCheat Sheet
Static slugmx-auto

Example Snippet

Use this code snippet as a starting point, then swap the markup around it to fit your component or layout.

html
<div class="rounded-lg border border-slate-200 mx-auto">Spacing preview</div>

Browse More

Return to the Cheat Sheet page for broader browsing, or open the Tailwind CSS Cheat Sheet to move across categories quickly.