Html/Training/Style Sheet

From W3C Wiki
< Html‎ | Training

Style Sheets

Style Sheets can format the HTML document. HTML documents may contain style sheet rules directly in them or they may import style sheets. There are three ways of providing styling information for the Web browsers.

Any style sheet language may be used with HTML. This educational materials use the style language "CSS(Cascading Style Sheets)".


Adding style to HTML

Linking style sheet

You can separate style sheets from HTML documents. Style sheet files are imported to HTML documents by <link>.

This offers several benefits:

  • Authors and Web site managers may share style sheets across a number of documents (and sites).
  • Authors may change the style sheet without requiring modifications to the document.
  • User agents may load style sheets selectively (based on media descriptions).


[Syntax]

 <head>
   <link rel="stylesheet" type="text/css" href="example.css">
 </head>


See also The link element.


Internal style sheet

You can put style sheet rules in the head of the document by <style>.


[Syntax]

 <head>
   <style>
     p { color: red; font-size:120%; }
   </style>
 </head>
 <body>

<p>This is a paragraph

 </body>


See also The style element.


Inline style sheet

The start tags can contain style sheet rules directly in HTML documents by the style attribute.


[Syntax]

<p style="color: red; font-size:120%; ">This is a paragraph


If you would like to learn CSS syntax, you go to the CSS educational materials for beginners.


In the next content, you will learn the script element.