大网数据广告活动
网站运营与故障问答

Is using the <pre> tag for ordinary text in a page likely to impact SEO?

· 52CE 我爱测

When coding pages by hand, I sometimes want to skip having to write all those <p> tags and use: <pre> <h2>Heading written as usual is no problem within a pre</h2> <i>First paragraph</i> is here. This is the second paragraph, but …

问题原文

原帖链接 · PetaspeedBeaver · CC BY-SA 3.0

When coding pages by hand, I sometimes want to skip having to write all those <p> tags and use:

<pre>
  <h2>Heading written as usual is no problem within a pre</h2>

  <i>First paragraph</i> is here.

  This is the second paragraph, but since I use the pre-tag I don't need to use the p tag to get a space in between the two. 

  Next paragraph etc &hellip;
</pre>

Which if css:

pre {
  whitespace: normal

and same font as the regular text is set for<pre>s will render something like this:


Heading written as usual is no problem within a pre

First paragraph is here.

This is the second paragraph, but since I use the pre-tag I don't need to use the p tag to get a space in between the two.

Next paragraph etc …


Is using the <pre> to save on typing some <p>s in this way likely to affect SEO? If so, why and how?

已采纳解答

原帖链接 · Simon Hayter · CC BY-SA 3.0

Both Google & Bing does not consider markup as a ranking factor, it uses markup to understand content and not directly reward, this includes Schema and other micro data formats.

So using <pre> or <p> is not going to going to make any real world differences in terms of rankings but that's not to say you should treat <pre> the same as <p> because some e-readers and browsers may render those differently, never mind it's also lazy to do this way.

Your gap between elements should come from the CSS not using a hack like PRE because as mentioned browsers including different versions of those browsers can render them differently if not set by the CSS. If you want everything to look the same across devices and browsers then use the CSS, that's what it was designed for.

Best practice would be to mimic the style of <pre><code> by adding a container around the <p> with something like:

<!-- HTML -->
<div class="pre">
   <h2>Identical Header</h2>
   <p>This looks identical to PRE</p>
   <p>I have a gap because P and H have margin-bottom</p>
</div>

/* CSS */
.pre {
    whitespace: normal;
    font-size: 1em;
    font-family: 'Same Font As PRE or CODE';
}
.pre h1, .pre h2, .pre h3, .pre h4, .pre h5 {
    margin-bottom: 1.5em;
    font-size: 1.5em
    font-family: inherit;
}
.pre p {
    font-size: inherit;
    font-family: inherit;
    margin-bottom: 1em;
}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2018-01-14)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。