Intern
What is the difference between the tags <div>, <img>, and <p>?
sobes.tech AI
Answer from AI
div - a universal container for grouping elements, has no semantic meaning. Often used for layout creation.
img - used to embed images into the document. The mandatory src attribute specifies the path to the image file. The alt attribute provides alternative text for accessibility.
p - represents a paragraph of text. Browsers usually add margins before and after the <p> element.
Main differences:
| Tag | Purpose | Semantics | Default display |
|---|---|---|---|
div |
Container for grouping | No | Block-level |
img |
Embedding an image | Indicates an image | Inline-block |
p |
Represents a paragraph of text | Indicates a paragraph | Block-level |
Example:
<div>
<h1>Title</h1>
<p>This is a paragraph of text.</p>
<img src="image.jpg" alt="Image description">
</div>