HTML Style attribute
- In earlier versions of HTML each tag had
mishmash of
attributes that were
used to
control things like colors, fonts, alignment, and size of things.
- These are replaced by the style attribute
(though most of the old
attributes and tags are still supported)
- The style attribute can be added to many tags
to define how the
element will appear
- Not all aspects of the style element would
apply to all tags.
- Use the style attribute by adding style
="property
list" to an html tag.
- property names and values are
separated by colons, e.g. color:red
- properties in the list are separated by
semi-colons, e.g.
font-family:Helvetica; color:red;
- example:
<h1 style = "font-family:Helvetica; color:red;
text-decoration:blink; text-align:center;
background-color:green;">red blinking text
centered</h1>
red
blinking text centered
- division tags, <div> can be used to
set a common set
of styles for a region of your page, e.g.
<div style = "font-family:Helvetica; color:blue;
text-decoration:blink; text-align:center;
background-color:gray; font-size:xx-large">
all of this text<br>
is blue,xx-large, blinking, centered<br>
with a gray background
</div>
all
of this text
is blue,xx-large, blinking, centered
with a gray background
- Adding a style attribute to each tag can be
quite tedious,
the preferred method is to create a cascading style sheet that defines
how you would like different tags to appear. This style sheet is
stored in a separate file and can be used with all your pages.