How to Fixed an Element to Center in Tailwind CSS? Last Updated : 15 Nov, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Here are two different methods to center an elementwith Tailwind CSS.1. Using mx-auto ClassWe can use the 'mx-auto' utility class to center an element horizontally. The "mx-auto" class centers an element horizontally within its parent container by setting the left and right margins of the element to "auto." HTML <!DOCTYPE html> <html> <head> <script src="https://cdn.tailwindcss.com"></script> </head> <body> <div class="flex h-screen items-center"> <h3 class="mx-auto">CODE WORLD</h3> </div> </body> </html> Output 2. Using items-center ClassWe can use the "flex" and "items-center" utility classes to center an element vertically. The "items-center" class centers the child element vertically within the parent container, and the "flex" class transforms the parent container into a flex container. HTML <!DOCTYPE html> <html> <head> <script src="https://cdn.tailwindcss.com"></script> </head> <body> <div class="fixed top-0 left-0 w-screen h-screen flex items-center justify-center"> <p class="text-black text-2xl"> CODE WORLD </p> </div> </body> </html> Output Example: The fixed container is positioned at the top-left of the viewport with a width and height of 100%, using the fixed, top-0, left-0, w-full, and h-full classes. The flex, items-center, and justify-center classes are applied to center the content of the fixed container both vertically and horizontally. HTML <!DOCTYPE html> <html> <head> <link href= "https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet"> </head> <body> <div class="fixed top-0 left-0 w-full h-full flex items-center justify-center"> <div class="bg-white p-6 rounded-lg shadow-lg"> <h1 class="text-red-500 text-5xl font-bold text-center my-5"> Google </h1> <p class="text-gray-600"> Thanks for visiting this site. Please feel free to explore and let me know if you have any questions. </p> </div> </div> </body> </html> Output Comment More infoAdvertise with us Next Article How to Fixed an Element to Center in Tailwind CSS? W wireleesnotes Follow Improve Article Tags : HTML Tailwind CSS-Questions Similar Reads How to Align Form Elements to Center using Tailwind CSS? Form elements are parts of a webpage that let users enter information. They include things like text boxes, checkboxes, radio buttons, dropdown menus, and buttons. To center form elements using Tailwind CSS, use classes like flex, items-center, and justify-center on a parent container.These are the 2 min read How to centre an Element using Tailwind CSS ? Tailwind CSS follows a utility-first approach, which means that instead of writing custom CSS for each component, we can utilize pre-defined classes that apply specific styles directly to HTML elements. We can center an element by using the utility classes of "margin" and "flex". This article will g 3 min read How To Center An Absolute Element In TailwindCSS? In TailwindCSS, aligning elements to the centre involves using different positioning strategies. By using utilities like flex, grid, and positioning classes such as absolute, top-1/2, and left-1/2, you can achieve precise centring of elements within their containers. These are some ways to Center an 3 min read How to Add Space Between Elements in Tailwind CSS ? Spacing between elements is a critical aspect of web design, affecting readability, flow, and the overall aesthetic of a website. Tailwind CSS, a utility-first CSS framework, provides an extensive set of spacing utilities that make it basic to control padding, margin, and gap spaces within and aroun 2 min read How to Center an Image using Tailwind CSS ? Here are the methods to center an image using Tailwind CSS:Method 1. Using Flexbox ClassesThis method centers the image both horizontally and vertically using Tailwind's flex, justify-center, and items-center classes.HTML<html> <head> <script src="https://cdn.tailwindcss.com"></ 2 min read Like