Basic CSS Properties
Introduction to CSS Properties
In Cascading Style Sheets (CSS), a property is defined as the element that determines the visual appearance of an HTML element.
Syntax for assigning values:
selector { property: value; }.Standard syntax example:
p { color: blue; }wherepis the selector,coloris the property, andblueis the assigned value.
Text Color: color
Definition: The
colorproperty is used specifically to set the color of text content within an element.Acceptable Values:
Color names: Examples include
red,blue, andgreen.HEX codes: Hexadecimal color representations such as
#ff0000.RGB: Red-Green-Blue functional notation such as
rgb(255,0,0).
CSS Example:
css h1 { color: red; } HTML Application:
<h1>This is a red heading</h1>.
Background Color: background-color
Definition: This property sets the background color for a specific element.
CSS Example:
css body { background-color: lightgray; } HTML Application:
<body>This page has a light gray background</body>.
Background Image: background-image
Definition: Applies a specific image to serve as the background of an element.
CSS Example:
css body { background-image: url("background.jpg"); } Additional Behavior and Notes:
Default Behavior: By default, the specified background image will repeat to fill the element's space.
Repetition Control: To prevent the image from repeating, the
background-repeat: no-repeat;property must be utilized.
Text Alignment: text-align
Definition: Controls the horizontal alignment of the text within an element.
Available Values:
leftrightcenterjustify
CSS Example:
css p { text-align: center; } HTML Application:
<p>This text is centered</p>.
Font Family: font-family
Definition: Specifies the specific typeface (font) used for the text of an element.
CSS Example:
css body { font-family: Arial, sans-serif; } Best Practices: Always include a fallback font (such as
sans-serif) in case the primary font is unavailable.
Font Size: font-size
Definition: This property is used to control the height/size of the text.
Measurement Units:
(pixels): Absolute units.(relative): Units relative to the font-size of the element.(percentage): Relative units based on the parent element's font-size.
CSS Example:
css p { font-size: 18\,px; }
Font Weight: font-weight
Definition: Controls the thickness or boldness of the text characters.
Available Values:
normalboldNumeric range: From
up to.
CSS Example:
css h1 { font-weight: bold; }
Font Style: font-style
Definition: Defines the specific style or slant of the text.
Available Values:
normalitalicoblique
CSS Example:
css p { font-style: italic; }
Combined Practice Example
The following code demonstrates a practical implementation of all properties combined:
General Body Settings:
css body { background-color: #f0f0f0; background-image: url("bg.jpg"); font-family: Arial, sans-serif; } Heading 1 (h1) Settings:
css h1 { color: blue; text-align: center; font-size: 32\,px; font-weight: bold; } Paragraph (p) Settings:
css p { color: black; text-align: justify; font-size: 16\,px; font-style: italic; }
Summary of Essential Properties
color: Used for setting the text color.background-color: Used for setting the background color of an element.background-image: Used for adding a background image to an element.text-align: Used to align text horizontally (left, right, center, or justify).font-family: Used to set the font type or typeface.font-size: Used to control the size of the text (using,, or).font-weight: Used to control the boldness or thickness of text (e.g.,boldor numeric values).font-style: Used to control the style of text, such asitalic.