Little Web Hut

HTML 4.01 and XHTML 1.0 Reference: <style> Tag

HTML <style> Tag
Syntax This element uses separate opening and closing tags.
<style>...</style>
Usage The <style> tag is used to define style information for the web page. The style information is contained between the opening and closing <style> tags. The <style> tag is located in the head section (between the opening and closing <head> tags).

HTML <style> tag example.
<html>

<head>
<title>HTML Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
  p, h1, h2 {color: red;}
  h3 {text-align: center;}
</style>
</head>

<body>
  <h1>h1 tag color set to red.</h1>
  <h2>h2 tag color set to red.</h2>
  <h3>h3 tag text-align set to center.</h3>
  <p>p tag color set to red.</p>
</body>

</html>
Test It HTML Style

XHTML <style> tag example.
<html xmlns="http://www.w3.org/1999/xhtml">
    
<head>
<title>HTML Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
  p, h1, h2 {color: red;}
  h3 {text-align: center;}
</style>
</head>

<body>
  <h1>h1 tag color set to red.</h1>
  <h2>h2 tag color set to red.</h2>
  <h3>h3 tag text-align set to center.</h3>
  <p>p tag color set to red.</p>
</body>

</html>
Test It XHTML Style

Content Model The <style> element can contain Text between its opening and closing tags.

<style> Tag Attribute Summary
Required Tag Specific Core Focus Events Language
type media xml:space1 id1 title     dir lang xml:lang1
Notes: 1. XHTML only.

<style> Tag Attributes
Attribute Description
typeThe type attribute specifies the style sheet language. The value "text/css" can be used for Cascading Style Sheets (CSS).

HTML <style> tag example using the type attribute.
<html>

<head>
<title>HTML Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
  p, h1, h2 {color: red;}
  h3 {text-align: center;}
</style>
</head>

<body>
  <h1>h1 tag color set to red.</h1>
  <h2>h2 tag color set to red.</h2>
  <h3>h3 tag text-align set to center.</h3>
  <p>p tag color set to red.</p>
</body>

</html>
Test It HTML Style

XHTML <style> tag example using the type attribute.
<html xmlns="http://www.w3.org/1999/xhtml">
    
<head>
<title>HTML Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
  p, h1, h2 {color: red;}
  h3 {text-align: center;}
</style>
</head>

<body>
  <h1>h1 tag color set to red.</h1>
  <h2>h2 tag color set to red.</h2>
  <h3>h3 tag text-align set to center.</h3>
  <p>p tag color set to red.</p>
</body>

</html>
Test It XHTML Style


Note: This is a required attribute.
mediaThe media attribute is used to specify the target medium for the style information. Possible values include "all", "aural", "braille", "handheld", "print", "projection", "screen", "tty", "tv". More than one value can be specified by separating them with commas.

The following example specifies a style to be used when the document is printed:
<style type="text/css" media="print">
xml:spaceThe xml:space attribute is used to specify that whitespace should be preserved.

XHTML <style> tag example:
<style type="text/css" xml:space="preserve">


Note: XHTML only.
idThe id attribute assigns a unique name to a tag. This allows style sheets or scripts to reference the tag. See id Example

Note: XHTML only.
titleThe title attribute specifies additional information about the tag. It is common for browsers to display the title when the pointing device stops over the object. See title Example
dirThe dir attribute tells the browser whether the text should be displayed from left-to-right or right-to-left. It does not reverse the direction of the characters, like the <bdo> tag does, but it can help the browser to determine if the text should be aligned on the left side or the right side. See dir Example
langThe lang attribute specifies a language. This attribute can help the browser to correctly display text. This attribute can also be useful for braille translation software, speech synthesizers, dictionary definitions, etc. See lang Example
xml:langThe xml:lang attribute specifies a language for XHTML documents. This attribute can help the browser to correctly display text. This attribute can also be useful for braille translation software, speech synthesizers, dictionary definitions, etc. See xml:lang Example

Note: XHTML only.

HTML <style> Tag Examples
Test It HTML StyleTest It HTML Style<style> tag example.