Should I put paragraph tags around images?

I have a webpage where I have text with images. I write some text (in a paragraph), then put an image, and then another paragraph.

Should I put p-tags around the image too, or should I just leave it between them with only the img tag?

The reason I'm asking about this is because so far I have just been looping through the images between paragraphs, but now if I want to add multiple images or add an image and an anchor then they will not sit together. The other thing I tried was adding

<p></p> 

between two images, but I feel it is wrong: P

+7
html image tags paragraph
source share
3 answers

You can use CSS to make images act as blocks, rather than as inline blocks:

Put the following in your CSS somewhere:

 img { display: block; } 

Or, if you have images that you want to display in a string, add class="block" to your img tags and change css to this:

 img.block { display: block; } 
+4
source share

Styling an image as a block element is a partial solution. HTML must also be designed to "work" without styles. If the window model requires that the block block contain only the block or inline elements — not mixed — we should do this at the lowest possible level. This is why menus are created as lists with no links. This is called graceful degradation.

So, the IMHO <p> tag around the image should be added if the nodes next to it are block elements.

+2
source share

I cannot think of any reason why you would not use <p><img/></p> if you need it. thus, the mark clearly describes the layout.

this is certainly more legible than changing the display type for all images. a better alternative would be to create a css class img.block {display:block;} + <img class="block"/>

0
source share

All Articles