2) External Style Sheet
Here
CSS file is written outside the HTML document and the reference of the CSS file
is placed in the HTML document. In external style sheet, the style sheet rules
are saved into a text file with the .css extension. Once you have a style sheet
document, you can link it with your web pages in the following two ways
i) Linking : Refers to the HTML link element, which
is used to link a style sheet.
<link rel=”stylesheet” type=”text/css” href=”test/css”/>
Here…
rel attribute specifies what you are linking.
type attribute specifies the MIME
type for the browser
href
attribute specifies the path of the .css file.
In the above code, the value of the rel attribute is set to
style sheet, value of the type attribute is set to text/css and that of the
href attribute is set to test.css.
ii) Importing : Here the @import
keyword is used followed by the Uniform Resource Identifier(URI) of the style sheet to which you want to
import the style rules.
<style type=”text/css”>
@import
url(‘demostyle.css”)
H1 {color:blue;}
</style>
In the above code @import keyword followed by the URI of the
style sheet named demostyle.css is used.
Advantages of External Style Sheets :-
Allows you to control the look and feel of several documents
in one go and do not need to define a specific style for every element.
Allows you to easily group your styles in a more efficient
way.
Disadvantages of External Style Sheets :-
Increases the download time as the entire CSS file has to be
downloaded to apply the style to the HTML document.
Displays the web page only after the entire style sheet is
loaded.
3) Inline style:-
These
styles are written in a single line separated by semicolons. These properties are placed inside the style attribute of the HTML element, on which you want to
apply the style.
<p style=”background:cyan; color:black; border:2px solid
white;”>
In the above code the <p> is styled.
Advantages of inline style :-
Provides highest precedence over internal and external style
sheets.
Provides and easy and quick approach to add a style sheet in
a web page. You don’t need to create a whole new document or edit a new element
in the head of your document to add an inline style.
Disadvantages of inline style :-
Makes a document difficult to maintain and increases the download
time. Inline style must be applied to every element on which you want to apply
a style.
Doesn’t allow to style pseudo-elements, which are used to
add special effects to the selectors.