lang属性和< meta http-equiv =“Content-Language”之间的区别是什么?含量="的en-US">标签? [英] What's the difference between the lang attribute and the <meta http-equiv="Content-Language" content="en-US"> tag?

查看:809
本文介绍了lang属性和< meta http-equiv =“Content-Language”之间的区别是什么?含量="的en-US">标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道使用lang属性的意义以及与使用metaContent-Language标签有什么不同?考虑下面的代码:

 < html lang =en> 
< head>
< meta http-equiv =Content-Languagecontent =en-US>
< / head> ...

我的假设是浏览器正在阅读元标记的值,但DOM与lang属性有关。它是否正确?是否有任何细微差别我不知道?

解决方案

lang属性(在HTML元素上)指定文档的语言(除非用另一个可以改变文档段落语言的lang属性覆盖)。

Content-Language HTTP标头指定目标受众的语言。这与文档实际写入的语言不同。例如,法语语言课程的一部分可能包含用法语书写的页面,但Content-Language应该是 en ,因为它是旨在为英语学习者学习法语。



来自规范 b
$ b


Content-Language实体标题字段描述自然语言s)的封闭实体的预期受众。请注意,这可能不等同于实体主体内使用的所有语言。

Meta HTTP-equiv是穷人的HTTP头。它具有真正的HTTP标题的所有含义,但不受尊重(和支持)。

作为一个经验法则,内容语言对搜索引擎更感兴趣并且lang属性对屏幕阅读器更感兴趣。

I was wondering what's the significance of using the "lang" attribute and how that differs from using the meta "Content-Language" tag?

Consider the following code:

<html lang="en">
    <head>
        <meta http-equiv="Content-Language" content="en-US">
    </head>...

My assumption is that the browser is reading the meta tag's value, but the DOM is concerned with the "lang" attribute. Is this correct? Are there any nuances I'm unaware of?

解决方案

The lang attribute (on the HTML element) specifies the language for the document (unless overridden with another lang attribute which can change the language for a section of the document).

The Content-Language HTTP header specifies the language of the intended audience. This is not the same as the language the document is actually written in. For example, part of a French language course could consist of a page written in French, but Content-Language would be en as it was intended for English speakers learning French.

From the spec:

The Content-Language entity-header field describes the natural language(s) of the intended audience for the enclosed entity. Note that this might not be equivalent to all the languages used within the entity-body.

Meta HTTP-equiv is the poor man's HTTP header. It has all the meaning of the real HTTP header, but less respect (and support).

As a rule of thumb, Content-Language is of more interest to search engines and the lang attribute is of more interest to screen readers.

这篇关于lang属性和&lt; meta http-equiv =“Content-Language”之间的区别是什么?含量=&QUOT;的en-US&QUOT;&GT;标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆