Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html attributes: quoted or unquoted? [duplicate]

Tags:

html

For some html attributes, I can use quotes around the values, or not:

For example, I can do

<table colspan='1'></table>

Or

<table colspan=1></table>

Is there any difference between these two ways? Which is the more conventional way of doing things?

like image 453
George Newton Avatar asked Oct 02 '22 23:10

George Newton


People also ask

Do HTML attributes need double quotes?

The HTML specification says: 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 spaces or any of " ' ` = < or > . Otherwise, it has to be quoted using either single or double quotes.

Do you need quotes for HTML attributes?

The HTML standard does not require quotes around attribute values.

Should we quote the attribute values?

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), and periods (ASCII decimal 46). We recommend using quotation marks even when it is possible to eliminate them.

When attribute of HTML value contains double quotes it is necessary to use?

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 ".


1 Answers

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).

like image 120
Sampson Avatar answered Oct 13 '22 10:10

Sampson