CSS: Cascading Style Sheets

What is CSS?

CSS (Cascading Style Sheets) is a style sheet language used to describe the presentation of a document written in HTML.

It controls the layout, colors, fonts, spacing, positioning, and overall visual appearance of web elements.

CSS helps separate content (HTML) from design.

How to Include CSS

There are three main ways to add CSS to a webpage:

  • Inline styles – applied directly to HTML elements.
  • Internal stylesheet – written inside a style tag in the HTML head
  • External stylesheet – a separate .css file linked to the HTML document.

Common CSS Properties

CSS (Cascading Style Sheets) is used to style HTML elements.

These properties help make web pages more visually appealing. For example:

  • color – sets the text color
  • background-color – sets the background color of an element
  • font-family – defines the font style of the text
  • font-size – controls the size of the text
  • margin – sets the space outside an element
  • padding – sets the space inside an element
  • border – adds a line around the element

CSS Selectors

CSS uses selectors to target HTML elements and apply styles:

  • Element selector: p h1 div
  • Class selector: .container .button
  • ID selector: #header #footer

Pseudo-classes and Pseudo-elements

CSS includes special selectors for specific states or parts of elements:

  • :hover – when the user hovers over an element.
  • :focus – when an element gains focus (like an input field).
  • ::before and ::after – used to insert content before or after an element.

Responsive Design with Flexbox

CSS Flexbox makes it easy to build responsive layouts:

  • display: flex; – enables flex container behavior
  • justify-content – aligns items horizontally
  • align-items – aligns items vertically

Why Use CSS?

CSS gives developers full control over how a website looks and feels.

It improves user experience, supports responsive design for mobile devices, and keeps styling separate from content — making code cleaner and easier to maintain.