InMotion Hosting Support Center

In this tutorial:

Images can be incorporated into your website in 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 the 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. Proin faucibus convallis elit. Maecenas rhoncus arcu at arcu. Proin libero. Proin adipiscing. In quis lorem vitae elit consectetuer pretium. Nullam ligula urna, adipiscing nec, iaculis ut, elementum non, turpis. Fusce pulvinar.

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. 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. Aenean sed turpis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec sem eros, ornare ut, commodo eu, tempor nec, risus. Donec laoreet dapibus ligula. Praesent orci leo, bibendum nec, ornare et, nonummy in, elit. Donec interdum feugiat leo. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Pellentesque feugiat ullamcorper ipsum.

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. Join our community now to receive specialized help with HTML and design, special offers, and cool gear. In the next tutorial, we will show you how to make a simple CSS Drop Down Menu.

Looking for more help with CSS? Check out our introduction to CSS guide!

Continued Education in Course 102: Inserting Images into a Website
You are viewing Section 5: Align and float images with CSS
Section 4: How to make an Image a Link

Support Center Login

Social Media Login

Social Login Joomla

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

n/a Points
2014-08-06 12:00 pm
I would not call myself a CSS beginner, but neither would I call myself an expert. I have been playing with HTML and CSS for about 8 years, just started getting deeper into HTML5 and CSS3. Articles like this are sometimes a kick in the pants for me and reminds me of things I already know, just not thinking about.
Thanks for the reminder!
n/a Points
2014-08-11 8:15 am


Thanks for the code and the effect of the cod.

Its help me to set my image name in the center after the image.Thanks agian.

n/a Points
2014-08-18 5:40 am
Keep keeping it simple for easy understanding.
n/a Points
2014-10-18 3:04 pm

Thanks for your sharing, great knowledge.


n/a Points
2014-11-05 1:20 pm

I'm a bigginer trying to follow this course step-by-step but i got stuck.

Can anyone help me understand the margin used in floating images:

  ( margin: 0px 0px 15px 15px)

Thank you ver much!!!!

16,204 Points
2014-11-05 1:42 pm
Hello Gasana,

Thank you for your question. The margin is in pixels, and goes counter clockwise (top, right, bottom, left).

For example this (margin: 0px 0px 15px 15px), would result in this:
Top margin: 0px

Right margin: 0px

Bottom margin: 15px

Left margin: 15px

So if you wanted a 15 pixel margin on the top of the image too, you would change it to:
(margin: 15px 0px 15px 15px)

If you have any further questions, feel free to post them below.

Thank you,
n/a Points
2014-11-06 5:25 pm

Hi John-Paul,

How about aligning an image used as a link. I want to use a small image instead of the word for "Contact" but it sits slightly above from the rest of the meny text links. I tried align:"bottom", vertical-align:"bottom" and align:"baseline", but the image never moved. Any other tricks to get the image to sit in line with the text in other menu links (the menu is horizontal)?


16,204 Points
2014-11-06 5:39 pm
Hello Miguel,

Thank you for your question. It really depends on your site, if you can provide a link we'd be happy to test further.

But, you may want to try testing the vertical-align.

vertical-align: bottom;

Thank you,
n/a Points
2014-11-06 6:03 pm

Hi John-Paul,

Tried vertical-align: bottom; too. Admittedly I did it in html, right after the img src in the link for the contact page, not in the css, but it did nothing for me.

The link to the page is I just put it up (still in design) for you to have a look.


16,204 Points
2014-11-06 6:42 pm
Hello Miguel,

Thank you for the information. This article and my previous response are only in regards to CSS, and not HTML.

If you want to work with the image in HTML, please see this img tag reference. It explains the options for using the img tag in depth, however, I recommend doing this in css.

I could not identify the specific CMS you are using, but keep in mind your theme/plugins may be over riding the code you are working with.

I see the envelope on the top right of the page. While it is slightly above the text next to it, the underline underneath (it appears when you mouse over) is lined up with the rest of the menu. So, the bottom does seem to be aligning.

It really boils down to how you want to code the site, and your comfort level. But you may want to try aligning the top of the other menu items with the top of the envelope, or making the header bar larger to accommodate the envelope sliding down.

Thank you,
n/a Points
2014-11-06 6:59 pm

Hi John-Paul,

Yes, my issue was meant to be a css solution. Apologies for not making that clear. I tried to solve it in both ways with no effect. I'll try to align them on the top. That may be the way to go. Thank you for your advice, it is helpful.


n/a Points
2015-01-09 7:09 am

Thank you for this beneficial episode

n/a Points
2015-01-13 9:34 pm

Hi John-Paul,

I'm trying to align 2 images on the left margin of the pagedown the page - but the 2nd image keeps wrapping to the right of the 1st image

11,156 Points
2015-01-13 10:01 pm
If you add clear:both the the CSS of the second div, it shoould put it below the first one.
n/a Points
2015-01-20 11:10 am

hi good day. please I am trying to align my images vertically on the left so they orderly in a line. What will the code be. presently as I put in the codes, the images outling themselves horizontally. your promot response will be greatly appreciated. thanks alot

11,156 Points
2015-01-20 11:17 am
To do so, you will need to add clear: both to the styling of subsequent images after the first.
n/a Points
2015-01-21 5:56 pm

Hello and thank you so much for giving us this information! I would like to know if there is a way to float image 'center' horizontally. So far I haven't found a code that works. It seems simple enough to put <img style="float: center;" but of course, it doesn't work.... Can you show me what I'm forgetting? Thank you so much for your time.

24,830 Points
2015-01-21 6:07 pm
Hello LL,

Thanks for the question. Centering images can be a pain. The best way is to create a style class that you put in the HEAD of your HTML page. It will look like this:

<style type="text/css">

Then in the code for your image element, you would specify:

<p class="centerimage"><img src="/support/graphic.jpg" ></p>

You can your add the ALT text, size, etc. for your image as well. If you want it to apply to ALL of your pages, then you would add the style to your CSS. I hope this helps to answer your question, please let us know if you require any further assistance.

Arnel C.

n/a Points
2015-01-28 8:15 am
Its really helpful bt you just given only the code... For beginners it will be little tough to learn.. So i request you to give some examples for this code and also editing the code in online.... The users can modify or edit the code they can learn more... So i feel it will be useful for the users....
n/a Points
2015-01-28 9:45 pm
provide a online editing console like in W3School then it will be very grateful to understand it properly for anyone in any level.
n/a Points
2015-01-29 7:23 pm

Arn thank you so much for this solution!!  I've been trying to figure out how to position images for so long.  It makes sense that I can position them as a text rather than as an image.  That being said, a few questions, one, how do you wrap images around the text- so that a text will appear over an image?  And secondly, what are the most common errors when making this code?  I have been having so much trouble with centering images, but, you guys seem to have posed the only solution with centering and aligning images that I've found yet. 


What about floating?  What instances will I use floating or will I just use this? 

24,830 Points
2015-01-30 8:09 am
Hello Jacob,

How do you wrap images around the text- so that a text will appear over an image?

Images and text are considered elements on the page. Getting to go on top of each other will not work in HTML, unless you set the image to a background image. This can be done in HTML or CSS. Here's the simple HTML for a background image:

<body background="URL">

Check out this link for further information on the use of background in CSS.

Common errors for background images?

I think the most common is simply the color of the text. Very often, people will set a dark colored text over a dark colored image making it hard to read or simply un-readable. Make sure to view your end result if you're working with text on a background.

Arnel C.

n/a Points
2015-01-30 2:51 am

hai , i m farhan ,     how create a image top, bottom, left &  right setting in bootstrap.






24,830 Points
2015-01-30 7:59 am
Hello Frahan Ahmad,

If you're looking for more information about images and how bootstrap can be used to format them, then please go to their official documentation page: BootStrap - CSS - Images.

Arnel C.
n/a Points
2015-02-18 5:18 pm

Hi, I want to display images of my products on a web page they would be 4 rows, each with 4 images across.  I also need to display the product number under each product.  I was using a table, but is there a way to do this using CSS.  Thanks for your advice

3,251 Points
2015-02-20 11:08 am
Hello Greg,

There is but it would require intense knowledge in CSS and would be better suited within a table.

Best Regards,
TJ Edens
n/a Points
2015-03-09 4:17 pm

this was really helpful!

Thanks a lot

Post a Comment

Email Address:
Phone Number:

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

29 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?


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:
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!