In this tutorial:

Images can be incorporated into your website is various way. They can be aligned and floated to allow the images to be placed in particular location in the page. How you want to display the images will determine whether you will align or float the image.

Aligned images do not wrap text around them. Aligning images will only position the image left, right, or center with the text following before and after the image. Aligning leaves quite a bit of white space on your site. You will see the white space when you go though the aligning section.

A floated image will allow the text to wrap around the image like a regular book or newspaper would do. Images can also be floated so they appear horizontally on your site. This is good for displaying images like a gallery. The following sections will explain how to float and align images using CSS.

Left, center, and right align

Images can be aligned left, right, and center using the div tag and an inline CSS style. Text DOES NOT wrap around images that are simply aligned. The following explains how to align your images left, right, and center using CSS.

Left Align

The line of code below is for aligning an image to the left.

<div style="text-align: left"><img src="/support/image/your-image.png" width="100" /></div>
Image Sample 1

Center Align

The following line of code is for centering an image.

<div style="text-align: center"><img src="/support/image/your-image.png" width="100" /></div>
Image Sample 2

Right Align

The folowing line of code contains the CSS attribute for aligning right.

<div style="text-align: right"><img src="/support/image/your-image.png" width="100" /></div>
Image Sample 3

Floating images using CSS

Floating images allows images to horizontally align with each other and allows text to wrap around he image. The following will explain horizontally aligning images and floating images around text.

Floating images left to wrap text

<img style="float: left; margin: 0px 15px 15px 0px;" src="/support/image/your-image.png" width="100" />

Image Sample 4Nunc pulvinar lacus id purus ultrices id sagittis neque convallis. Nunc vel libero orci. Vivamus at dolor a nibh aliquet luctus. Duis imperdiet mi id lorem pellentesque tempus. Ut quis felis posuere tellus feugiat ultrices. Praesent id tortor non tellus viverra placerat. Vivamus euismod nisi a leo interdum molestie ornare tellus consectetur.

Nullam cursus varius tellus, id laoreet magna hendrerit at. Nulla sit amet purus at nunc blandit ultricies eu a urna. Proin euismod porttitor neque id ultricies.

Important! Floated images will overlap each other if the float is not cleared. Make sure you are placing a clear float code after each section your image is floating in. Below is the code to clear your floats.

<br style="clear:both" />
Here is an example:
<p><img style="float: left; margin: 0px 15px 15px 0px;" src="/support/image/your-image.png" width="100" />
Nunc pulvinar lacus id purus ultrices id sagittis neque convallis. Nunc vel libero orci. 
<br style="clear: both;" /></p>

 

Floating images right to wrap text

<img style="float: right; margin: 0px 0px 15px 15px;" src="/support/image/your-image.png" width="100" />

Image Sample 5Pellentesque mattis tincidunt porttitor. Praesent commodo quam at elit posuere sed tempor risus tincidunt. Maecenas condimentum iaculis ligula, sit amet scelerisque nibh aliquam in. Quisque ornare gravida est ut fermentum. Nam venenatis pretium enim, in laoreet nibh tristique sit amet.

Nullam cursus varius tellus, id laoreet magna hendrerit at. Nulla sit amet purus at nunc blandit ultricies eu a urna. Proin euismod porttitor neque id ultricies.

Floating images left horizontally

This will use the same code as before (See below). The images are simply placed one after another to get them to float horizontally.

<img style="float: right; margin: 0px 0px 15px 15px;" src="/support/image/your-image.png" width="100" />

Image Sample 6 Image Sample 7 Image Sample 8 Image Sample 9

Floating images inline with each other is a nice way to display your images as a Gallery. This concludes How to Align and float images with CSS.

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve this article:
Email Address
Name

new! - Enter your name and email address above and we will post your feedback in the comments on this page!

Like this Article?

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question
n/a Points
2014-05-04 5:13 am

This is a good introduction to css for the beginners

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

1 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!