What are the standards for writing HTML code?
This time I will bring you what are the specifications for writing HTML code, what are the precautions for writing HTML code, the following is a practical case, let's take a look.
Self-closing tag, no need to close (for example: img input br hr, etc.);
Optional The closing tag must be closed (for example: or );
Reduce the number of tags as much as possible;
<img src="images/google.png" alt="Google"> <input type="text" name="title"> <ul> <li>Style</li> <li>Guide</li> </ul> <!-- Not recommended --> <span class="avatar"> <img src="..."> </span> <!-- Recommended --> <img class="avatar" src="...">
Class and ID
The class should be named after the function or content, not the expression;
class and id word letters are lowercase, and when composed of multiple words, use dash-separation;
Use a unique id as Javascript hook, and avoid creating classes without style information;
<!-- Not recommended --> <div class="j-hook left contentWrapper"></div> <!-- Recommended --> <div id="j-hook" class="sidebar content-wrapper"></div>
AttributesOrder
HTML attributes should appear in a specific order to ensure readability.
id
class
name
data-xxx
src, for, type, href
title, alt
aria-xxx, role
<a id="..." class="..." data-modal="toggle" href="###"></a> <input class="form-control" type="text"> <img src="..." alt="...">
Quotation marks
Use double quotation marks uniformly for the definition of attributes.
I believe you have mastered the methods after reading these cases. For more exciting information, please pay attention to php Chinese website Other related articles!
Related reading:
HTML optimization techniques you must know
How to set the horizontal and vertical centering of HTML elements
How to use HTML and CSS to make a clear message
The above is the detailed content of What are the standards for writing HTML code?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

To create an HTML unordered list, you need to use a tag to define a list container. Each list item is wrapped with a tag, and the browser will automatically add bullets; 1. Create a list with a tag; 2. Each list item is defined with a tag; 3. The browser automatically generates default dot symbols; 4. Sublists can be implemented through nesting; 5. Use the list-style-type attribute of CSS to modify the symbol style, such as disc, circle, square, or none; use these tags correctly to generate a standard unordered list.

SemanticHTMLimprovesbothSEOandaccessibilitybyusingmeaningfultagsthatconveycontentstructure.1)ItenhancesSEOthroughbettercontenthierarchywithproperheadinglevels,improvedindexingviaelementslikeand,andsupportforrichsnippetsusingstructureddata.2)Itboostsa

Using tags is the easiest and recommended method. The syntax is suitable for modern browsers to embed PDF directly; 2. Using tags can provide better control and backup content support, syntax is, and provides download links in tags as backup solutions when they are not supported; 3. It can be embedded through Google DocsViewer, but it is not recommended to use widely due to privacy and performance issues; 4. In order to improve the user experience, appropriate heights should be set, responsive sizes (such as height: 80vh) and PDF download links should be provided so that users can download and view them themselves.

rel="stylesheet"linksCSSfilesforstylingthepage;2.rel="preload"hintstopreloadcriticalresourcesforperformance;3.rel="icon"setsthewebsite’sfavicon;4.rel="alternate"providesalternateversionslikeRSSorprint;5.rel=&qu

Usetheelementwithinatagtocreateasemanticsearchfield.2.Includeaforaccessibility,settheform'sactionandmethod="get"attributestosenddatatoasearchendpointwithashareableURL.3.Addname="q"todefinethequeryparameter,useplaceholdertoguideuse

ThetargetattributeinanHTMLanchortagspecifieswheretoopenthelinkeddocument.1._selfopensthelinkinthesametab(default).2._blankopensthelinkinanewtaborwindow.3._parentopensthelinkintheparentframe.4._topopensthelinkinthefullwindowbody,removingframes.Forexte

Use elements and set the action and method attributes to specify the data submission address and method; 2. Add input fields with name attribute to ensure that the data can be recognized by the server; 3. Use or create a submission button, and after clicking, the browser will send the form data to the specified URL, which will be processed by the backend to complete the data submission.

Use tags to highlight text semantically, often used to identify search results or important content; 2. Custom styles such as background colors, text colors and borders can be customized through CSS; 3. It should be used in contexts with practical significance, rather than just visual decoration to improve accessibility and SEO effects.
