HTML Questions & Answers Logo
HTML Questions & Answers Part of the Q&A Network
Q&A Logo

How can I center text inside a <div> without using CSS classes?

Asked on Sep 10, 2025

Answer

To center text inside a <div> without using CSS classes, you can use the align attribute directly within the <div> tag. However, it's important to note that this attribute is deprecated in HTML5, and using CSS is the recommended approach.
<!-- BEGIN COPY / PASTE -->
    <div align="center">
      Centered text inside this div.
    </div>
    <!-- END COPY / PASTE -->
Additional Comment:
  • The align attribute is not recommended for modern web development.
  • Using CSS with text-align: center; is the preferred method.
  • Deprecated attributes may not be supported in future browser versions.

✅ Answered with HTML best practices.


← Back to All Questions
The Q&A Network