gpt4 book ai didi

html - 如何在 HTML 中正确使用 lang

转载 作者:搜寻专家 更新时间:2023-10-31 08:04:31 24 4
gpt4 key购买 nike

我想问你如何在 HTML 代码中正确使用 lang。我正在尝试使用 2 种语言 en, pl 制作网站。

<html lang="en">
<html lang="pl">

这种方式是否正确?

最佳答案

如果文档的主要语言是波兰语,大部分是英语,那么它应该有 <html lang="pl"><div lang="en">或英文部分周围的东西:

<html lang="pl">

<body>
[Polish content]
<div lang="en">
[English content]
</div>
[more Polish content]
<div lang="en">
[more English content]
</div>
[more Polish content]

无论 html如果可能的话,元素应该总是有一个 lang值,per the HTML spec :

Authors are encouraged to specify a lang attribute on the root html element, giving the document's language. This aids speech synthesis tools to determine what pronunciations to use, translation tools to determine what rules to use, and so forth.

但是,如果一个文档是多种语言的混合体,那么它就不能真正被视为具有单一的主要语言,then the html element still should have a lang attribute, but with an empty value :

Setting the attribute to the empty string indicates that the primary language is unknown.

<html lang="">

<body>
<div lang="pl">
[Polish content]
</div>
<div lang="en">
[English content]
</div>
<div lang="pl">
[Polish content]
</div>
<div lang="en">
[English content]
</div>

有关这方面的更多详细信息,请参阅以下 W3C 指南:

关于html - 如何在 HTML 中正确使用 lang,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40828205/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com