Using the p align attribute in HTML and XHTML

There are several ways to align block elements (tables, images, objects, and paragraphs) on the canvas. They are based on the align attribute.

The p> start tag has the alignment attribute that can have values like left, right, center and justify. However, the align attribute is obsolete in favor of CSS text-align property.

Paragraph Alignment

Paragraph alignment, also known as justification, determines how the lines of a paragraph are aligned. The paragraph start tag p> supports four alignment types: left, center, right, and justify.

The default paragraph alignment is left-aligning, which makes sense because most people read English from left to right. However, when you use center or right alignment, the starting point of each line changes, creating a jagged edge that may be harder to read.

The paragraph alignment attribute — formerly called the align attribute — is deprecated in HTML and XHTML, in favor of style sheet-based layout controls. Nevertheless, it is still supported in some browsers and may be used with the p> tag. You can also set paragraph alignment using the CSS text-align property. Unlike the paragraph-alignment attribute, which specifies an inline style, text-align sets a global style for the entire page. For example, if you set the text-align property to justify for a paragraph, all of the paragraph’s lines will be justified.

Text Alignment

The p align> tag provides four kinds of text alignment: left, right, center, and justify. This attribute, however, is deprecated in HTML 4 and XHTML, in favor of style sheet-based positioning through the text-align property.

Most people read English from left to right, and the majority of web pages use this default alignment. This is because it allows the reader to follow a straight edge without having to start each new line at a different point, which could cause jagged lines that are difficult to read.

If you need to change this alignment, simply add the text-align:’left’, ‘right’, ‘center’ or ‘justify’ property to the opening tag of the element in question. Note that this will only work if your site has an overriding style sheet that will apply these changes to all elements. Otherwise, you’ll need to manually add the text-align code to each element within the > symbols. This is a bit more time-consuming, but it’s the only way to ensure that each element will be positioned exactly how you want it to be displayed.

Image Alignment

Although a minor detail, image alignment is important because it can affect the appearance of your website. Knowing how to align images correctly can help you bring a sense of balance and symmetry to your page layout.

Aligning images can be done using the float or text-align properties. The former is used when the image is inline, while the latter is used for images that are inside a block of text.

If you want an image to be centered, simply add the text-align: center; property to the parent element that contains the img> tag. Make sure the img> is contained in a block-level element like a div.

The float property sets the object to “float” over its current margin, which allows subsequent text to flow against it. This is useful for displaying images in horizontal rows, which is commonly found on blogs and social media websites. The float property is also the preferred method for aligning images in table cells in HTML.

Section Alignment

Unlike word processors, which usually force lines of text to wrap or break at the longest possible length when the width of a line exceeds that of the browser window, HTML and XHTML give you the ability to control paragraph justification with the p> tag. You can use the align attribute to set four kinds of paragraph justification: left, right, center, and justify.

The default is left-aligned, which mimics the way people normally read English. Once the Web begins supporting languages like Arabic that are written right to left, however, the default alignment may change.

For any element other than a p> tag, you can set its alignment with the CSS style property. To change the alignment of an existing element, replace its opening p> tag with a p style=”text-align:center”>/p> tag. This will override any coding for that element in the site’s style sheet or an external style sheet. You can also use the float property to align images or other objects.

Return to the home screen