Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What values can I put in an HTML attribute value?

Tags:

html

Do I need to escape quotes inside of an html attribute value? What characters are allowed?

Is this valid?

<span title="This is a 'good' title.">Hi</span> 
like image 877
Kyle Avatar asked Mar 16 '11 01:03

Kyle


People also ask

What are HTML attribute values?

The purpose of the HTML value attribute is to specify the current value for an input type. For those elements that can display their values (such as text fields), they will display this value onscreen. Otherwise, the values are all available as form values when submitted.


Video Answer


1 Answers

If your attribute value is quoted (starts and ends with double quotes "), then any characters except for double quotes and ampersands are allowed, which must be quoted as &quot; and &amp; respectively (or the equivalent numeric entity references, &#34; and &#38;)

You can also use single quotes around an attribute value. If you do this, you may use literal double quotes within the attribute: <span title='This is a "good" title.'>...</span>. In order to escape single quotes within such an attribute value, you must use the numeric entity reference &#39; since some browsers don't support the named entity, &apos; (which was not defined in HTML 4.01).

Furthermore, you can also create attributes with no quotes, but that restricts the set of characters you can have within it much further, disallowing the use of spaces, =, ', ", <, >, ` in the attribute.

See the HTML5 spec for more details.

like image 92
Brian Campbell Avatar answered Oct 04 '22 14:10

Brian Campbell