1D0-61B · Question #57
Which line of code uses the correct syntax to apply an external CSS style sheet to HTML documents?
The correct answer is D. <link rel="stylesheet"type="text/css"href="syb/syb.css"/>. Option D is correct because it uses the <link> element (the proper HTML tag for external resources) with all three required attributes correctly quoted: rel="stylesheet" declares the relationship, type="text/css" specifies the MIME type, and href="syb/syb.css" points to the…
Question
Which line of code uses the correct syntax to apply an external CSS style sheet to HTML documents?
Options
- A<link rel=stylesheet type=css href=syb/syb.css/>
- B<style ref =stylesheet type=text/css href=syb/syb.css/>
- C<style ref ="stylesheet"type="css"href="syb/syb.css"/>
- D<link rel="stylesheet"type="text/css"href="syb/syb.css"/>
How the community answered
(56 responses)- A2% (1)
- B2% (1)
- C5% (3)
- D91% (51)
Explanation
Option D is correct because it uses the <link> element (the proper HTML tag for external resources) with all three required attributes correctly quoted: rel="stylesheet" declares the relationship, type="text/css" specifies the MIME type, and href="syb/syb.css" points to the file path.
Why the distractors fail:
- A uses
<link>correctly but omits quotes around attribute values and usestype=cssinstead oftype="text/css"- both are invalid syntax. - B uses
<style>instead of<link>, and<style>is for embedded CSS written directly in the HTML, not for linking external files. It also incorrectly usesrefinstead ofrel. - C has the same
<style>/referrors as B, plus the incorrect MIME typetype="css".
Memory tip: Think "Link = External, Style = Internal." Whenever you're pulling in a CSS file from outside the HTML document, you always <link> to it. The three attributes to memorize are Rel, Type, Href - RTH ("right there, here it is").
Topics
Community Discussion
5D is the correct answer. The link element is what you use to attach an external stylesheet, not the style element, so B and C are eliminated immediately regardless of anything else wrong with them. A uses link but drops the quotes from attribute values and writes type=css instead of type=text/css, which is the proper MIME type the browser expects. D gets all three attributes right, rel="stylesheet", type="text/css", and href pointing to the file, with every value properly quoted. For your cards, I would make two separate cards out of this. One for the element name, link versus style, because that distinction trips people up on multiple questions, not just this one. The second card for the exact attribute syntax, especially type="text/css" with the text/ prefix, since that is the detail most likely to show up in a distractor.
D is the one, and here is why it sticks: remember LINK-REL-TYPE-HREF, or "Let Rhinos Tackle Hurdles," because a link tag always carries rel="stylesheet" plus type="text/css" plus href pointing to your file, all with proper quotes. The style tag is for internal CSS, not external sheets, so A through C are all dead ends before you even check the quotes.
Type is optional in modern HTML and has been dropped from most style guides, so if you see it on the exam just know it can appear or not and the href with rel="stylesheet" is the real giveaway.
D, and yeah A almost gets you with the missing quotes if you are rushing.
Option D is the only one using the link element, which is what actually attaches an external stylesheet to a document. The style element in B and C is for embedding CSS directly in the page, not pointing to an outside file, so those are wrong on the element alone before you even look at the attributes. Option A uses link but drops the quotes around the attribute values and mangles the href path with a trailing slash that would break the reference entirely. Quick question before you move on: do you know why the type attribute in D is technically optional in HTML5, and when you might still include it anyway?