Computer >> Computer tutorials >  >> Programming >> HTML

How to set Heading alignment in HTML?


Headings in HTML have 6 tags, <h1> to <h6>. To set the heading alignment in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <h1> to <h6> tag, with the CSS property text-align. HTML5 do not support the align attribute of the heading tag, so the CSS style is used to set alignment.

Just keep in mind, the usage of style attribute overrides any style set globally. It will override any style set in the HTML <style> tag or external style sheet.

How to set Heading alignment in HTML?

Example

You can try to run the following code to set heading alignment in HTML

<!DOCTYPE html>
<html>
   <head>
      <title>HTML Document</title>
   </head>

   <body>
      <h1 style="text-align:center">Tutorial</h1>
      <p>Learn for free</p>
   </body>
</html>

Output

How to set Heading alignment in HTML?