Skip to content

Basic CSS Properties

Commonly used CSS properties

Basic CSS introduction

Anatomy of a CSS rule

anatomy of a css rule

Rules - an individual block of CSS that instructs the browser on how to style the page

  • Selector - indicates which HTML element will be styled
  • Declaration - a statement that tells the browser what to do with the elements
    • Property - the characteristic of the element that will be changed
    • Value - the new value of the property

Styling by HTML tag

The following CSS rule will make the text of all paragraphs in the page red.

This is a headline

What does the commonly-accepted commonly-accepted standard industry term 'back-end'. Clicking on this link which refers to B2B Marketing awards shortlist will take you to the awards page of the customer journey.

It may seem terrific, but it's 100% realistic! What does the term 'structuring'. If all of this comes off as mixed-up to you, that's because it is! If you productize globally, you may also mesh iteravely.

p {
color: red;
}

Styling by attribute

In the following CSS rule, if an image has an alt text, it will have a red border.

artistic and colorful waves on top of a black background
img[alt] {
border: 3px solid red;
}

We can reverse this by adding the :not() pseudo-class. In this next example, the image with no alt text will have a red border.

artistic and colorful waves on top of a black background
img:not([alt]) {
border: 3px solid red;
}

Styling by class

We can add the class attribute to any HTML tag and add any word we like. We can then use that class to style the element.

We will grow our capability to upgrade. Is it more important for something to be dynamic or to be customer-directed? What does the term 'short-term' really mean?

Have you ever needed to maximize your feature set? In one step? What do we incubate? Anything and everything, regardless of obscureness! Our feature set is unparalleled, but our raw bandwidth and easy operation is invariably considered a remarkable achievement.

<p class="red-text">
We will grow our capability to upgrade. Is it more important for something to
be dynamic or to be customer-directed? What does the term 'short-term' really
mean?
</p>

<p>
Have you ever needed to maximize your feature set? In one step? What do we
incubate? Anything and everything, regardless of obscureness! Our feature set
is unparalleled, but our raw bandwidth and easy operation is invariably
considered a remarkable achievement.
</p>
.red-text {
color: red;
}

We can use multiple different classes in a single HTML tag, like in the next example

White text on purple background

<h3 class="fg-white bg-purple">White text on purple background</h3>
.fg-white {
color: white;
}

.bg-purple {
background-color: purple;
}

Text properties

Property Description Values Examples
color sets the color of the text Any color, hexadecimal colors (there's a color picker you can use for this)
color: red;
color: dodgerblue;
color: #fd5003
line-height sets the distance between lines of text "normal", any number, any length (with unit like px or rem and em, and numerical percentage.
line-height: normal;
line-height: 2;
line-height: 1.75;
line-height: 10px;
line-height: 1em;
line-height: 1.5rem;
line-height: 200%;
text-align sets the alignment of text "left", "center", "right", "justify"
text-align: left;
text-align: center;
text-align: right;
text-align: justify;
letter-spacing sets the amount of space between characters "normal", or any number with unit (px, rem, em)
letter-spacing: normal;
letter-spacing: 2px;
letter-spacing: 0.25rem;
text-transform sets the casing of letters "none", "capitalize", "uppercase", "lowercase"
text-transform: none;
text-transform: capitalize;
text-transform: uppercase;
text-transform: lowercase;

Border

anatomy of a CSS border

Fonts

Property Description Values Examples
font-family the font to use for this element Any font in your system
font-family: "Comic Sans";
font-family: "Consolas";
font-family: "Lucida Calligraphy";
font-family: "Century Gothic";
font-size the size of the font any length with unit (the best unit for this is rem)
font-size: 1rem;
font-size: 2.5rem;
font-size: 250%;
font-weight the thickness of the font normal, bold, bolder,lighter
font-weight: normal;
font-weight: bold;
font-weight: bolder;
font-weight: lighter;
font-style the style of the font normal, italic, oblique (some of these values might not work if the font you are using doesn't support it
font-style: normal;
font-style: italic;
font-style: oblique;