Style Sheet Language
CSS (Cascading Style Sheets) is a style sheet language used for describing 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.
While HTML provides the structure of a web page, CSS provides the visual styling and layout. CSS is designed to enable the separation of presentation and content, improving accessibility and providing more flexibility in the visual characteristics of the page.
/* Basic selector and declaration block */ selector { property: value; another-property: value; } /* Example with actual values */ h1 { color: #333333; font-size: 24px; font-family: 'Arial', sans-serif; margin-bottom: 16px; } /* Class selector */ .button { background-color: #4CAF50; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; } /* ID selector */ #header { background-color: #f2f2f2; padding: 20px; }
/* Element selector */ p { line-height: 1.6; } /* Descendant selector (space) */ article p { font-size: 16px; } /* Child selector (>) */ nav > ul { display: flex; } /* Adjacent sibling selector (+) */ h2 + p { margin-top: 0; } /* Attribute selector */ input[type="text"] { border: 1px solid #ccc; } /* Pseudo-classes */ a:hover { text-decoration: underline; } li:nth-child(odd) { background-color: #f0f0f0; }
/* Flexbox */ .container { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 20px; } /* CSS Grid */ .grid-layout { display: grid; grid-template-columns: repeat(3, 1fr); grid-gap: 16px; } /* Variables (Custom Properties) */ :root { --primary-color: #007bff; --secondary-color: #6c757d; --font-size-base: 16px; } .button { background-color: var(--primary-color); font-size: var(--font-size-base); } /* Media queries */ @media (max-width: 768px) { .container { flex-direction: column; } }
CSS is essential for web development and is used for:
CSS has evolved through several major versions:
CSS is now developed as modules rather than monolithic versions, with ongoing development by the W3C.
Here are some excellent resources for learning CSS:
Technologies that extend or work alongside CSS: