Style - HTML Element

The style element of HTML is used to add styling rules, either embedded or external.

1286 views

Edited: 2019-11-03 04:39

The HTML style Element is used to embed styling rules directly in a page, or load external styling rules, (such as CSS StyleSheet). The rules contained in a style element are used to control the appearance and layout of a page.

External StyleSheets are normally added with the link element in the head of a page, but can also be added using a @import rule. I.e.:

<style type="text/css">
   @import url("/style.css");
 </style>

Attributes

Attribute:Value:Description:
AttributesOther AttributesGlobal, I18n, Event
typeContent TypeThe Content Type of the scripting language used.
mediaMedia DescriptorEither a single, or comma-separated list. I.e. "screen,print"
titleTextAdvisory title

Example

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">

  <head>
    <title>My first Website</title>
    <style type="text/css">
      h1 {color:#0000FF;}
      p {font-size:2em;}
    </style>
  </head>

  <body>
    <h1>My first use of Style</h1>
    <p>Using CSS to change the style of headings and paragraphs</p>

  </body>

</html>

Tell us what you think: