CSS (Cascading Style Sheets)
CSS, or Cascading Style Sheets, is a stylesheet language used to describe the look and formatting of documents written in HTML, XHTML, or XML. CSS provides the ability to separate the presentation from the content, which makes it easier to maintain and scale web pages.
History
- 1994: Håkon Wium Lie proposed CSS while working at CERN, the birthplace of the web.
- 1996: CSS level 1 was published as a recommendation by the W3C (World Wide Web Consortium).
- 1998: CSS2 was released, introducing new features like absolute, relative, and fixed positioning of elements.
- 2005: CSS3 was split into several modules, allowing different parts of the specification to evolve at different paces.
Key Concepts
- Selectors: CSS uses selectors to apply styles to elements. These can be element names, classes, IDs, or more complex selectors.
- Properties and Values: CSS rules contain properties and values that define how an element should be styled. For example, `color: red;` sets the text color to red.
- Cascading: The term "cascading" refers to the way styles are applied. Styles can be inherited or overridden based on specificity and origin (user, author, or user-agent).
- Box Model: Every element in CSS generates a rectangular box, known as the CSS box model, which describes the structure of web page elements.
- Positioning: CSS allows for positioning elements in various ways (static, relative, absolute, fixed, and sticky).
- Flexbox and Grid: Modern layout systems introduced in CSS3 for more complex layouts.
Usage
CSS can be applied to a document in three ways:
- Inline: Applied directly to an HTML element using the `style` attribute.
- Internal: Placed within the `