What else can be used instead of < or > in HTML codes? - html

When we do any HTML coding we use < and > to specify a tag which any browser does not show as text but as display. Can anything else(any coding, for HTML) be used instead of these symbols?

I think you are asking whether it is possible to use characters other than < and > as tag start and tag end characters. For example, can one somehow define that [ and ] are used instead, so that we would write [p] and not <p>.
The answer is no. HTML was formally based on SGML, which has provisions for such definitions; in SGML, < and > are just “reference concrete syntax” characters for abstract “start of tag” and “end of tag” notations. But HTML was never actually implemented as SGML-based, and the HTML specifications even formally fixed the syntax to use < and >. And XML, the simplified version of SGML, upon which XHTML is based, has no provisions for setting such syntax features.

In practical terms: No. Only < and > mark the start and end of a tag in HTML.
In theoretical terms only (because this is not supported by any mainstream browser), in HTML 4 and earlier you could use SHORT TAGS. The syntax for this is to use / instead of > to end the start tag and then / instead of the entire end tag:
For example:
<title/This is the title/
or
<br/ <!-- note that the end tag for br elements must be omitted in HTML 4 and earlier -->
Some other SGML features may allow other options, but they would also not be supported by browsers.
The following is my answer to what appeared to be the original question after someone had edited it to show < instead of <.
In theory, for HTML 4 and earlier, you can use CDATA sections … but they never saw widespread support in browsers so aren't of any practical value in HTML.
There is also the <xmp> element, which is obsolete. The HTML 5 draft marks it as non-conforming and says:
Use pre and code instead, and escape "<" and "&" characters as "<" and "&" respectively
The W3C Wiki has this to say about xmp:
No, really. don't use it.
Character references (< and co) are the correct tools for the job. Any desire to avoid them is better replaced by learning to love a programatic solution or the find & replace feature of your editor.

Related

In what contexts can you use greater than as text in html

In what contexts can I use the greater than symbol < as text in HTML?
For example < & <= parse render as text perfectly fine if they are in a tag:
<p>
<
<=
</p>
However <t will be parsed as HTML by the browser and not produce the text <t.
Is there a rule for what characters can proceed the greater than symbol for the browser to assume that it is the start of a tag?
The rule is: almost never.
Only inside quoted attribute values (and in raw text tags like script and style) are you permitted to write < unescaped. I think attribute names permit these too, but not > (though why you would put a < in an attribute name is beyond me).
Browsers will do their best to recover from bad HTML, so sometimes you might get away with it if you forget.
But it's best to always encode your entities.
You should scan the HTML spec, but here's one relevant chapter with some of the constraints listed in various sections.
Use an HTML validator in strict mode to make sure you're getting it right; the HTML you gave in your question is rejected by the linked tool, with a suggestion to switch to <.

How to avoid <> in HTML?

I would like to paste into my HTML code a phrase
"<car>"
and I would like that this word "car" will be between <>. In some text will be
"<car>"
and this is not a HTML expression. The problem is that when I put it the parser think that this is the HTML syntax how to avoid it. Is there any expression which need to be between this?
replace < by < and > by >
Live on JSFiddle.
< and > are special characters, more special characters in HTML you can find here.
More about HTML entities you can find here.
use > for > and < for <
$gt;car<
you need to use special character .. To know more about Special Character link here
CODE:
<p>"<car >"</p>
OUTPUT:
"<car>"
< = < less than
> = > greater than
The same applies for XML too. Take a look here, special characters for HTML.
If you really want LESS THAN SIGN “<” to appear visibly in page content, write it as &, so that it will not be treated as starting a tag. Ref.: 5.3.2 Character entity references in HTML 4.01.
So you would write
<car>
If you like, you can write “>” as > for symmetry, but there is no need to.
But if you really want to put something in angle brackets, e.g. using a mathematical notation, rather than a markup notation (as in HTML and XML), consider using U+27E8 MATHEMATICAL LEFT ANGLE BRACKET “⟨” and U+27E9 MATHEMATICAL RIGHT ANGLE BRACKET “⟩”. They cause no problems to HTML markup, as they are not markup-significant. If you don’t know how to type them in your authoring environment, you can use character references for them:
⟨car⟩
This would result in ⟨car⟩, though as always with less common special characters, you would need to consider character (font) problems.
You can use the "greater than" and "less than" entities:
<car>
The W3C, the organization responsible for setting web standards, has some pretty good documentation on HTML entities. They consist of an ampersand followed by an entity name followed by a semicolon (&name;) or an ampersand followed by a pound sign followed by an entity number followed by a semicolon (&#number;). The link I provided has a table of common HTML entities.

invalid tags in HTML <abc> vs <1234>

I was writing a simple web page. And I wanted to print <abc> and <1234> inside the page. Why <1234> is printed not <abc>? I know <abc> is invalid tag thats why it is not rendered. But what about <1234>?
You have to do it like:
and <1234>
Use HTML entities.
< = <
> = >
Using them tells HTML that you want the < and > to be displayed as it is and not be interpreted as the < and > in <html>
DEMO
P.S.: Here's a list of them.
This is down to the way that browsers parse the HTML into a format that gets displayed as a web page.
As a rule, HTML tags must start with letters. Because of this, the browser attempts to parse as a valid tag (therefore hiding it), but doesn't recognise <1234> and therefore leaves it untouched.
Edit:
As #Arkana pointed out below, there's nothing I can see in the HTML specification that specifically forbids starting a HTML tag with a number. My best guess is that because no (currently valid) HTML tags actually do start with a number, the browser's parser just ignores these tags, based on the same rule that IDs and Names follow according to the HTML4 spec.
In XHTML and in HTML5 (even in HTML serialization), both <abc> and <123> are invalid. In HTML 4.01, <123> is valid, though not recommended, and it simply means those five data characters.
What matters in browsers is how they parse an HTML document. There is an attempted semi-formal description of this in HTML5 CR, but it’s a bit hard reading. The bottom line is that < triggers special parsing: if the next character is a letter, data is parsed as an HTML tag; otherwise, the < as well as data after it are taken as normal data characters.
When a tag like <abc> has been parsed, modern browsers construct an element node in the document tree – even though the tag is invalid and the tag name is not known to the browser at all. If there is no end tag <abc>, the node contains all the rest there is in the document. But for an element node with an unknown name, there is no default styling and no default action. You won’t notice its existence, unless you try to do something with it (like put abc { color: solid red } in a style sheet).
Technically, one could say that the cause of the difference is that “a” is a name start character (a character that may appear as the first one in a tag name), whereas “1” is not.
It is safest to always escape a “<” character in content (except for style and script and xmp elements, which have rules of their own) as <. There is no need to escape a “>”, but if desired, for symmetry, you can escape it as >.
Unrecognised elements are added to the DOM for forward compatibility (they can be enhanced with CSS/JS). Element names may not begin with a number though, so they are not added to the DOM and error recovery treats them as text instead.
Use < and > if you want to include < and > as data instead of markup.

In what scopes do special HTML characters need to be escaped?

In HTML,
Dust & Bones
needs to be escaped as follows:
Dust & Bones
What's the scope of where &amp needs to be applied. Is it just href or is it anywhere within HTML text? What about
<input value="http://... & ">?
or within
<script>... & ... </script>
do these need escaping?
update
The bigger question, which would explain this, is, when does the HTML parser look for &XXX; tokens and replace them? Is it done once on the whole document, or do different rules apply for the text between tags vs. attribute values within a tag vs. wihtin tagA vs. within tagB -- different parsing rules seem to apply within , so I may write && (for AND) and < for (LESS-THAN). So, what rules apply in which scopes?
The rules vary depending on the version of HTML you are dealing with but are always more complex then is worth trying to remember.
The safe approach is "Use character references to represent the 5 HTML special characters everywhere except inside script and style elements", which makes you safe for everything except XHTML.
For XHTML the rule is the same with the additional proviso of "and use explicit CDATA sections in script and style elements".
The bigger question, which would explain this, is, when does the HTML parser look for &XXX; tokens and replace them?
As it parses the HTML (depending on what the current state of the tokeniser is ("inside start tag" and "inside attribute value" are examples of different states)).
Is it done once on the whole document
Unless you trigger additional HTML parsing (e.g. by setting innerHTML on an element).
or do different rules apply for the text between tags vs. attribute values within a tag vs. wihtin tagA vs. within tagB
Different rules apply in different places. The complete, current rules are (as I suggested in a comment) rather complex and would require a lot of work to extract from the HTML 5 parsing rules. This is why I suggest, if you are an HTML author and not a browser author, using the simpler rules of "Use character references unless you are in a script or style element".
-- different parsing rules seem to apply within <script>, so I may write && (for AND) and < for (LESS-THAN). So, what rules apply in which scopes?
In HTML 4 terms, script and style elements are defined as containing CDATA (where the only sequence of characters with special meaning in HTML are </ which terminates the CDATA section). Everywhere else in the document (including, counter-intuitively, attribute values that are defined as containing CDATA) & indicates the start of a character reference (although there might be a few exceptions based on what the character following the & is).
The HTML 5 rules are more complicated, but the basic principle of "It is safe and sane to use character references for &, <, >, " and ' everywhere except inside script and style elements" holds.

How can you make <html> show inside of a <p> tag?

I am currently creating a webpage to teach others HTML. In my HTML document, I want to make a paragraph like, "Start with html, and end with /html". The html and /html should have <> tags around them, but I don't know how to do this! (this is my question) The document just leaves html and /html (with <> around them) out. How do I make sure that the document leaves it in?
Thank you.
Use HTML entities
To write the characters < and > use < and >
This gives you:
<html> and </html>
Rendered as:
<html> and </html>
This is called HTML Entities. A more complete list can be found here or on wikipedia.
In HTML, there is a standard set of 252 named character entities for
characters - some common, some obscure - that are either not found in
certain character encodings or are markup sensitive in some contexts
(for example angle brackets and quotation marks). Although any Unicode
character can be referenced by its numeric code point, some HTML
document authors prefer to use these named entities instead, where
possible, as they are less cryptic and were better supported by early
browsers. Character entities can be included in an HTML document via
the use of entity references, which take the form &EntityName;, where
EntityName is the name of the entity. For example, —, much like
— or —, represents U+2014: the em dash character "—" even
if the character encoding used doesn't contain that character.
Use amp codes (HTML Entities)!
<p><html></p>
You can use the HTML entities: > for >, < for <.
If you want to display HTML tags replace all < and > with < and <
Example: <HTML>
use &lt for < and &gtfor >