Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I put paragraph tags around images?

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

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

The reason I ask this is because up until now I was just plopping images in between paragraphs, but now if I want to add more than one image or add an image and an anchor then the don't sit together right. The other thing I tried was adding

<p></p>

in between two images but I feel like that is wrong :P

like image 979
Adam Avatar asked Jan 27 '10 23:01

Adam


2 Answers

You could use CSS to make the images act as blocks rather than as inline-blocks:

Put the following in your CSS somewhere:

img { display: block; }

Or if you have some images that you want to display inline, then add class="block" to your img tags, and change the css to this:

img.block { display: block; }
like image 143
pib Avatar answered Nov 03 '22 05:11

pib


Styling an image as a block element is a partial solution. HTML should be designed to "work" without styles also. If the box model requires that a block element contains only block or inline elements - not mixed - than we should do so on the lowest possible level. This is why menus are created as lists not sets of links. This is called graceful degradation.

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

like image 23
T.J. Avatar answered Nov 03 '22 06:11

T.J.