HTML Align CenterStyling the content on a web page plays an important role, as it makes the web page attractive and captures the attention of the users. It is very common to align the text in the center. In HTML, the text can be aligned to the center with the help of the "align" attribute and by using the < center> tag. The "align" attribute and the <center> tag were supported in earlier versions of HTML. NOTE: The "align" attribute and the <center> tag are no longer supported in HTML5 in order to favor CSS (Cascading Style Sheets) for styling web pages. It is recommended to use the "text-align" property of CSS to align text to the center instead of the HTML "align" attribute and the <center> tag.HTML <Center> TagThis tag specifies the center alignment of the text, so you can use the < center> tag to control the alignment of different elements. Syntax:The syntax shown above includes the <center> opening tag & </center> closing tag, and the content is written between the opening tag and the closing tag, which will be center-aligned. Examples of Aligning Text to Center in HTML using < center> TagExample 1: In this example, we have aligned the text written in <h1> and <p> tag using < center> tag. Code: Output: As you can see in the output below, the text inside the <h1> and <p> tags is aligned to the center. Example 2:In this example, we will write many HTML tags inside the <center> tag. Code: Output: As you can see in the output below, the text inside each tag is centered on the web page. "Align" AttributeIn HTML, the "align" attribute is used to align text in the center, left, or right on the web page. You can implement this attribute by writing it inside the opening HTML tag. Syntax:
Examples of Aligning Text in HTML using the "Align" AttributeExample 1: In this example, we will align the HTML elements to the center. Code: Output: Example 2: In this example, we will demonstrate the alignment of HTML elements to center, left, right, and justify. Code: Output: Browsers Support
Conclusion
Next TopicHTML Font Family |