Table of Contents
HTML Detailed explanation of the rules for whether to add quotation marks to the attribute value
Home Web Front-end Front-end Q&A Can quotes be ignored in html5 attribute values?

Can quotes be ignored in html5 attribute values?

Jan 18, 2022 am 11:02 AM
html5 attribute value quotation marks

<blockquote><p>html5 attribute values ​​can ignore quotes. In HTML5, the quotation marks around the attribute value in the tag are optional, if the attribute value does not contain spaces or any """, "'", "`", "=", "<", "> " and other special symbols, it can remain in the format without quotation marks. <!--”、“--></p></blockquote> <p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/202201/18/2022011810542942686.jpg" class="lazy" alt="Can quotes be ignored in html5 attribute values?" ></p> <p> The operating environment of this tutorial: Windows 7 system, HTML5 version, Dell G3 computer .</p> <p>html5 can use single quotes, double quotes, or no quotes. The quotes on both sides of the attribute value in the tag are optional. However, it is customary to still write it.</p> <blockquote> <p>W3C Working Draft (January 13, 2011): </p> <p>The attribute value can remain unquoted if it does not contain spaces or any <code>"</code>,<code>'</code> , <code>`</code>, <code>=</code>, <code><</code>, <code>></code> and other special symbols</p> </blockquote> <h2 id="strong-HTML-Detailed-explanation-of-the-rules-for-whether-to-add-quotation-marks-to-the-attribute-value-strong"><strong>HTML Detailed explanation of the rules for whether to add quotation marks to the attribute value </strong></h2> <p><span style="font-size: 18px;"><strong>Explanation: </strong></span></p> <p>When the attribute value is a word or a whole string (without When the attribute value is multiple words or a whole string of characters (with spaces in between): quotation marks are required </p> <p></p> <p>Remarks: <span style="color:#a2e043;"><strong>The above are the teacher’s original words. Personal experiment found that whether to add quotation marks depends on whether there are spaces in the value. If there are spaces, add quotation marks. If not, you don’t need to add them. [But for the sake of convenience Programming habits, it is recommended to add quotation marks in both cases] </strong></span></p> <p>Experiment: <strong><span style="font-size: 18px;"></span></strong></p>Case 1: Material name (nothing in the name Space): <p><strong></strong> Code ① (value with quotes): </p> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><img src="images/163logo.gif" alt="logo"/></pre><div class="contentsignin">Copy after login</div></div> <p></p>Normal display <p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/024/00eae49203e0874f882870c50d05c6ca-0.png" class="lazy" alt="" style="max-width:90%" style="max-width:90%"> Code ② (value without quotes): </p> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><img src=images/163logo.gif alt="logo"/></pre><div class="contentsignin">Copy after login</div></div> <p> </p>Normal display<p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/024/00eae49203e0874f882870c50d05c6ca-0.png" class="lazy" alt="" style="max-width:90%" style="max-width:90%"></p> Case 2: Material name (there are spaces in the name): <p><strong></strong></p> <p>## Code ① (Value with quotes): <img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/024/00eae49203e0874f882870c50d05c6ca-2.png" class="lazy" alt="" style="max-width:90%" style="max-width:90%"></p> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><img src="images/163 logo.gif" alt="logo"/></pre><div class="contentsignin">Copy after login</div></div> <p>Normal display </p> <p>Code ② (Value without quotes): <img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/024/00eae49203e0874f882870c50d05c6ca-0.png" class="lazy" alt="" style="max-width:90%" style="max-width:90%"></p> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><img src=images/163 logo.gif alt="logo"/></pre><div class="contentsignin">Copy after login</div></div> <p>Picture not found</p> <p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/024/f0500214e16d3d9f8377585a2cdaef5a-4.png" class="lazy" alt="" style="max-width:90%" style="max-width:90%"> Summary: It can be seen that if there are spaces in the value, the value must be quoted. If there are no spaces in the value, you can add it or not </p> <p><span style="color:#a2e043;"></span></p>Expand knowledge: Some easily overlooked details of html5<p><span style="font-size: 18px;"><strong></strong></span></p>In html5, spaces and slashes at the end of empty elements can be ignored. <ul style="list-style-type: disc;"> <li> <p></p>The quotation marks around the attribute value in the tag are optional. However, it is customary to write it down. </li> <li> <p></p>The numeric value of the attribute does not need to enter the unit, only the value itself can be entered. Such as height and width in labels, etc. </li> <li> <p></p>Some attributes in the tag only accept predefined values ​​(also called enumeration values). Be sure to write enumeration values ​​in lowercase letters. Such as input type. Some attributes can be any value, such as the Value of input. There is also a special Boolean attribute value in the </li> <li> <p></p> tag. This attribute value is optional and represents true if present. If you must fill in a value, fill it in itself. Such as hidden="hidden". Naming convention for </li> <li> <p></p>#html: It is best to use all lowercase letters, use - (dash) between words to separate words, and use .html for the extension (although you can also use . htm means html page). </li> <li> <p></p>The alt attribute in the img tag is used to display the text if the image does not load successfully or is only accessed through a text-only browser (rarely), and the screen reader will read the text. Text (Accessibility). </li> <li> <p></p>The title tag must be located inside the head tag and behind the character encoding meta tag. </li> <li> <p></p>Related recommendations: "</li>html video tutorial</ul>"<p></p>

The above is the detailed content of Can quotes be ignored in html5 attribute values?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

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 Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles