direction-attribute
它能做什么
这项技能检查网页是否为其语言设置了正确的文字方向。适合构建从右到左语言网站,或包含混合方向内容的开发者。
适用场景
- ✓当你的网站加入阿拉伯语、希伯来语、波斯语或乌尔都语内容时。
- ✓当用户姓名或评论中混合了从左到右和从右到左的文字时。
- ✓当菜单和布局对从右到左的读者显示颠倒时。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/direction-attribute/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“你能检查一下我的网站对阿拉伯语读者是否显示正确吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会检查页面及混合方向部分(例如用户评论)上的 dir 属性。在需要的地方,它会建议添加正确的值,或使用隔离标签。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Set text direction for RTL languages
Without proper dir attributes, RTL text displays incorrectly, UI elements appear backwards, and screen readers announce content in the wrong order.
Quick Reference
- Set
dir="rtl"on <html> for Arabic, Hebrew, Persian, Urdu - Use
dir="auto"for user-generated content - Combine with CSS logical properties (inline-start, inline-end)
- Test UI mirroring for navigation, icons, and layouts
- Use bidi isolation such as
<bdi>for inline mixed-direction user content
Check
Verify that this HTML document uses the appropriate dir attribute to indicate text direction for right-to-left languages like Arabic, Hebrew, or mixed content. Check user-generated inline text for dir="auto" or bidi isolation where names, handles, or snippets mix writing directions.
Fix
Add the dir attribute to the html element or specific elements with values 'ltr' (left-to-right), 'rtl' (right-to-left), or 'auto' for automatic detection. Use <bdi> or equivalent bidi isolation for mixed-direction inline content.
Explain
Explain how the dir attribute helps browsers and screen readers properly display and navigate text in different writing directions.
Code Review
Review templates, server-rendered HTML, and shared components that output markup related to Set text direction for RTL languages. Flag exact elements, attributes, and routes where the rendered HTML violates the rule. Inspect user-generated inline content, not only page-level locale wrappers.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/html/direction-attribute
常见问题
dir 属性有什么作用?
它告诉浏览器文字的流动方向,是从左到右还是从右到左。
什么是双向隔离(bidi isolation)?
它使混合方向的文字(例如另一种文字的姓名)不会干扰附近的文字。这项技能建议为此使用 bdi 标签。
它涵盖布局镜像吗?
这项技能建议测试导航、图标和布局是否正确地镜像。
详情
作者的原始描述
Use when reviewing templates, rendered HTML, or shared components related to Set text direction for RTL languages. Validate the final browser-facing markup, not just the source framework abstraction.
热度
- GitHub 星标
- 75k
- 排名
- #2816
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。