HTML <style> tag

The <style> tag is used to set styles for a page and styles for the elements on the page. Styles such as background color, text color, text font type, borders around elements, and much more.

NOTE: The <style> tag always goes in the head section of an HTML document.

NOTE: Styles are not set with HTML, but with another language called CSS. Learn CSS at our CSS tutorials.

Attributes

Attribute Description Possible values
type Required. Sets the MIME type of the stylesheet text/css
media Sets which device the styles will be used for. NOTE: Can have more than one value all, aural, braille, handheld, print, projection, screen, tv, tty

For more information on media types read our CSS media types page.

Standard attributes

dir, lang, title, xml:lang

For more information on standard attributes, check out our HTML standard attributes reference page.

Event attributes

NONE

For more information on event attributes, check out our HTML event attributes reference page.

Example

<html> <head> <style type="text/css"> h1 {background-color: #c2d7ab; font-family: georgia;padding:8px;} p {color: #687687; font-family: verdana;} </style> </head> <body> <h1>Wireless Internet</h1> <p> Wireless internet, also known as 802.11 or WiFi is a very convenient way of getting online. In some places, just bring your laptop, have a seat, and you're ready to go! </p> </body> </html>
Output:

Wireless Internet

Wireless internet, also known as 802.11 or WiFi is a very convenient way of getting online. In some places, just bring your laptop, have a seat, and you're ready to go!

Tips & notes

Styles set using the <style> tag are declared internally, but it's better to declare them externally (in a separate file). In a separate file, you can create a set of styles in one place and can change the appearance of many different pages at once by editing those styles as opposed to going into every page and changing the styles manually which is how it has to be done with internal styles. Read about declaring styles externally at our CSS stylesheets page.

You can use the <style> tag more than once on a single page, but keep in mind that it must always be located in the head section of an HTML document.

Web Reference
  1. CSS reference
  2. RSS reference
  3. HTML reference


© Copyright 2011-2012 Landofcode.com
Terms of use | Privacy policy | Copyright information | Make a donation