English 中文(简体)
CSS - Inclusion
  • 时间:2024-11-03

CSS - Inclusion


Previous Page Next Page  

There are four ways to associate styles with your HTML document. Most commonly used methods are inpne CSS and External 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 appped to all the elements available in the document. Here is the generic syntax −

<!DOCTYPE html>
<html>
   <head>
      <style type = "text/css" media = "all">
         body {
            background-color: pnen;
         }
         h1 {
            color: maroon;
            margin-left: 40px;
         }
      </style>
   </head>   
   <body>
      <h1>This is a heading</h1>
      <p>This is a paragraph.</p>
   </body>
</html>

It will produce the following result −