There are a lot of different techniques that will allow you to align images, both HTML and CSS techniques, but one of the easiest ways to align an image to the left or right of a page or element is to use floats. When you float an image to the left or to the right of a page, not only will it align the image to the left or the right side, but it’ll also wrap the nearest elements around the image, unless you clear the float.
To align an image to the right side of a page or element using floats, you’ll want to float it right. Here’s how that CSS would look:
- float: right;
The results of the above code would look like this:
If you want to float an image to the left, your code would be very similar to what’s above:
- float: left;
And your results would look very similar to the default image positioning:
Except that any content surround the images (text, other HTML elements) would wrap around the image and appear right next to it on its right side (see example below). If you don’t float the image, then all of that content would appear below it, so if you really want to align the image to the left, be sure to float it.
And if you don’t want all of your HTML elements or text to be aligned to the right of your image, don’t forget to clear your floats!