\ Tailwind is an increasingly popular and widely used framework, which makes it easier in some cases to build and ship features and products. In this guide, we'll be covering how you can vertically and horizontally center an element or text with tailwind. \ In another article, I've already covered how to center an HTML element both horizontally and vertically using CSS. If you want to learn about that, __[click here](https://hackernoon.com/vertically-centering-text-and-html-elements-with-css)__. ## Horizontally and Vertically center an element with Tailwind Horizontally and vertically centering something with Tailwind is easy with `flexbox`. All we have to do is three things: \ * use `h-screen` to make the element the height of the screen * use `flex` to make the element a `flexbox` * use `items-center` to vertically center it * use `justify-center` to center it horizontally \ Our code then looks like this: \n ```javascript <div class="h-screen flex items-center justify-center"> Horizontally and Vertically Centered Element </div> ``` \ Which produces a result like this: See the Pen __[Horizontally and vertically centering with Tailwind](https://codepen.io/smpnjn/pen/rNrPENZ)__ by smpnjn (__[@smpnjn](https://codepen.io/smpnjn)__) on __[CodePen](https://codepen.io/)__. ## Vertically centering an element with Tailwind The easiest way to vertically center something is to do what we did before, and use `flexbox`. This time, though, we'll remove `justify-center`. The item will then be centered only along the vertical axis. \n ```javascript <div class="h-screen flex items-center"> Vertically Centered Element </div> ``` You can see an example of this in the codepen below: See the Pen [here](https://codepen.io/smpnjn/pen/jOpdoJL). ## Horizontally centering an element with Tailwind In the same way that we vertically centered the div above, we can also horizontally center using our previous approach. The code for that looks like this: \n ```javascript <div class="flex justify-center items-center"> Horizontally Centered Element </div> ``` \ This is the same code we used for horizontal and vertical centering, just without `h-screen`. Here's the result: See the Pen [here.](https://codepen.io/smpnjn/pen/xxJMNoM) ## Conclusion Centering elements with flexbox is easy in Tailwind. In this guide, we've learned how to vertically and horizontally center elements including HTML elements and text - which is infinitely useful in web development. \ To learn more about **CSS** in general, you can __[find my other content here](https://hackernoon.com/u/smpnjn)__. \ --- Also published [here.](https://fjolt.com/article/css-tailwind-center-elements)