How To Add CSS

When a browser reads a style sheet, it will format the HTML document according to the information in the style sheet.

Three Ways to Insert CSS

There are three ways of inserting a style sheet:

  • External CSS
  • Internal CSS
  • Inline CSS

External CSS

With an external style sheet, you can change the look of an entire website by changing just one file!

Each HTML page must include a reference to the external style sheet file inside the <link> element, inside the head section. Continue reading How To Add CSS

CSS Selectors

CSS selectors are used to “find” (or select) the HTML elements you want to style.

We can divide CSS selectors into five categories:

This page will explain the most basic CSS selectors. Continue reading CSS Selectors

CSS Attribute Selectors

Style HTML Elements With Specific Attributes

It is possible to style HTML elements that have specific attributes or attribute values.


CSS [attribute] Selector

The [attribute] selector is used to select elements with a specified attribute.

The following example selects all <a> elements with a target attribute:

Continue reading CSS Attribute Selectors

CSS Pseudo-elements

What are Pseudo-Elements?

A CSS pseudo-element is used to style specific parts of an element.

For example, it can be used to:

  • Style the first letter or line, of an element
  • Insert content before or after an element
  • Style the markers of list items
  • Style the viewbox behind a dialog box

Continue reading CSS Pseudo-elements

CSS Pseudo-classes

What are Pseudo-classes?

A pseudo-class is used to define a special state of an element.

For example, it can be used to:

  • Style an element when a user moves the mouse over it
  • Style visited and unvisited links differently
  • Style an element when it gets focus
  • Style valid/invalid/required/optional form elements

Syntax

The syntax of pseudo-classes:

selector:pseudo-class {
  property: value;
}

Continue reading CSS Pseudo-classes

CSS Combinators

A CSS selector can contain more than one simple selector. Between the simple selectors, we can include a combinator.

There are four different combinators in CSS:

  • Descendant combinator (space)
  • Child combinator (>)
  • Next sibling combinator (+)
  • Subsequent-sibling combinator (~)

Descendant Combinator

The descendant combinator matches all elements that are descendants of a specified element.

The following example selects all <p> elements inside <div> elements: Continue reading CSS Combinators

CSS Syntax

The selector points to the HTML element you want to style.

The declaration block contains one or more declarations separated by semicolons.

Each declaration includes a CSS property name and a value, separated by a colon.

Multiple CSS declarations are separated with semicolons, and declaration blocks are surrounded by curly braces.

In this example all <p> elements will be center-aligned, with a red text color:
p {
  color: red;
  text-align: center;
}

Continue reading CSS Syntax

CSS Introduction

CSS is the language we use to style a Web page.

What is CSS?

  • CSS stands for Cascading Style Sheets
  • CSS describes how HTML elements are to be displayed on screen, paper, or in other media
  • CSS saves a lot of work. It can control the layout of multiple web pages all at once
  • External stylesheets are stored in CSS files

CSS Demo – One HTML Page – Multiple Styles!

Here we will show one HTML page displayed with four different stylesheets. Click on the “Stylesheet 1”, “Stylesheet 2”, “Stylesheet 3”, “Stylesheet 4” links below to see the different styles:

Continue reading CSS Introduction