如何在html标签不被解析的显示在html页面上

有三样标签可以用:

1、<xmp>
2、<pre>
3、<code>

不过,MDN上这样说:

Note: Do not use this element(<xmp>).
It has been deprecated since HTML3.2 and was not implemented in a consistent way. It was completely removed from the language in HTML5.
Use the <pre> element or, if semantically adequate, the <code> element instead. Note that you will need to escape the '<' character as '&lt;' to make sure it is not interpreted as markup.
A monospaced font can also be obtained on any element, by applying an adequate CSS style using monospace as the generic-font value for the font-family property.

原文:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/xmp

所以,

<xmp>被淘汰了,但它是不转义标签,最好用的标签。目前在各个浏览器测试用了也还能支持。
下面我们看看,各种标签下如何让html标签不被解析到html页面上。

代码和用法:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<xmp>
    <div>xmp:你可以显示代码吗?</div>
</xmp>
<pre>
    &lt;div&gt;
    pre: 你可以显示代码么?
    &lt;/div&gt;
</pre>
<code>
    &lt;div&gt;
    code: 你可以显示代码么?
    &lt;/div&gt;
</code>
</body>
</html>

效果:
这里写图片描述

还有一个pre和code的区别:
http://www.php.cn/div-tutorial-369716.html
https://www.jianshu.com/p/6abc36c28e45

  • 6
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值