search
HomeWeb Front-endHTML TutorialSummary of coding conventions in HTML

本篇文章给大家带来的内容是关于HTML中编码规范的总结,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

1.img标签要写alt标签
2.单标签不要写闭合标签(img、link、input、hr、br)
3.自定义属性要以data- 开头
4.td要在tr里面,li要在ul/ol里面
5.ul/ol的直接子元素只能是li
6.section里面要有标题标签
7.使用section标签增强SEO(搜索引擎优化)
8.行内元素里面不可使用块级元素(a标签里面不能放p)
9.每个页面要写
10.要用table布局写邮件模板
11.html要保持简洁,不要套太多层
12.特殊情况下才在html里面写script和style
13.样式要写在head标签里
14.html要加上lang的属性

    <html lang="en">
    <html lang="zh-CN">

15.要在head标签靠前位置写上charset和meta标签

16.特殊符号使用html实体

© &copy;
¥ &yen;
® &reg;
> >
< <
& &

17.img空src的问题

<img src="/static/imghwm/default1.png"  data-src="about:blank"  class="lazy"   alt><img  src="/static/imghwm/default1.png"  data-src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"  class="lazy"   alt="Summary of coding conventions in HTML" >

18.关于行内元素空格和换行的影响
19.类的命名使用小写字母加中划线(hello-world)
20.不推荐使用自定义标签
21.重复杂id和重复属性
22.不推荐使用属性设置样式(canvas width height 需要写)
23.使用合适的标签
(1)如果内容是表格就使用table,table有自适应的优点;如果是一个列表就使用ol/ul标签,扩展性比较好
(2)如果是输入框就使用input,而不是写一个p标签,然后设置contenteditable=true,因为这个在IOS Safari上光标定位容易出现问题。如果需要做特殊效果除外
(3)如果是粗体就使用b/strong,而不是自己设置font-weight
(4)如果是表单就使用form标签,注意form里面不能套form
(5)如果是跳链就使用a标签,而不是自己写onclick跳转。a标签里面不能套a标签
(6)使用html5语义化标签,如导航使用nav,侧边栏使用aside,顶部和尾部使用header/footer,页面比较独立的部分可以使用article,如用户的评论。
(7)如果是按钮就应该写一个button或者<input type="button">,而不是写一个a标签设置样式,因为使用button可以设置disabled,然后使用CSS的:disabled,还有:active等伪类使用,例如在:active的时候设置按钮被按下去的感觉
(8)如果是标题就应该使用标题标签h1/h2/h3,而不是自己写一个<p class="title"></p>,相反如果内容不是标题就不要使用标题标签了
(9)在手机上使用select标签,会有原生的下拉控件,手机上原生select的下拉效果体验往往比较好,不管是IOS还是android,而使用<input type="tel">在手机上会弹一个电话号码的键盘,<input type="number"> <input type="email">都会弹相应的键盘
(10)如果是分隔线就使用hr标签,而不是自己写一个border-bottom的样式,使用hr容易进行检查
(11)如果是换行文本就应该使用p标签,而不是写br,因为p标签可以用margin设置行间距,但是如果是长文本的话使用p,因为p标签里面不能有p标签,特别是当数据是后端给的,可能会带有p标签,所以这时容器不能使用p标签。
24.不要在https的链接里写http的图片

<img  src=”//static.chimeroi.com/hello-world.jpg” alt="Summary of coding conventions in HTML" >

相关推荐:

html的基础元素,让你零基础学习HTML

html页面中友情链接怎么进行添加设置?(代码示例)

The above is the detailed content of Summary of coding conventions in HTML. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment