Open links in new tab
  1. The <center> tag was used in HTML4 to center-align text or other content on web pages. However, this tag is deprecated in HTML5 and has been replaced by more modern and flexible CSS techniques.

    Example using <center> Tag

    <!DOCTYPE html>
    <html>
    <head>
    <title>HTML Center Tag</title>
    </head>
    <body>
    <h2>Welcome to GeeksforGeeks</h2>
    <center>Hi Geeks</center>
    </body>
    </html>

    Example using CSS

    To center content using CSS, you can use the text-align property for text and margin: 0 auto; or display: flex; justify-content: center; for block-level elements.

    <!DOCTYPE html>
    <html>
    <head>
    <title>CSS text-align property</title>
    <style>
    .center-text {
    text-align: center;
    }
    .center-block {
    display: flex;
    justify-content: center;
    }
    </style>
    </head>
    <body>
    <h1 class="center-text">GeeksforGeeks</h1>
    <div class="center-block">
    <p>CSS center property</p>
    </div>
    </body>
    </html>

    Note: The <center> tag is obsolete in HTML5 and should be avoided in favor of CSS for centering content. Using CSS provides more versatile and consistent ways to center content across different devices and screen sizes.

    Feedback
  1. How to Center Text in HTML? - GeeksforGeeks

    Nov 6, 2024 · To center text in HTML, we can use CSS text-align: center property. It aligns the text to center horizontally. The <center> tag was used in older versions to center the text horizontally, but it is depreciated in HTML 5.

  2. How to Align Text in HTML – Text-align, Center, and …

    Sep 22, 2022 · center: You use this to align the texts to the perfect center of the page or container. justify : You use this to adjust the text content to touch the left and right edges of your page or container. The general syntax would be:

  3. How to align entire html body to the center? - Stack …

    Jun 24, 2011 · Solutions 1 (flex + justify-content) and 3 only align vertically to the center, content is still aligned to the right. Solution 2 (flex, margin: auto) works …

    • Reviews: 2
    • How to center text in HTML - Computer Hope

      May 1, 2023 · To center text using HTML (HyperText Markup Language), you can use the <center> tag or use a CSS (Cascading Style Sheets) property. To proceed, select the option you prefer and follow the instructions.

    • HTML center Tag | GeeksforGeeks

      Apr 17, 2025 · The <center> tag in HTML was used to horizontally center content on a webpage. However, it is deprecated in HTML5 and should no longer be used. Alternatively, we will use the text-align property. Related Article:

    • How to Center Text in HTML (with Pictures) - wikiHow

      Mar 10, 2025 · This wikiHow teaches you how to center text in an HTML website using Cascading Style Sheets (CSS). Centering in HTML used to be done with the <center> tag, but that tag is now considered obsolete …

      • Views: 244.1K
      • How to Center Content in HTML

        Centering content in HTML is a common task for web developers, whether it’s centering text, images, or entire divs within a webpage. This guide will cover various methods to achieve centering in HTML, using CSS. We’ll explore different scenarios including centering text, images, divs, and even vertically centering content.

      • How to Center Text in HTML - HogoNext

        Mar 1, 2025 · For simple horizontal centering of block-level text, use text-align: center;. For centering a block element itself, use margin: 0 auto;. For complex layouts and precise centering in both directions, use Flexbox or Grid. For single line vertical centering, use line-height. For older browsers, text-align, margin: auto and padding are more reliable.

      • HTML <center> Tag - W3docs

        You can use the CSS margin-right and margin-left properties to center blocks. The <center> tag comes in pairs. The content is written between the opening (<center>) and closing (</center>) tags. As we’ve already mentioned, the <center> tag isn’t supported in HTML5․. Instead, we use CSS styles. How to style <center> tag?

      • Some results have been removed
      Refresh