Which one of the following attributes is required for internal linking in HTML?
- (a)Name
- (b)Align
- (c)Body
- (d)Link
Correct — A, (a) Name. Internal linking means a link that jumps to a place inside the same document — the table of contents at the head of a long page whose entries carry the reader down to the right section, or the back-to-top link at the foot of it. Making one takes two halves, and the attribute this question is after is the one that supplies the first half. The destination has to be marked, and in the anchor element that mark is the name attribute: <a name="section2"></a> placed at the point the reader is to arrive at. That creates what is called a named anchor, or a bookmark. The link itself is then an ordinary anchor whose href carries a fragment identifier — a hash followed by the name — as in <a href="#section2">Go to section 2</a>. The browser matches the fragment against the named anchor and scrolls to it without fetching anything from the server, which is what distinguishes an internal link from an ordinary one. The same fragment can be attached to a full address to jump into a particular part of another page, written as page.html#section2, and a link whose href is just the hash returns the reader to the top of the document. One piece of history is worth carrying, because it explains why two answers can look right in different books. The name attribute on the anchor element is the HTML 4 way of marking a destination. HTML5 dropped it there and uses the id attribute instead, placed on whatever element is the destination — <h2 id="section2">Section 2</h2> — with the link written exactly as before. Since id can be used as an anchor target in HTML 4 as well, modern pages generally use it. The option set here offers no id, and among the four printed the attribute that performs the job is name.
- (b)Align — Align is a presentational attribute, not a linking one. In HTML 4 it appeared on elements such as img, table, paragraph and heading to set the horizontal placement of the content, with values like left, right and center; it was deprecated in favour of style sheets, and the work it used to do belongs to the CSS text-align and float properties. Nothing about it identifies a destination or carries a reader anywhere. It is in the set because it is a familiar attribute name from the same era of hand-written HTML as the named anchor, which makes it recognisable without being relevant.
- (c)Body — Body is an element, not an attribute, and the distinction is the point of the option. An element is a tagged region of the document — body holds everything the reader sees, as against head, which holds the metadata — while an attribute is a name-and-value pair written inside a tag to qualify that element. The question asks which attribute performs a job, so an element name cannot be the answer whatever it does. The confusion is a real one in the other direction as well, because in HTML 4 the body element carried attributes named link, vlink and alink for the colours of hyperlinks, which is exactly the sort of half-memory the next option trades on.
- (d)Link — The word does duty in two places in HTML and neither one creates an internal destination. As an element, link is an empty tag placed in the head of a document to declare a relationship with an external resource — most often a style sheet, written with rel and href attributes — so it points outward, not inward. As an attribute, link belonged to the body element in HTML 4 and set the colour of unvisited hyperlinks, alongside vlink for visited and alink for active ones; all three were deprecated in favour of CSS. Because the word is the obvious one to reach for when the question mentions linking, this is the strongest distractor in the set, and it is defeated by asking what the attribute actually does rather than what it is called.
HTML marks up a document with elements, and qualifies those elements with attributes written as name-and-value pairs inside the opening tag. The anchor element is the one that creates hyperlinks, and it has always had two jobs. With an href attribute it is the source of a link, and the value of href is where the reader goes. With a name attribute it was, in HTML 4, the destination of a link — a marked point in the document that a fragment identifier could aim at. A fragment identifier is the part of an address after a hash, and it is handled entirely inside the browser: the page is not requested again, and the browser simply brings the marked point into view. That is why an internal link is instantaneous and why it works offline on a downloaded page. The modern way to mark a destination is the id attribute, which is a global attribute available on every element and must be unique within the document; HTML5 removed name from the anchor element and made id the single mechanism, so a contemporary page marks its sections by putting an id on the heading itself. Both forms answer to the same link syntax, and knowing that the fragment identifier is the constant part of the mechanism — while the attribute that receives it has changed with the version of the standard — is what allows a candidate to answer this question in either direction. The related vocabulary that examiners draw on is small: href for the destination of a link, target for the window it opens in, rel for the relationship a link declares, and the hash for the fragment.
Web questions in this paper stay at the level of hand-written markup rather than of frameworks, which suits an examination that must be answerable by a candidate from any academic background. The design of this option set repays attention: one correct attribute, one presentational attribute from the same era, one element masquerading as an attribute, and one word that is both an element and an attribute elsewhere in the language. Three of the four are defeated by asking what the thing actually does, and the fourth is defeated by knowing that an element is not an attribute. That is a general defence against the whole family of terminology questions in this block, where the Commission almost always builds the distractors out of real vocabulary used in the wrong slot rather than out of invented words. Note that the item asks which attribute is required for internal linking specifically — href is needed for every link, internal or not, and it is the marking of the destination that makes an internal link internal.
- An internal link points to a place inside the same document, using a fragment identifier — a hash followed by the destination's name — in the href of an anchor.
- In HTML 4 the destination is marked by the name attribute on an anchor element, which creates a named anchor or bookmark.
- HTML5 removed name from the anchor element and uses the id attribute, which is global, unique within the document, and placed on whatever element is the destination.
- A fragment is resolved inside the browser without a fresh request to the server; an href of just a hash returns the reader to the top of the page.
- A fragment can be appended to a full address to jump into a named part of a different page.
- The word link is an element in the head that declares a relationship to an external resource such as a style sheet, and was also a deprecated body attribute in HTML 4 setting the colour of unvisited hyperlinks.
- Mistaking an element for an attribute; two of the four options here are element names in HTML and only one of them is ever an attribute as well
- Answering href, which is needed for every link and does not distinguish an internal one; the mark is on the destination side
- Assuming the HTML5 answer is the only answer — the destination is marked by name in HTML 4 and by id in HTML5, and an option set may print either
- Forgetting that a fragment identifier can be attached to another page's address, so an internal link and an inward link to another page share the same syntax
- Giving the same id to two elements in one document, which makes the destination ambiguous
Markup questions in this paper are single-attribute or single-tag recall items with short one-word options, and the distractors are drawn from real HTML vocabulary used in the wrong role. The preparation that pays is a short list of the elements and attributes that do the main jobs — linking, images, tables, forms and document structure — learnt with what each one does rather than with where it is written.
No directly related past PYQ was found.
- practice — not a real PYQ
In an HTML document, a link written as <a href="#contact">Contact</a> will
- (a)request a file named contact from the server
- (b)move the reader to the element marked as contact within the same document
- (c)open a new browser window
- (d)send an electronic mail message to the address contact
Answer(b) move the reader to the element marked as contact within the same document — the hash introduces a fragment identifier, which the browser resolves against a named anchor or an id inside the page already loaded, with no fresh request to the server. Opening a new window is the work of the target attribute, and a mail link needs the mailto scheme in the href.
- practice — not a real PYQ
Which one of the following attributes must be unique within an HTML document?
- (a)class
- (b)style
- (c)id
- (d)title
Answer(c) id — it identifies one element uniquely, which is what allows it to serve as the destination of a fragment identifier and as a handle for scripts. A class may be shared by any number of elements, and style and title may be repeated freely.