Free Online CSS Centering Generator for Every Method
Say what you are centring, a box, some text, an icon beside a label, an overlay or a whole page, and in which axis, and the page lists every method that actually works for that case with the trade-off of each. The preview has a height control, because most centring bugs are a container with no spare room.
container 220px tall both axes
Enjoying WizTools123? Help keep our server infrastructure 100% free and open for everyone.
How to Centre Anything in CSS
A few steps, and nothing is uploaded.
What to Know About Centring in CSS
Including the two that waste the most time.
vertical-align: middle almost never does what people expect. It does not centre a block inside its parent. It only aligns inline-level boxes against each other within a single line box, and it aligns the middle of the box with the middle of the parent's x-height, not the middle of the parent. So it can nudge an icon against neighbouring text, which is a real use, and it works on table cells where it aligns cell content. Everywhere else it appears to do nothing, because there is no line box for it to act in. For a block inside a container, use flex, grid or align-content.
transform: translate(-50%, -50%) can blur text. If the element's size is an odd number of pixels, half of it is not a whole pixel, so the element is painted on a half-pixel boundary and the browser antialiases the text. It is subtle but visible on thin fonts at normal weight. The cures are an even width and height, rounding the size, or using a method that does not involve a fractional translate: flex, grid place-items, or absolute with inset: 0 and margin: auto. The last one needs a known width and height but produces integer positions.
align-items: center distributes free space, and a container that has sized itself to its content has none, so nothing appears to happen. This is the most common report of "centring does not work". Give the container a height, a min-height, or make it a flex or grid item that gets stretched, and the same rule starts behaving. Drag the height control on the preview down to see this happen deliberately.
Key Features & Capabilities
What this tool does, and what it deliberately does not.
About the CSS Centering Generator
Centring in CSS has a reputation it half deserves. Horizontally centring a block has been one line since the nineties. Vertically centring anything was genuinely awkward until flexbox, and the old workarounds survive in enough tutorials that people still reach for vertical-align or a negative margin and then wonder why the result moves when the text changes length.
This page asks the two questions that decide the answer: what are you centring, and in which axis. An overlay pinned over a card has different options from a line of text, and a whole page has different options again because the container is the viewport. Only the methods that apply are shown, each with the condition it needs and the thing it costs you, so the choice is made on the trade-off rather than on which snippet came up first.
The height slider is the part that matters most. Nearly every real centring bug is a container that has no spare vertical space, so align-items: center has nothing to distribute and appears to be ignored. Being able to drag the container shorter and watch each method behave differently teaches the underlying rule faster than any amount of prose, and it also shows which methods overflow and which clip.
Frequently Asked Questions
Flex against grid, absolute methods, and why vertical centring fails.
display: grid; place-items: center is the shortest thing in CSS that centres in both axes, and it does not affect the child's sizing. Flexbox with align-items and justify-content is two properties but is more familiar and easier to extend when a second child arrives. If you are only ever centring one element, grid is tidier.height or min-height, or make sure the container is itself being stretched by its own parent. On a page-level container, min-height: 100dvh is usually what you want, since 100vh is wrong on mobile browsers with a retracting toolbar.align-content now works on a plain block container, not just on flex and grid. So display: block; align-content: center vertically centres the in-flow children without changing the display type at all, which means nothing else about the layout shifts. Support is good in current browsers but not in older ones, so treat it as a progressive improvement over a flex container rather than a replacement yet.inline-flex container with align-items: center and a gap. That aligns the two boxes by their centres and spaces them without a margin hack. vertical-align: middle can get close, but it aligns against the x-height of the text rather than its centre, so the result shifts whenever the font or the line height changes.