HTML and CSS Reference
In-Depth Information
The Style Element
Embedded styles are placed within a <style> element located in the header section of a
Web page. The opening <style> tag begins the embedded style rules and the closing
</style> tag ends the area containing embedded style rules. When using the <style>
tag, you do not need the style attribute. However, the <style> tag does use a type
attribute that should have the value of "text/css" .
Figure 3.5
Web page using
embedded styles
The following code is an example of a Web page (shown in Figure 3.5) that uses
embedded styles to set the text color and background color of the page.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" lang="en" xml:lang="en">
<title>Embedded Styles</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css">
body { background-color: #CCFFFF;
color: #000033;
<h1>Embedded Styles</h1>
<p>This page uses embedded styles.</p>
Notice the way the style rules were coded with each rule on its own line. The format-
ting is not required for the styles to work, but it makes the styles more readable and
easier to maintain than one long row of text. The styles are in effect for the entire Web
page document because they were applied to the <body> tag using the body selector.
Now let's see a working example. Launch Notepad and open the starter.html file from
the Chapter3 folder in the student files.
Save your page as embedded.html and test it in a browser. Your page should look simi-
lar to the one shown in Figure 3.6.
Search WWH ::

Custom Search