Align and float images with CSS

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.

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.

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. We also have a helpful article on External, Internal, and Inline CSS styles

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!

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)?

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.

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.

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

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.

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.

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....

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?

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.

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, John-Paul

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

Hi. I stumbled upon this site trying to figure out how to have text over an image. I currently have 4 boxes, each going to have a different 'background' image. I want each image to fill the box that it is in, and allow text to be right over it. My image is going to be 40% opaque which is why I can't just make the image as a background to the div. When I change the div opacity, it makes the font the same opacity and cannot overwrite that. Any suggestions? Please and thank you.

We, unfortunately, can't alter your code or provide coding support for you. As per the tutorial above:

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.

I hope this helps to answer your question, please let us know if you require any further assistance.

Arn thank you for the information. but i tried to align the image with css in the center and it didnt worked at all i tried the code on this side and some others noone worked ill just forget about this now i tried to get the <nav> left of the image and the image in center + right side of the image the text wrapping arround but now ill just make it simple image on left (which works same for right with css but not center) with some text right next to it and the <nav> on the bottom