CSS (Cascading Style Sheets) uses properties and values to control the presentation of HTML elements. A property is a characteristic of an element, such as color or font size, while the value defines the specific appearance of that property. Together, properties and values allow developers to customize elements to create visually appealing and responsive web designs.
In CSS, properties define what aspect of an element you want to style. Properties cover various aspects of design, including text styling, layout, colors, and animations. Here are some commonly used CSS properties:
Properties are always written in lowercase and followed by a colon (:
), with the specified value following.
Each property in CSS is assigned a value, which determines the specific outcome of that property. Values can be colors, measurements, keywords, or functions, depending on the property.
Example:
In this example, color
is set to red
, font-size
is 18px
, and margin
is 10px
. Values should correspond to the type expected by the property.
There are various types of values in CSS, which include:
none
, solid
, auto
, or inherit
.red
), hex codes (e.g., #ff0000
), RGB/RGBA values (e.g., rgb(255, 0, 0)
), or HSL values (e.g., hsl(0, 100%, 50%)
).px
(pixels), em
(relative to the font size), and %
(percentage of the containing element).url()
for background images or calc()
for calculations.In CSS, properties and values are written in a specific syntax. A declaration consists of a property and its value, separated by a colon, with a semicolon at the end to terminate the statement.
Multiple declarations can be grouped together in a rule set:
For example:
This code applies a blue color, 24px font size, and 20px margin to all <h1>
elements on the page.
Some CSS properties accept multiple values. For instance, the margin
property can take up to four values to define the margin for each side of an element:
Here, 10px
is applied to the top margin, 15px
to the right, 20px
to the bottom, and 25px
to the left.
Understanding CSS properties and values is fundamental to creating effective stylesheets. Properties define the aspects of styling, and values specify the details, allowing for extensive control over HTML presentation. Mastering these elements enables developers to build visually appealing and responsive web pages.