Can paragraph tags be one sentence long?

微笑、不失礼 提交于 2019-12-13 03:47:41

问题


I am confused by the meaning of the paragraph tag. Some websites use paragraphs for one sentence, but it doesn't really feel like paragraphs.

Take for example this webpage. What tags would make more sense semantically for the elements "Professional Robust HDMI fiber extender for 4k video" and "HDMI 2.0 | 2160p60 | 18Gbps | HDR | 4:4:4 | HDCP 2.2"? Would you use a span, a div, or a heading for the first sentence?

Same question for the second sentence. It doesn't feel like a paragraph, it's not even a sentence. It consists of just words separated by a vertical line. Is it a span, a div, or a subheading then? On the other hand, if I use a span, wouldn't that indicate to search engines and screen readers that this isn't text? I mean, span is not semantic, whereas this second sentence provides meaning.

Same thing for the next headings down the page. Specifications, support, and ordering information are headings, no doubt about that, they introduce a new section of content. But what about "Built to last" and "Fiber all the way"? They don't really feel like the same type of headings. What is the most semantic tag for them?


回答1:


First of all, if the "why?" of this question is "SEO & semantic HTML", it worths noting that in this particular case (as well as in many others), it absolutely doesn't matter what tag to use.

Not every single thing has a semantic meaning in the markup.

It's a good idea to use <footer>...</footer> over generic <div>...</div> for footer, but in case of text elements the most important thing is probably to clearly differentiate "text" with "headings".

By the way, if you lookup the definition of paragraph, it specify only 2 particular limitations of paragraphs

  1. It is some text ( good one to follow & not use <p> as container for <div>s or <img>s ).
  2. "A paragraph begins on a new line" ( easy to follow in web environment, since different place on the page is pretty much as a "new line" in a book ).

The rest are just general observations.

It says "it is usually more than one sentence" & "there is often a blank line between paragraphs", but technically you might write two 1-word paragraphs that are separated by a " | " instead of a blank line.

Which also follows paragraph specs.

As for <span> & <div>, according to specs they should be used for the same purpose (document structuring) with a difference that <div> is a block-level element while the <span> is an inline element.

So <span>s are basically inlined <div>s.

In your example site, I'd say that "Professional robust HDMI fiber extender for 4K video" is an <h2> or <h3> considering the name of e-store is an <h1> somewhere in the <nav> (it's a common practice as far as I know).

The "HDMI 2.0 | 2160p60 | 18Gbps | HDR | 4:4:4 | HDCP 2.2" should most probably be <p> (or an <h4>/<h5> if it's really important).

The "sections" of this element might or might not be wrapped in <span>s depending on whether you need it for styling or other purposes.




回答2:


You should not be worried unless you want to style it then use span. If not it should be in heading three or paragraph depending on what you want.




回答3:


Question: Can paragraph tags be one sentence long?

Yes, <p> tags can be one sentence long—just like paragraphs in the English language can be one sentence long. One of the examples used on the <p>: Paragraph Element page of the MDN Web Docs uses a single-sentence paragraph as an example:

<p>Some species live in houses where they hunt insects attracted by artificial light.</p>

Question: Take for example this webpage. What tags would make more sense semantically for the elements "Professional Robust HDMI fiber extender for 4k video" and "HDMI 2.0 | 2160p60 | 18Gbps | HDR | 4:4:4 | HDCP 2.2"? Would you use a span, a div, or a heading for the first sentence?

If I were writing the webpage as a text document, what would make the most sense for the main heading of the document? And in the case of an h1: what is the subject of the page? In this case, I would say that "HXT2: Professional robust HDMI fiber extender for 4K video" makes the most sense as the h1, as that is the subject of the page. The alt text of the image HXT2 image acts as text, so you could mark that up this way:

<h1><img src="HXT2.jpg" alt="HXT²"> Professional robust HDMI fiber extender for 4K video</h1>

The following run of text ("HDMI 2.0 | 2160p60 | 18Gbps | HDR | 4:4:4 | HDCP 2.2") is really a list of meta information, which could be semantically marked up as the unordered list that it is:

<ul>
  <li>HDMI 2.0</li>
  <li>2160p60</li>
  <li>18Gbps</li>
  <li>HDR</li>
  <li>4:4:4</li>
  <li>HDCP 2.2</li>
</ul>

Question: If I use a span, wouldn't that indicate to search engines and screen readers that this isn't text?

No. While <span> elements don't have any special semantic meaning of their own, they don't remove the inherent semantics of text. Text wrapped in a <span> is still text, and it has no inherent affect on the way that search engines or screen readers interpret it.



来源:https://stackoverflow.com/questions/58047525/can-paragraph-tags-be-one-sentence-long

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!