CSS align

You may be familiar with the HTML align attribute (which has been discontinued as of HTML 5). The align attribute could be used with tags such as <table>, <td>, and <img> to specify the alignment of these elements. This attribute allowed you to align elements horizontally. HTML also has/had a valign attribute for aligning elements vertically. This has also been discontinued from HTML5.

These attributes were discontinued in favor of using CSS to set the alignment of HTML elements.

There isn't actually a CSS align or CSS valign property. Instead, CSS has the text-align which applies to inline content of block-level elements, and vertical-align property which applies to inline level and table cells.

CSS text-align example

In this example, we use text-align:right to align the contents of the <div> to the right.

The css text-align property applies to the contents of the block-level element - it doesn't need to be text. For more information on usage, see the text-align property page.

CSS vertical-align example

Here, we align an image vertically using the vertical-align property.

CSS float Property

Depending on what you're trying to do, you might find that the CSS float property might be more suitable.