Html Attribute With/Without Quotes

HTML attribute with/without quotes

It is all about the true validity of HTML markup. It's for what W3C (WWW Consortium) work for. Many things might work in HTML but they have to be validated in order to be more carefully recognized by the web browser. You can even omit the <html> and </html> tags at the start and end, but it is not recommended at all, nobody does it and it is considered as a 'bad code'.

Therefore, it is more valid to put them in quotes.

Do HTML attributes need quotation marks?

If the attribute contains a string that is not ascii or has whitespace then you need to wrap it in quotes

Attributes are placed inside the start tag, and consist of a name and
a value, separated by an "=" character. The attribute value can remain
unquoted if it doesn't contain ASCII whitespace or any of " ' ` = < or
>. Otherwise, it has to be quoted using either single or double quotes. The value, along with the "=" character, can be omitted
altogether if the value is the empty string.


link here

HTML attributes without quotation marks?

Always use quotation marks.

I don't believe that HTML properties without quotation marks are classed as Invalid HTML, but they will potentially cause you problems later on down the line.

By default, SGML requires that all attribute values be delimited using
either double quotation marks (ASCII decimal 34) or single quotation
marks (ASCII decimal 39). Single quote marks can be included within
the attribute value when the value is delimited by double quote marks,
and vice versa. Authors may also use numeric character references to
represent double quotes (") and single quotes ('). For double
quotes authors can also use the character entity reference ".

In certain cases, authors may specify the value of an attribute
without any quotation marks. The attribute value may only contain
letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45),
periods (ASCII decimal 46), underscores (ASCII decimal 95), and colons
(ASCII decimal 58). We recommend using quotation marks even when it is
possible to eliminate them.

Source: http://www.w3.org/TR/REC-html40/intro/sgmltut.html#h-3.2.2


I think they're a great way of clearly defining when an attribute value starts and finishes.

Take for example the class attribute which can have multiple classes seperated by spaces:

<div class="classa classb" id="123">

This clearly shows the browser that my classes are classa and classb, with an element id of 123.

Take away the quotation marks and we've got:

<div class=classa classb id=123>

A browser could now interpret this as 3 classes, with no id. classa, classb and id=123.

Or it may even interpret it as 3 attributes. class="classa", classb="" and id="123"

(Even stackoverflow's syntax styling is struggling with this one!)

Html attributes: quoted or unquoted?

Wrap your values in quotes (single or double, just don't mix them):

  1. It's necessary for many values ( class="container modal warning" )
  2. It prevents confusing values with later attributes ( class="foo"id="bar" )
  3. People will like you, and treat you kindly.

During Tokenization, all three are considered (single, double, and none).

Do you quote HTML5 attributes?

I'm in favour of always using quotes.

  • It looks way cleaner and more consistent

  • All editors can deal with it properly

  • It's easier to maintain - you can edit values without breaking them because quotes are missing.

The few bytes you save in document size by dropping quotes where they are not needed are not worth mentioning (unless maybe you're Google's home page).

HTML - Is it necessary to enclose a call to the css file into quotes?

I believe the spec defines it to have quotes, but some browsers go beyond and will know what you meant.

EDIT: I was wrong! From the spec

Attributes are placed inside the start tag, and consist of a name and a value, separated by an "=" character. The attribute value can remain unquoted if it doesn't contain space characters or any of " ' ` = < or >. Otherwise, it has to be quoted using either single or double quotes. The value, along with the "=" character, can be omitted altogether if the value is the empty string.

http://www.w3.org/html/wg/drafts/html/master/introduction.html#restrictions-on-content-models-and-on-attribute-values

XSLT - HTML id attribute without quotes div id=myId

I believe your title should read without quotes, "", not without parenthesis, ().

No, XSLT is not going to help you create XML that's not well-formed. (You could stand on your head and output text rather than XML to achieve such a effect, but don't do that.) Attribute values must have single, ', or double quote, ", delimiters for the markup to be XML. Even the HTML output option is not going to serialize attribute values without quote delimiters.


In comments, @Ole asks:

In principle you are right, but I thought that in HTML5, also attributes without quotes are allowed?

Yes, in HTML5, unquoted attribute values are allowed, but you'll be better off using the single-quoted and double-quoted attribute value syntaxes that are also supported in HTML5, especially if you want to be able to leverage XML tools.

Find html attributes without quotes, and add them back in

I've used https://github.com/MindTouch/SGMLReader in the past to solve a similar issue. Worked like a charm (YMMV).

Why should we use double quotes inside html input tag attribute values?

http://www.w3schools.com/html/html_attributes.asp

Excerpt from link:

We Suggest: Always Quote Attribute Values

The HTML5 standard does not require quotes around attribute values.

W3C recommends quotes in HTML4, and demands quotes for stricter document types like XHTML.

Sometimes it is necessary to use quotes.



Related Topics



Leave a reply



Submit