HTML style Tag

  • HTML <style> tag is used to add CSS style to an HTML document. The <style> tag contains CSS properties for an HTML document.

  • Usually <style> tag appear in the <head> element of the document. However it'll also acceptable to used in the <body> element of the document.

Example

<!DOCTYPE html>
<html>
<head>
  <title>HTML style tag</title>
  <style type="text/css">
      h2 {
        font-size: 20px;
        font-family: Verdana, Geneva, sans-serif;
        font-weight: normal;
        color: #196a8e;
      }
      p {
        font-size: 15px;
        color: red;
      }
  </style>
</head>
<body>
  <h2>This example represent style element.</h2>
  <p>This example represent style element.</p>
</body>
</html>

Run it...   »

<style> Tag Attributes

HTML <style> tag support following specific attributes.

Attributes Value Description
media all
braille
print
projection
screen
speech
Specifies the device for media style should be apply to.
type text/css Specifies the MIME type of style sheet language.

Browser Compatibility

  • Google Chrome
    Yes
  • Mozilla Firefox
    Yes
  • Microsoft Edge
    Yes
  • Opera
    Yes
  • Safari
    Yes