There are four ways to associate styles with your HTML document. Most commonly used methods are inline CSS and External CSS :
1.Inline CSS
2.Internal Css
3.External Css
4. Imported CSS
EMBEDDED CSS â THE <STYLE> ELEMENT
You can put your CSS rules into an HTML document using the <style> element. This tag is placed inside the <head>âŚ</head> tags. Rules defined using this syntax will be applied to all the elements available in the document. Here is the generic syntax â
EXAMPLE
Following is the example of embedded CSS based on the above syntax â
<!DOCTYPE html>
<html>
 <head>
   <style type = âtext/cssâ media = âallâ>
    body {
      background-color: linen;
    }
    h1 {
      color: maroon;
      margin-left: 40px;
    }
   </style>
 </head> Â
 <body>
   <h1>This is a heading</h1>
   <p>This is a paragraph.</p>
 </body>
</html>
ATTRIBUTES
Attributes associated with <style> elements are â
AttributeValueDescription
typetext/cssSpecifies the style sheet language as a content-type (MIME type). This is required attribute.
mediascreen tty tv projection handheld print braille aural allSpecifies the device the document will be displayed on. Default value is all. This is an optional attribute.
INLINE CSS â THE STYLE ATTRIBUTE
You can use style attribute of any HTML element to define style rules. These rules will be applied to that element only. Here is the generic syntax â
<element style = ââŚstyle rulesâŚ.â>
ATTRIBUTESAttributeValueDescription
stylestyle rulesThe value of style attribute is a combination of style declarations separated by semicolon (;).
EXAMPLE
Following is the example of inline CSS based on the above syntax â
<html>
 <head>
 </head>
 <body>
   <h1 style = âcolor:#36C;â>
    This is inline CSS
   </h1>
 </body>
</html>
EXTERNAL CSS â THE <LINK> ELEMENT
The <link> element can be used to include an external stylesheet file in your HTML document.
An external style sheet is a separate text file with .css extension. You define all the Style rules within this text file and then you can include this file in any HTML document using <link> element.
Here is the generic syntax of including external CSS file â
<head>
 <link type = âtext/cssâ href = ââŚâ media = ââŚâ />
</head>
ATTRIBUTES
Attributes associated with <style> elements are â
AttributeValueDescription
typetext cssSpecifies the style sheet language as a content-type (MIME type). This attribute is required.
hrefURLSpecifies the style sheet file having Style rules. This attribute is a required.
mediascreen tty tv projection handheld print braille aural allSpecifies the device the document will be displayed on. Default value is all. This is optional attribute.
EXAMPLE
Consider a simple style sheet file with a name mystyle.css having the following rules â
h1, h2, h3 {
 color: #36C;
 font-weight: normal;
 letter-spacing: .4em;
 margin-bottom: 1em;
 text-transform: lowercase;
}
Now you can include this file mystyle.css in any HTML document as follows â
<head>
 <link type = âtext/cssâ href = âmystyle.cssâ media = â allâ />
</head>
IMPORTED CSS â @IMPORT RULE
@import is used to import an external stylesheet in a manner similar to the <link> element. Here is the generic syntax of @import rule.
<head>
 <@import âURLâ;
</head>
Here URL is the URL of the style sheet file having style rules. You can use another syntax as well â
<head>
 <@import url(âURLâ);
</head>
EXAMPLE
Following is the example showing you how to import a style sheet file into HTML document â
<head>
 @import âmystyle.cssâ;
</head>













