Which of the following tag is used to insert comments in the HTML source code ?
- (a)</-- -->
- (b)<!-- -->
- (c)<-- ! -->
- (d)</-- --/>
Correct — B, (b) the pair that opens with an exclamation mark inside the angle bracket and closes with two hyphens before the closing bracket. A comment in HTML is written between an opening delimiter of a left angle bracket, an exclamation mark and two hyphens, and a closing delimiter of two hyphens and a right angle bracket. Everything between the two is ignored by the browser when the page is rendered. Each option is printed as two fragments with a wide gap between them, because a comment is not one tag but a container: whatever the author writes in the gap is the comment text. The four options differ only in the delimiters, so the whole item is a test of whether the candidate has typed the sequence often enough to recognise it. The logic of the sequence is worth knowing rather than memorising. HTML inherits it from SGML, where a left angle bracket followed by an exclamation mark introduces a markup DECLARATION — something addressed to the parser rather than to the document — and the pair of hyphens then opens a comment inside that declaration. The same opener is visible in the line every HTML file begins with, the document type declaration, which also starts with a left angle bracket and an exclamation mark. Nothing that starts with a left angle bracket followed by a solidus can be a comment, because that sequence is reserved for the closing half of an element. Two practical points follow, and both have been examined. First, comment text is removed from the rendered page but not from the file: anyone can read it with 'view source', so credentials, internal notes and unreleased copy do not belong in HTML comments. Second, commenting out is the standard way of disabling a block of markup temporarily — wrap it in the delimiters and the browser skips it without the author having to delete anything. Note also that the delimiters may not contain a further pair of hyphens inside them, which is why comments cannot be nested.
- (a)</-- --> — The closing delimiter is right and the opening one is wrong. A left angle bracket followed by a solidus is the opening of an END tag — the sequence that closes a paragraph, a division or an anchor — and a parser reading it expects an element name to follow, not a comment. The exclamation mark that actually introduces a markup declaration is missing altogether. Browsers are famously forgiving of malformed markup and will recover from this in one way or another, but nothing in the language defines it as a comment.
- (c)<-- ! --> — Every character of the correct answer is present, and one of them is in the wrong place. The exclamation mark has been moved out of the opening delimiter and dropped into the body of the comment, leaving an opener of a left angle bracket followed by two hyphens. That is not a markup declaration at all, so a parser has no reason to treat what follows as a comment. This is the option that catches candidates who remember that a comment contains an exclamation mark somewhere without remembering where.
- (d)</-- --/> — Wrong at both ends. The opener repeats the closing-tag error of option (a), and the terminator adds a solidus before the right angle bracket, borrowing the self-closing form used for void elements such as a line break or an image in XHTML. A comment has no self-closing form: it is terminated by two hyphens followed immediately by a right angle bracket, and nothing else.
HTML marks up a document with elements, and an element is normally written as a start tag, some content and an end tag. A comment is not an element. It is a markup declaration — a note addressed to whoever reads the source file, which the parser recognises and discards before rendering. That is why its delimiters look nothing like a tag: the opener carries an exclamation mark, the same character that introduces the document type declaration at the head of every page, and there is no element name to close. Comments serve three purposes in practice: documenting what a block of markup does, marking the boundaries of a section in a long file, and temporarily disabling markup during development without deleting it. Different languages in the same web page use entirely different comment syntax — a stylesheet uses a solidus and asterisk pair, and a script uses a double solidus for a single line or the same solidus and asterisk pair for a block — so an author moving between a style block and the surrounding markup has to switch conventions in the same file.
The computers and IT block of this paper stays at the level of things a working officer types or sees rather than at the level of theory, and this item is at the recognition end of that scale. There is nothing to reason out: either the sequence is familiar or it is not. The habit rewarded is reading each option character by character rather than in outline, because all four look alike at a glance and differ by the placement of a single exclamation mark or solidus. Note that the stem prints 'Which of the following tag is used' with a singular noun where the grammar wants a plural; the booklet's wording is reproduced here unchanged.
- An HTML comment opens with a left angle bracket, an exclamation mark and two hyphens, and closes with two hyphens and a right angle bracket.
- The text between the delimiters is ignored when the page is rendered but remains visible in the page source.
- The exclamation mark after the left angle bracket marks a markup declaration; the document type declaration at the top of an HTML file uses the same opener.
- A left angle bracket followed by a solidus opens an END tag and can never open a comment.
- Comments cannot be nested, because a further pair of hyphens is not permitted inside them.
- Commenting out a block is the standard way of disabling markup without deleting it.
- Comment syntax differs by language: a stylesheet uses a solidus-asterisk pair and a script uses a double solidus for a single line.
- Because comments travel to the client in the page source, no confidential information should be written in them.
- Assuming a comment is a tag with an opening and a closing tag, and looking for an element name inside it.
- Placing the exclamation mark anywhere other than immediately after the left angle bracket.
- Adding a solidus to the terminator by analogy with a self-closing element.
- Believing a comment hides information from the user — it is removed from the rendered page, not from the file the browser downloaded.
HTML appears in EO/AO papers as syntax recognition — the comment delimiters, the tag for a line break, the tag for a hyperlink, the attribute that supplies alternative text for an image — and occasionally as a question about which language does what in a web page. Learn the dozen most common tags with their exact punctuation, since the wrong options in this family are always near-misses differing by one character.
No directly related past PYQ was found.
- practice — not a real PYQ
Text written inside an HTML comment is :
- (a)Displayed in the browser in a smaller font
- (b)Removed from the file before it is sent to the browser
- (c)Not rendered by the browser but visible in the page source
- (d)Executed as a script by the browser
Answer(c) Not rendered by the browser but visible in the page source
- practice — not a real PYQ
In an HTML document, the declaration that specifies the document type is written :
- (a)At the end of the body section
- (b)At the very beginning of the document, before the opening html tag
- (c)Inside the title element
- (d)Anywhere in the head section
Answer(b) At the very beginning of the document, before the opening html tag