Should I use the

tag in markup?

2019-01-17 22:46发布

I have always used either <br /> or a <div/> tag when something more advanced is necessary.

Is use of the <p/> tag still encouraged?

11条回答
唯我独甜
2楼-- · 2019-01-17 23:41

Using <p /> has never been encouraged:

From XHTML HTML Compatibility Guidelines

C.3. Element Minimization and Empty Element Content

Given an empty instance of an element whose content model is not EMPTY (for example, an empty title or paragraph) do not use the minimized form (e.g. use <p> </p> and not <p />).

查看更多
Luminary・发光体
3楼-- · 2019-01-17 23:42

A <p> signifies a paragraph. It should be used only to wrap a paragraph of text.

It is more appropriate to use the <p> tag for this as opposed to <div>, because this is semantically correct and expected for things such as screen readers, etc.

查看更多
孤傲高冷的网名
4楼-- · 2019-01-17 23:42

From the HTML 4.01 Specification :

We discourage authors from using empty P elements. User agents should ignore empty P elements.

While they are syntactically correct, empty P elements serve no real purpose and should be avoided.

查看更多
够拽才男人
5楼-- · 2019-01-17 23:46

A <p> tag wraps around something, unlike an <input/> tag, which is a singular item. Therefore, there isn't a reason to use a <p/> tag..


I've been told that im using <br /> when i should use <p /> instead. – maxp 49 secs ago

If you need to use <p> tags, I suggest wrapping the entire paragraph inside a <p> tag, which will give you a line break at the end of a paragraph. But I don't suggest just substituting something like <p/> for <br/>

<p> tags are for paragraphs and signifying the end of a paragraph. <br/> tags are for line breaks. If you need a new line then use a <br/> tag. If you need a new paragraph, then use a <p> tag.

查看更多
狗以群分
6楼-- · 2019-01-17 23:47

Interestingly, Counting paragraph tags states that a random sample of 833,866 HTML documents found that 50.1% of the documents sampled contain only <p>...</p>, 4.41% contain only ...<p>..., and a mere 0.21% contain only ...<p/>....

查看更多
登录 后发表回答