CSS, or Cascading Style Sheets, is a stylesheet language used to describe the presentation of a document written in HTML or XML. CSS describes how elements should be rendered on screen, on paper, in speech, or on other media.
The primary purpose of CSS is to separate content from design, allowing developers to maintain consistency across multiple web pages by controlling the layout, colors, fonts, and overall visual aesthetics of a website.
body {
background-color: lightblue;
}
h1 {
color: white;
text-align: center;
}
p {
font-family: verdana;
font-size: 20px;
}
CSS allows for greater control over the appearance of a website, enabling responsive designs that adapt to different screen sizes and devices.
By using CSS, developers can apply styles to multiple elements simultaneously, reducing redundancy and improving load times.
Console Output:
This is a styled webpage with a light blue background and centered white header text.
CSS syntax is composed of a selector and a declaration block. The selector points to the HTML element you want to style. The declaration block contains one or more declarations separated by semicolons.
In the example below, the selector is "p" and the declaration block is enclosed in curly braces, containing two declarations: color and font-size.
p {
color: red;
font-size: 16px;
}
Selectors are used to target the HTML elements to which you want to apply styles. They can be simple, like targeting an element by its name, or complex, involving multiple elements, classes, or IDs.
Each declaration includes a CSS property name and a value, separated by a colon. Properties specify the stylistic aspect that you want to change, such as color, font-size, or margin.
Console Output:
The paragraph text is styled with a red color and a 16px font size.
Inline CSS is used to apply a unique style to a single HTML element. It uses the style attribute inside the HTML tag.
Internal CSS is used to define styles for a single HTML page. It is defined within a
This is a paragraph.