Image HTML alignment

Fixes a stack of <img> tags that sits to the left, overflows on a phone, or has uneven gaps between pictures. Paste the HTML you have or pick the image files, and get tags that are centred, scale down on narrow screens, and keep their proportions. Preview at phone and desktop width before you paste it back.

Runs in your browser · nothing is uploaded
Settings

Puts loading="lazy" on everything except the first image. A long page of pictures loads noticeably faster.

Cleaned HTML

Preview

Numbered placeholders show alignment and spacing without contacting image hosts. Actual image heights and contents are not previewed.

Assumptions

How it is calculated

Common mistakes

FAQ

Why do my images sit against the left edge?

Because <img> is an inline element, so it is laid out like a word in a sentence. Unless something around it centres the text, it hugs the left. This tool puts display:block and auto left and right margins on the image itself. Wrapping everything in a div with text-align:center also works, but many editors strip wrapper tags and style blocks, so putting the rule on the image is more likely to survive.

The images overflow the screen on a phone

Without a width they render at their natural pixel size, so an 860px image runs off a 375px screen. Combining width:100% with max-width makes the image shrink on narrow screens while never growing past its intended size on wide ones. height:auto is what keeps the proportions.

The gaps between images are uneven

The line breaks and spaces between your <img> tags are treated as whitespace between words, which leaves a small gap under each image. Adding <br> stacks another line break on top of that. Switching the images to display:block removes the gap entirely, and if you do want spacing you can set it in pixels and get exactly that.

Can I turn local files straight into HTML?

Not into self-contained HTML, no. Embedding image data directly in the file with a data: address is possible, but many content editors reject it and the file size becomes unmanageable. So this tool covers the last step instead: upload the images to your host, paste the folder address, and it joins that with each file name. From the files themselves it reads only the name and dimensions, and nothing is uploaded.

The order of my images is wrong

Sorting file names as plain text puts 10 before 2. This tool compares the numeric parts as numbers, so 001, 002 … 010, 011 come out in the order you expect. If you want to control the order yourself, use the paste mode: it keeps whatever order you give it.

What maximum width should I use?

It depends entirely on where the page will be published, so it is offered as a choice rather than a recommendation. Check the guidance for your platform. If you are unsure, match the natural width of your images: setting a width larger than the original only stretches them and makes them look soft.

Is my HTML sent anywhere?

No. Rebuilding the tags happens entirely in your browser. The preview does fetch the images from wherever you have hosted them, because that is what previewing them means, but nothing else leaves the page.

Related tools