I want to display ' on a web page but it displays the apostrophe character instead of '
Is it possible to display ' on a webpage?
If you want to say "Display an & character" instead of "Start a character reference", then you need to use a character reference to represent it: & (so ').
you should use ' .
Related
I would like to understand why using a browser, and editing an html page with the inspect button, the value fields of the radio inputs cannot be changed with;
value='"'
I change the character to & quot;
value="""
because chrome firefox and others do not allow to insert the character " clean within the value?
can you give me an explanation on this?
The inspector favors double quotes to clearly show strings. It may not actually look that way in the DOM, but in the inspector it's the rule. You can't have an unescaped double quote in-between 2 others, so value="\"" might work, or value=""" as you said. Not sure how relevant this link is but it shows that they purposely hard-code that double quote in there
I accept some of the symbols, we have to use character entities. But what is the difference to use & and & or > and > and some of them which is available in keyboard.
Just for knowledge purpose.
Thanks in Advance.
The only characters you need to use character references for are < (start of tag), & (start of character reference), " (start/end of attribute value) and ' (ditto), and then only in places where they have special meaning.
e.g. < means "start of tag" in many parts of an HTML document, so you have to use < if you want to express "less than symbol" instead.
Character entities are used to display reserved characters in HTML.
< , & are reserverd charcters .
I am having trouble understanding how escaping works inside html tag attribute values that are javascript.
I was lead to believe that you should always escape & ' " < > . So for javascript as an attribute value I tried:
It doesn't work. However:
and
does work in all browsers!
Now I am totally confused. If all my attribute values are enclosed in double quotes, does this mean I do not have to escape single quotes? Or is apos and ascii 39 technically different characters? Such that javascript requires ascii 39, but not apos?
There are two types of “escapes” involved here, HTML and JavaScript. When interpreting an HTML document, the HTML escapes are parsed first.
As far as HTML is considered, the rules within an attribute value are the same as elsewhere plus one additional rule:
The less-than character < should be escaped. Usually < is used for this. Technically, depending on HTML version, escaping is not always required, but it has always been good practice.
The ampersand & should be escaped. Usually & is used for this. This, too, is not always obligatory, but it is simpler to do it always than to learn and remember when it is required.
The character that is used as delimiters around the attribute value must be escaped inside it. If you use the Ascii quotation mark " as delimiter, it is customary to escape its occurrences using " whereas for the Ascii apostrophe, the entity reference ' is defined in some HTML versions only, so it it safest to use the numeric reference ' (or ').
You can escape > (or any other data character) if you like, but it is never needed.
On the JavaScript side, there are some escape mechanisms (with \) in string literals. But these are a different issue, and not relevant in your case.
In your example, on a browser that conforms to current specifications, the JavaScript interpreter sees exactly the same code alert('Hello');. The browser has “unescaped” ' or ' to '. I was somewhat surprised to hear that ' is not universally supported these days, but it’s not an issue: there is seldom any need to escape the Ascii apostrophe in HTML (escaping is only needed within attribute values and only if you use the Ascii apostrophe as its delimiter), and when there is, you can use the ' reference.
' is not a valid HTML reference entity. You should escape using '
Why we use & instead of & ?
What is the advantage ?
From HTML 4.0.1 Specification:
Authors should use & (ASCII
decimal 38) instead of & to avoid
confusion with the beginning of a
character reference (entity reference
open delimiter). Authors should also
use & in attribute values since
character references are allowed
within CDATA attribute values.
Your question should be reversed!
You should always use &, because that's the only way to create valid HTML.
Since the & character is used for entities (such as & or >), it must be escaped in order to write a literal &.
As stated in, When did single quotes in HTML become so popular? and Jquery embedded quote in attribute, the Wikipedia entry on HTML says the following:
The single-quote character ('), when used to quote an attribute value, must also be escaped as ' or ' (should NOT be escaped as ' except in XHTML documents) when it appears within the attribute value itself.
Why shouldn't ' be used? Also, is " safe to be used instead of "?
" is on the official list of valid HTML 4 entities, but ' is not.
From C.16. The Named Character Reference ':
The named character reference '
(the apostrophe, U+0027) was
introduced in XML 1.0 but does not
appear in HTML. Authors should
therefore use ' instead of
' to work as expected in HTML 4
user agents.
" is valid in both HTML5 and HTML4.
' is valid in HTML5, but not HTML4. However, most browsers support ' for HTML4 anyway.
' is not part of the HTML 4 standard.
" is, though, so is fine to use.
If you need to write semantically correct mark-up, even in HTML5, you must not use ' to escape single quotes. Although, I can imagine you actually meant apostrophe rather then single quote.
single quotes and apostrophes are not the same, semantically, although they might look the same.
Here's one apostrophe.
Use ' to insert it if you need HTML4 support. (edited)
In British English, single quotes are used like this:
"He told me to 'give it a try'", I said.
Quotes come in pairs. You can use:
<p><q>He told me to <q>give it a try</q></q>, I said.<p>
to have nested quotes in a semantically correct way, deferring the substitution of the actual characters to the rendering engine. This substitution can then be affected by CSS rules, like:
q {
quotes: '"' '"' '<' '>';
}
An old but seemingly still relevant article about semantically correct mark-up: The Trouble With EM ’n EN (and Other Shady Characters).
(edited) This used to be:
Use ’ to insert it if you need HTML4 support.
But, as #James_pic pointed out, that is not the straight single quote, but the "Single curved quote, right".
If you really need single quotes, apostrophes, you can use
html | numeric | hex
‘ | | // for the left/beginning single-quote and
’ | | // for the right/ending single-quote