Implementation: CSSProperties

Cascading Style Sheets (CSS) are used to apply styles to a webpage (internal) or website (external). Understanding the properties of text and backgrounds provides fundamental knowledge of CSS and how to apply styles using selectors, classes and IDs.

Part ofComputing ScienceWeb design and development

Properties

When using CSS, a developer can alter the values stored for properties of an element. The properties that you need to be able to alter are:

  • text
    • font-family
    • font-size
    • color
    • alignment
  • background color

Text properties

The CSS rules shown below all exemplify use of the following text properties:

  • font-family
  • font-size
  • color
  • text-align

The table below shows common values for the above properties.

font-familyfont-sizecolortext-align
Arial10pxredleft
Calibri12pxgreenright
Times14pxblackcenter
Times New Roman16pxbluejustify
Serif18pxwhiteinherit
font-familyArial
font-size10px
colorred
text-alignleft
font-familyCalibri
font-size12px
colorgreen
text-alignright
font-familyTimes
font-size14px
colorblack
text-aligncenter
font-familyTimes New Roman
font-size16px
colorblue
text-alignjustify
font-familySerif
font-size18px
colorwhite
text-aligninherit

The property values shown above are not exhaustive. The font-size and color properties can both be implemented in numerous ways. In the table shown above, px is used to define the size of the text and the name of the color is used to identify colors.

Background colors

To apply a background color to a page, the following CSS rule could be used.

body {
background-color:ivory;
}

This CSS rule would apply an ivory colored background to the page or pages in question.

If part of an external CSS file, the background color could be applied to all pages linking to the file. If used as part of an internal style, the background color of that particular webpage would be ivory.

Background colors can be applied to a range of elements, not only the body element. This means that it is possible to change the background of a particular paragraph or section on a page without changing the background of the entire page.