Example of embedded CSS


Place your CSS rules into an HTML document using the <style> element that is called embedded CSS. This tag is placed inside <head>...</head> tags. Rules defined using this syntax will be applied to all the elements available in the document.

Following is the example of embed CSS based on the above syntax:

<!DOCTYPE html>
<html>
   <head>
      <style media = "all">
         body {
            background-color: orange;
         }
         h1 {
            color: yellow;
            margin-left: 30px;
         }
      </style>
   </head>
   <body>
      <h1>This is a heading</h1>
      <p>This is a paragraph.</p>
   </body>
</html>

The following is the attribute:

Attribute
Value
Description
Type
text/css
Specifies the style sheet language as a content-type (MIME type). This is required attribute.
media
screen
tty
tv
projection
handheld
print
braille
aural
all
Specifies the device the document will be displayed on. The default value is all. This is an optional attribute.


Lakshmi Srinivas
Lakshmi Srinivas

Programmer / Analyst / Technician

Updated on: 04-Mar-2020

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements