Resources | Subject Notes | Information Communication Technology ICT
Be able to attach comments to an external stylesheet.
A stylesheet is a separate file that contains the rules for how an HTML document should be displayed. Using external stylesheets is a good practice as it separates the presentation (styling) from the content (HTML), making websites easier to maintain and update.
External stylesheets are linked to HTML documents using the element within the
section.
Comments in CSS stylesheets are used to provide explanations, notes, or to temporarily disable sections of code. They are ignored by the CSS parser and do not affect the rendering of the website.
Comments in CSS are enclosed within double hyphens (--
).
.css
extension (e.g., styles.css
).styles.css
file, add comments using the double hyphen syntax.
element in the
section to link the CSS file.Consider the following example:
HTML File (index.html) | CSS File (styles.css) |
---|---|
|
/* This is a comment in the CSS file */
body {
font-family: Arial, sans-serif; /* Sets the default font */
background-color: #f0f0f0;
}
h1 {
color: blue; /* Sets the heading color */
text-align: center;
}
p {
line-height: 1.5; /* Improves readability */
}
|
styles.css
, the line starting with /*
and ending with */
is a comment.font-family
property.h1
and p
styling.Comments are ignored by the browser and are only for human readability.