style Element

Description

The style element lets you define CSS styles inline in your HTML document.

style element has the local Attributes: type, media, scoped.

The scoped attribute has been added in HTML5.

Example

The following code gives an example of the style element in use.


<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
a  {<!--from w w  w  . j a  v a  2 s.  co m-->
    background-color: grey;
    color: white;
    padding:  0.5em;
}
</style>
</head>
<body>
    <p>This is a test.</p>
    <a href="http://java2s.com">Visit  java2s.com</a>
</body>
</html>

Click to view the demo

The code above created a new style for the a element. It displays the link with a grey background, white text, and some padding.

You can use the style element throughout an HTML document, and a single document can contain multiple style elements.

type

The type attribute from style element lets you tell the browser what kind of style you are going to define; however, the only style mechanism that browsers support is CSS, so the value of this attribute will always be text/css.





















Home »
  HTML CSS »
    HTML »




HTML Introduction
HTML Document
HTML Section
HTML Group Content
HTML Text Marker
HTML Table
HTML Form
HTML Embed