What Is CSS?: Specify A Background Color
What Is CSS?: Specify A Background Color
CSS stands for Cascading Style Sheets. It is a language designed to specify the overall appearance of webpages as well as the appearance
and structure of the text and elements such as images and buttons on webpages and their layout. Styles can be specified with CSS using
internal style sheet definitions which are placed right into HTML/XHTML code or in external files.
• Specify a background color - You can specify a background color for a webpage, a table, a form element, a paragraph,
and more.
• Specify a common style for one tag or a set of tags. - For example, you can specify that all text declared with the
<h2> tag should be blue or that all text declared with the <p> (paragraph) tag should be bold and in a Courier font.
• Specify the distance between elements - For example, you can specify how much distance between the top most
point of a page and the first element that appears on it there should be or the line spacing in a paragraph.
• Specify the appearance of links - For example, you can specify that an unvisited link should be blue and not
underlined, when the user moves the mouse over a link it should have a gray background and be underlined, and visited
• Specify multiple styles for various webpages - You can have one stylesheet definition that can be used on several
webpages instead of redefining the style on each individual page. For example, if you want the links on several of your
pages to be green, you can specify this in one external stylesheet definition, and upload it to the pages where you want
this particular style to take effect. Once you want to make a change to the stylesheet definition, you can do so in the
stylesheet, and the changes will appear automatically on all the pages that the stylesheet has been uploaded to.
Al
Use an internal stylesheet when you want an HTML document to have a unique style. An internal stylesheet is defined using the <style>
The <style> tag specifies the content type of a stylesheet with its type attribute which should be set to "text/css".
Syntax:
<html> <head> <style type="text/css"> p {color: green} </style> </head> <body> <p> The text in this paragraph will be green.
The above stylesheet definition specifies that all text declared with the <p> tag should be green.
Output:
NOTE: There are some old browsers still in use that do not support styles. Such browsers will ignore the <style> tag and will display the
content within it on a webpage. You can prevent this by placing HTML comments within the <style> tag:
Example:
<html> <head> <style type="text/css"> <!-- p {color: green;} --> </style> </head> <body> <p> The text in this paragraph will be
Use an external stylesheet when you want to apply one style to many pages. If you make one change in an external stylesheet, the change
An external stylesheet is declared in an external file with a .css extension. It is called by pages whose interface it will affect. External
stylesheets are called using the <link> tag which should be placed in the head section of an HTML document. This tag takes three
attributes.
• rel - When using an external stylesheet on a webpage, this attribute takes the value "stylesheet"
• type - When using an external stylesheet on a webpage, this attribute takes the value "text/css"
• href - Denotes the name and location of the external stylesheet to be used.
Example:
<html> <head> <link rel="stylesheet" type="text/css" href="style1.css" /> </head> <body> <p> The text in this paragraph will be
Output:
The <font> tag is used to set text size, font type, and color. It takes three attributes - size, face, color.
Attributes of the <font> tag
• size - Takes a numerical value (1 (smallest) - 7 (biggest)) specifying the size of the text.
• face - Specifies the font of the text. Many possible values including Times New Roman, Georgia, and Courier New.
<font face="Goergia" color="green" size="4"> The font of this text will be Georgia, it will be green, and a size of 4. </font>
In HTML, frames are a way to display more than one webpage in the same window. Each of these pages will be called a frame. The main
page will not have any content on it, but will contain a 'frameset' that will consist of these frames.
• border - a numeric value which sets the size of the border between frames
• noresize - prevents the user from changing the intended size of your frames. Takes the value "noresize"
In this example, there is a frameset with two rows. The first row is set to 50% of the height of the browser window, and the second row is
p {color:blue}
NOTE: The <style> tag is NOT used in an external stylesheet, and neither are HTML comments.
Use inline stylesheets when you want to apply a style to a single occurence of an element.
Inline stylesheets are declared within individual tags and affect those tags only. Inline stylesheets are declared with the styleattribute.
Example:
In this example, we are using the stylesheet command color to denote that the text in a paragraph will be gray.
Output: